pub struct Camera2d { /* private fields */ }Expand description
Represents a camera (“view”) positioned and oriented in a 2D scene with a 2D transformation and a 2D projection
Implementations§
Source§impl Camera2d
impl Camera2d
Sourcepub fn new(viewport_width: u16, viewport_height: u16) -> Self
pub fn new(viewport_width: u16, viewport_height: u16) -> Self
Create a new camera centered at the origin looking down the positive Y axis with ‘up’ vector aligned with the Z axis.
The orthographic projection is defined such that at the initial zoom
level of 1.0, one unit in world space is one pixel, so the points in
the bounding rectangle defined by minimum point (-half_screen_width+1, -half_screen_height+1) and maximum point (half_screen_width, half_screen_height) are visible.
pub const fn yaw(&self) -> Rad<f32>
pub const fn position(&self) -> Point2<f32>
pub const fn orientation(&self) -> Rotation2<f32>
pub const fn viewport_width(&self) -> u16
pub const fn viewport_height(&self) -> u16
pub const fn transform_mat_world_to_view(&self) -> Matrix4<f32>
pub const fn zoom(&self) -> f32
pub const fn ortho(&self) -> FrustumPlanes<f32>
pub const fn projection_mat_ortho(&self) -> Matrix4<f32>
Sourcepub fn screen_to_world(&self, screen_coord: Point2<f32>) -> Point2<f32>
pub fn screen_to_world(&self, screen_coord: Point2<f32>) -> Point2<f32>
Convert a screen space coordinate to world space based on the current view.
let [width, height] = [320, 240];
let mut camera2d = Camera2d::new (width, height);
let screen_coord = [width as f32 / 2.0, height as f32 / 2.0].into();
assert_eq!(camera2d.screen_to_world (screen_coord).0, [0.0, 0.0].into());Sourcepub fn world_to_screen(&self, world_coord: Point2<f32>) -> Point2<f32>
pub fn world_to_screen(&self, world_coord: Point2<f32>) -> Point2<f32>
Convert a world space coordinate to screen space based on the current view.
let [width, height] = [320, 240];
let mut camera2d = Camera2d::new (width, height);
let world_coord = math::Point::origin();
assert_eq!(camera2d.world_to_screen (world_coord).0,
[width as f32 / 2.0, height as f32 / 2.0].into());Sourcepub fn set_viewport_dimensions(
&mut self,
viewport_width: u16,
viewport_height: u16,
)
pub fn set_viewport_dimensions( &mut self, viewport_width: u16, viewport_height: u16, )
pub fn set_position(&mut self, position: Point2<f32>)
pub fn rotate(&mut self, delta_yaw: Rad<f32>)
Sourcepub fn move_local(&mut self, delta_x: f32, delta_y: f32)
pub fn move_local(&mut self, delta_x: f32, delta_y: f32)
Move by delta X and Y values in local coordinates
Sourcepub fn move_origin_to_bottom_left(&mut self)
pub fn move_origin_to_bottom_left(&mut self)
Move camera so that the world-space origin will be centered on the lower left pixel
Sourcepub fn scale_zoom(&mut self, scale: f32)
pub fn scale_zoom(&mut self, scale: f32)
Trait Implementations§
impl StructuralPartialEq for Camera2d
Auto Trait Implementations§
impl Freeze for Camera2d
impl RefUnwindSafe for Camera2d
impl Send for Camera2d
impl Sync for Camera2d
impl Unpin 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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more