pub struct Camera2d {
pub center: Vec2,
pub offset: Vec2,
pub units_per_pixel: f32,
pub zoom: 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.
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 view_proj(&self, viewport_px: [f32; 2]) -> Mat4
pub fn view_proj(&self, viewport_px: [f32; 2]) -> Mat4
Y-down view-projection: world +y points screen-down. Guards degenerate inputs (zero viewport/zoom) so a
bad snapshot can never div-by-zero; callers driving viewports
should prefer fit_view_proj (contain-fit + look), which is the
single framing contract canvas, GPU, and picks share.
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.