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.
impl Camera2D
Camera projection, smooth follow, frustum culling, and trauma shake operations.
Sourcepub fn add_trauma(&mut self, amount: f32)
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.
Sourcepub fn follow(
&mut self,
target: Point,
responsiveness: f32,
dt_secs: f32,
viewport: Size,
)
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.0recommended).f32- Elapsed frame delta in seconds.Size- Viewport logical size for optional world-bounds clamping.
Sourcepub fn shake_offset(&self) -> Point
pub fn shake_offset(&self) -> Point
Sourcepub fn projection_params(&self, viewport: Size) -> (f32, f32, f32, f32, f32)
pub fn projection_params(&self, viewport: Size) -> (f32, f32, f32, f32, f32)
Precomputes hoisted camera screen-projection parameters (effective_cam_x, effective_cam_y, zoom, half_vp_w, half_vp_h) once per frame so tile/entity/particle loops avoid redundant per-item sin/cos shake math.
§Arguments
&Self- Camera reference.Size- Viewport logical size.
§Returns
(f32, f32, f32, f32, f32)- Hoisted(cam_x_plus_shake, cam_y_plus_shake, zoom, half_vp_w, half_vp_h)tuple.
Sourcepub fn world_to_screen_with_shake(
&self,
world: Point,
viewport: Size,
shake: Point,
) -> Point
pub fn world_to_screen_with_shake( &self, world: Point, viewport: Size, shake: Point, ) -> Point
Projects a world-space point into viewport-local screen coordinates using a pre-hoisted shake offset.
§Arguments
&Self- Camera reference.Point- World-space point.Size- Viewport logical size.Point- Precomputed per-frameshake_offset()value.
§Returns
Point- Viewport-local logical pixel coordinates.
Sourcepub fn world_to_screen(&self, world: Point, viewport: Size) -> Point
pub fn world_to_screen(&self, world: Point, viewport: Size) -> Point
Sourcepub fn screen_to_world(&self, screen: Point, viewport: Size) -> Point
pub fn screen_to_world(&self, screen: Point, viewport: Size) -> Point
Source§impl Camera2D
impl Camera2D
pub fn get_position(&self) -> Point
pub fn get_mut_position(&mut self) -> &mut Point
pub fn set_position(&mut self, val: Point) -> &mut Self
pub fn get_zoom(&self) -> f32
pub fn get_mut_zoom(&mut self) -> &mut f32
pub fn set_zoom(&mut self, val: f32) -> &mut Self
pub fn get_trauma(&self) -> f32
pub fn get_mut_trauma(&mut self) -> &mut f32
pub fn set_trauma(&mut self, val: f32) -> &mut Self
pub fn get_max_shake(&self) -> f32
pub fn get_mut_max_shake(&mut self) -> &mut f32
pub fn set_max_shake(&mut self, val: f32) -> &mut Self
pub fn get_shake_time(&self) -> f32
pub fn get_mut_shake_time(&mut self) -> &mut f32
pub fn set_shake_time(&mut self, val: f32) -> &mut Self
pub fn get_mut_world_bounds(&mut self) -> &mut Option<Rect>
pub fn set_world_bounds(&mut self, val: Option<Rect>) -> &mut Self
Trait Implementations§
impl Copy for Camera2D
impl StructuralPartialEq for Camera2D
Auto Trait Implementations§
impl Forget for Camera2D
impl Freeze for Camera2D
impl Move 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
Mutably borrows from an owned value. Read more