pub struct Camera2d {
pub center: Vec2,
pub offset: Vec2,
pub units_per_pixel: f32,
pub zoom: f32,
pub roll: f32,
}Expand description
2D orthographic camera. Owned by the UI (signals), copied into the snapshot per frame.
The camera’s look point is effective_center
(center + offset); zoom and units_per_pixel scale the view
uniformly. All three viewport consumers (canvas drawing, the GPU batch
matrix, and pointer picks) derive from these fields through one shared
transform, so they can never disagree.
Fields§
§center: Vec2World-space point the camera follows (the follow target, room
center, or player position). Defaults to (0, 0).
Scroll limits (see apply_limits) clamp this field; put
momentary displacement such as trauma shake in offset
instead so it can push past the limits.
offset: Vec2Momentary displacement added to center.
Defaults to (0, 0).
Useful for looking around or camera shake animations: applied after limits, so a shake impulse still moves the view even when the follow target is pinned at a scroll edge. Decays back to zero under game-side trauma handling.
units_per_pixel: f32World units per screen pixel at zoom 1. Defaults to 1.0.
Combined with the viewport size to build the orthographic
projection: a smaller value shows less of the world (larger
sprites). Together with zoom, the visible world width is
viewport_dp * units_per_pixel / zoom. Non-positive values fall
back to 1.0 so a bad snapshot can never divide by zero.
zoom: f32Magnification. Defaults to 1.0.
Higher values zoom in: 2.0 shows half the world width on each
axis (a quarter of the area); 0.5 shows twice as much. Applied on
canvas and GPU alike. Non-positive values fall back to 1.0.
roll: f32Roll in radians around the look point (trauma shake). Defaults to 0.0.
Applied after look/zoom on canvas, GPU, picks, and actor surfaces, so all consumers stay glued. Positive is clockwise in y-down space.
Implementations§
Source§impl Camera2d
impl Camera2d
Sourcepub fn effective_center(&self) -> [f32; 2]
pub fn effective_center(&self) -> [f32; 2]
Effective look point: center + offset.
All framing (canvas drawing, the GPU batch matrix, pointer picks,
actor surfaces) uses this value, so shake and look-around applied
through offset move every consumer together.
Sourcepub fn fit_matrix(&self, canvas_dp: [f32; 2], world_size: [f32; 2]) -> Mat4
pub fn fit_matrix(&self, canvas_dp: [f32; 2], world_size: [f32; 2]) -> Mat4
Framing matrix used by GPU + picks. Prefer this over raw ortho.
Includes roll around the look point.
Sourcepub fn dp_to_world_pt(
&self,
canvas_dp: [f32; 2],
world_size: [f32; 2],
dp: [f32; 2],
) -> Vec2
pub fn dp_to_world_pt( &self, canvas_dp: [f32; 2], world_size: [f32; 2], dp: [f32; 2], ) -> Vec2
World under a dp-space cursor (canvas coords, density already divided out).
Includes roll.
Sourcepub fn view_proj_screen(&self, viewport_px: [f32; 2]) -> Mat4
pub fn view_proj_screen(&self, viewport_px: [f32; 2]) -> Mat4
Raw ortho ignoring contain-fit letterbox. Kept for HUD overlays in
screen space; viewport code must use fit_matrix.
Sourcepub fn view_proj(&self, viewport_px: [f32; 2]) -> Mat4
👎Deprecated since 0.1.8: ignores world_size; use fit_view_proj for the shared canvas/GPU/pick framing contract
pub fn view_proj(&self, viewport_px: [f32; 2]) -> Mat4
ignores world_size; use fit_view_proj for the shared canvas/GPU/pick framing contract
Legacy y-down view-projection: world +y points screen-down.
Diverges from the shared framing contract: this frames from
viewport * units_per_pixel / zoom and ignores
FrameInput::world_size, so it disagrees with canvas, GPU, and
picks whenever a contain-fit letterboxes. Kept for guards/tests;
viewport code must use fit_view_proj instead.
Sourcepub fn screen_to_world(&self, viewport_px: [f32; 2], px: [f32; 2]) -> Vec2
👎Deprecated since 0.1.8: ignores world_size; use pick_world over the painted FrameGeom instead
pub fn screen_to_world(&self, viewport_px: [f32; 2], px: [f32; 2]) -> Vec2
ignores world_size; use pick_world over the painted FrameGeom instead
Legacy world-space position under a viewport-pixel cursor.
Inverts view_proj, so it shares that
function’s divergence from the contain-fit contract. Pointer picks
must go through pick_world over the painted FrameGeom.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Camera2d
impl RefUnwindSafe for Camera2d
impl Send for Camera2d
impl Sync for Camera2d
impl Unpin for Camera2d
impl UnsafeUnpin for Camera2d
impl UnwindSafe for Camera2d
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FromTemplate for T
impl<T> FromTemplate for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Template for T
impl<T> Template for T
Source§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
entity context to produce a Template::Output.Source§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clone.