Skip to main content

Camera2D

Struct Camera2D 

Source
pub struct Camera2D { /* private fields */ }
Expand description

2D game camera supporting world-to-screen projection, zoom, smooth target follow, frustum culling, and trauma screen shake.

Implementations§

Source§

impl Camera2D

Camera projection, smooth follow, frustum culling, and trauma shake operations.

Source

pub fn at(center: Point, zoom: f32) -> Self

Creates a Camera2D positioned at center with zoom.

§Arguments
  • Point - Initial world center.
  • f32 - Initial zoom multiplier clamped to [0.25, 4.0].
§Returns
  • Self - Configured 2D camera.
Source

pub fn add_trauma(&mut self, amount: f32)

Adds impact trauma in [0.0, 1.0] to drive damped screen shake.

§Arguments
  • &Self - Mutable camera.
  • f32 - Trauma impulse amount.
Source

pub fn follow( &mut self, target: Point, responsiveness: f32, dt_secs: f32, viewport: Size, )

Smoothly follows target using frame-rate-independent exponential damping and decays screen shake.

§Arguments
  • &Self - Mutable camera.
  • Point - Desired world target point.
  • f32 - Responsiveness factor (6.0..=16.0 recommended).
  • f32 - Elapsed frame delta in seconds.
  • Size - Viewport logical size for optional world-bounds clamping.
Source

pub fn shake_offset(&self) -> Point

Computes the current screen-shake offset in world coordinates.

§Arguments
  • &Self - Camera reference.
§Returns
  • Point - Shake offset (dx, dy).
Source

pub fn world_to_screen(&self, world: Point, viewport: Size) -> Point

Projects a world-space point into viewport-local screen coordinates.

§Arguments
  • &Self - Camera reference.
  • Point - World-space point.
  • Size - Viewport logical size.
§Returns
  • Point - Viewport-local logical pixel coordinates.
Source

pub fn screen_to_world(&self, screen: Point, viewport: Size) -> Point

Unprojects a viewport-local screen point back into world coordinates.

§Arguments
  • &Self - Camera reference.
  • Point - Viewport-local logical pixel point.
  • Size - Viewport logical size.
§Returns
  • Point - Corresponding world-space point.
Source

pub fn lerp(self, other: Self, alpha: f32) -> Self

Linearly interpolates position, zoom, and shake state between self and other at alpha in [0.0, 1.0].

§Arguments
  • Self - Previous fixed-step camera state.
  • Self - Current fixed-step camera state.
  • f32 - Normalized interpolation factor in [0.0, 1.0].
§Returns
  • Self - Render-time interpolated 2D camera.
Source

pub fn visible_world_rect(&self, viewport: Size) -> Rect

Computes the world-space visible frustum rectangle for culling offscreen sprites and tiles.

§Arguments
  • &Self - Camera reference.
  • Size - Viewport logical size.
§Returns
  • Rect - Visible world-space frustum bounds.
Source§

impl Camera2D

Source

pub fn get_position(&self) -> Point

Source

pub fn get_mut_position(&mut self) -> &mut Point

Source

pub fn set_position(&mut self, val: Point) -> &mut Self

Source

pub fn get_zoom(&self) -> f32

Source

pub fn get_mut_zoom(&mut self) -> &mut f32

Source

pub fn set_zoom(&mut self, val: f32) -> &mut Self

Source

pub fn get_trauma(&self) -> f32

Source

pub fn get_mut_trauma(&mut self) -> &mut f32

Source

pub fn set_trauma(&mut self, val: f32) -> &mut Self

Source

pub fn get_max_shake(&self) -> f32

Source

pub fn get_mut_max_shake(&mut self) -> &mut f32

Source

pub fn set_max_shake(&mut self, val: f32) -> &mut Self

Source

pub fn get_shake_time(&self) -> f32

Source

pub fn get_mut_shake_time(&mut self) -> &mut f32

Source

pub fn set_shake_time(&mut self, val: f32) -> &mut Self

Source

pub fn get_mut_world_bounds(&mut self) -> &mut Option<Rect>

Source

pub fn set_world_bounds(&mut self, val: Option<Rect>) -> &mut Self

Trait Implementations§

Source§

impl Clone for Camera2D

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Camera2D

Source§

impl Debug for Camera2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Camera2D

Default camera centered at (0, 0) with 1.0x zoom.

Source§

fn default() -> Self

Creates a default Camera2D.

§Returns
  • Self - Default 2D camera.
Source§

impl PartialEq for Camera2D

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Camera2D

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.