pub struct Camera2d { /* private fields */ }Expand description
2D camera mapping world coordinates into logical screen pixels.
center and all input positions are in world units. zoom is logical screen
pixels per world unit. rotation is in radians.
Implementations§
Source§impl Camera2d
impl Camera2d
Sourcepub fn new(center: Vec2, zoom: f32) -> Result<Self, Camera2dError>
pub fn new(center: Vec2, zoom: f32) -> Result<Self, Camera2dError>
Builds a camera centered on a world-space point.
zoom is logical screen pixels per world unit and must be finite and
positive. Invalid values return Camera2dError::InvalidZoom instead of
being silently clamped.
Sourcepub fn set_center(&mut self, center: Vec2) -> Result<(), Camera2dError>
pub fn set_center(&mut self, center: Vec2) -> Result<(), Camera2dError>
Replaces the world-space point displayed at the viewport center. Invalid coordinates leave the current center unchanged.
Sourcepub fn set_zoom(&mut self, zoom: f32) -> Result<(), Camera2dError>
pub fn set_zoom(&mut self, zoom: f32) -> Result<(), Camera2dError>
Replaces camera scale in logical screen pixels per world unit.
Invalid values return Camera2dError::InvalidZoom and leave the
current zoom unchanged.
Sourcepub fn set_rotation(&mut self, rotation: f32) -> Result<(), Camera2dError>
pub fn set_rotation(&mut self, rotation: f32) -> Result<(), Camera2dError>
Replaces clockwise screen rotation in radians. Non-finite values leave the current rotation unchanged.
Sourcepub fn projection(self) -> Projection2d
pub fn projection(self) -> Projection2d
Returns the pseudo-depth projection applied to camera-relative coordinates.
Sourcepub fn set_projection(&mut self, projection: Projection2d)
pub fn set_projection(&mut self, projection: Projection2d)
Replaces the pseudo-depth projection applied to camera-relative coordinates.
Sourcepub fn pan_by(&mut self, delta: Vec2) -> Result<(), Camera2dError>
pub fn pan_by(&mut self, delta: Vec2) -> Result<(), Camera2dError>
Pans the displayed world center by a finite world-space delta.
Sourcepub fn zoom_about_screen(
&mut self,
factor: f32,
anchor: LogicalScreenPosition,
viewport: LogicalViewport,
) -> Result<(), Camera2dError>
pub fn zoom_about_screen( &mut self, factor: f32, anchor: LogicalScreenPosition, viewport: LogicalViewport, ) -> Result<(), Camera2dError>
Changes zoom while keeping the depth-zero world point under anchor fixed.
anchor is measured in logical pixels. The operation is atomic: invalid
factors, singular projections, or overflows leave this camera unchanged.
Sourcepub fn fit_to_bounds(
&mut self,
bounds: Rect,
padding: f32,
viewport: LogicalViewport,
) -> Result<(), Camera2dError>
pub fn fit_to_bounds( &mut self, bounds: Rect, padding: f32, viewport: LogicalViewport, ) -> Result<(), Camera2dError>
Centers and zooms the camera so finite non-empty world bounds fit a viewport.
padding is measured in logical pixels on every edge. The extent
calculation accounts for this camera’s rotation and depth-zero tilt.
Sourcepub fn world_to_screen(
self,
world: Vec2,
viewport: LogicalViewport,
) -> Result<LogicalScreenPosition, Camera2dError>
pub fn world_to_screen( self, world: Vec2, viewport: LogicalViewport, ) -> Result<LogicalScreenPosition, Camera2dError>
Converts a world-space point into logical screen pixel coordinates.
Returns an error if finite values overflow during the transform.
Sourcepub fn projected_world_to_screen(
self,
world: Vec2,
depth: f32,
viewport: LogicalViewport,
) -> Result<LogicalScreenPosition, Camera2dError>
pub fn projected_world_to_screen( self, world: Vec2, depth: f32, viewport: LogicalViewport, ) -> Result<LogicalScreenPosition, Camera2dError>
Converts a world-space point and pseudo-depth into logical screen pixels.
Sourcepub fn screen_to_world(
self,
screen: LogicalScreenPosition,
viewport: LogicalViewport,
) -> Result<Vec2, Camera2dError>
pub fn screen_to_world( self, screen: LogicalScreenPosition, viewport: LogicalViewport, ) -> Result<Vec2, Camera2dError>
Converts logical screen pixel coordinates back into world coordinates.
This is equivalent to Camera2d::screen_to_world_at_depth with
depth = 0.0.
Sourcepub fn screen_to_world_at_depth(
self,
screen: LogicalScreenPosition,
depth: f32,
viewport: LogicalViewport,
) -> Result<Vec2, Camera2dError>
pub fn screen_to_world_at_depth( self, screen: LogicalScreenPosition, depth: f32, viewport: LogicalViewport, ) -> Result<Vec2, Camera2dError>
Converts logical screen pixel coordinates into world coordinates on a pseudo-depth plane.
depth must match the same caller-defined scalar depth passed to
Camera2d::projected_world_to_screen. If projection tilt is close to
90 degrees, the inverse mapping is singular and returns
Camera2dError::SingularProjection.
Sourcepub fn tween(self) -> Result<Tween<Self>, TweenError>
pub fn tween(self) -> Result<Tween<Self>, TweenError>
Creates a tween initialized with this camera state.
Trait Implementations§
impl Copy for Camera2d
Source§impl Interpolate for Camera2d
impl Interpolate for Camera2d
Source§fn interpolate(self, end: Self, amount: f32) -> Self
fn interpolate(self, end: Self, amount: f32) -> Self
self and end.