pub struct Camera { /* private fields */ }Expand description
A rectangular viewport onto a larger world, with world/screen conversions.
Implementations§
Source§impl Camera
impl Camera
Sourcepub const fn new(viewport: Rect, world: Size) -> Self
pub const fn new(viewport: Rect, world: Size) -> Self
Create a camera drawing into viewport (screen cells) over a world of
world cells. The initial origin is (0, 0); call
center_on to follow a target.
Sourcepub fn set_viewport(&mut self, viewport: Rect)
pub fn set_viewport(&mut self, viewport: Rect)
Replace the viewport (for example after a terminal resize), keeping the world unchanged and re-clamping the origin so it stays in bounds.
Sourcepub fn center_on(&mut self, target: Pos)
pub fn center_on(&mut self, target: Pos)
Center the view on target (world coords), clamped to the world edges so
the viewport never scrolls past [0, world).
Sourcepub fn visible_bounds(&self) -> Rect
pub fn visible_bounds(&self) -> Rect
The world rectangle currently visible, clamped to world bounds.
Sourcepub const fn world_to_screen(&self, world: Pos) -> Option<Pos>
pub const fn world_to_screen(&self, world: Pos) -> Option<Pos>
Map a world position to its screen position, or None if it is outside
the visible viewport.
Sourcepub fn screen_to_world(&self, screen: Pos) -> Option<Pos>
pub fn screen_to_world(&self, screen: Pos) -> Option<Pos>
Map a screen position back to a world position, or None if it is
outside the viewport or beyond the world (useful for mouse picking).