Struct gl_utils::camera2d::Camera2d [−][src]
pub struct Camera2d { pub position: Point2<f32>, pub yaw: Rad<f32>, pub orientation: Basis2<f32>, pub transform_mat_world_to_view: Matrix4<f32>, pub viewport_width: u16, pub viewport_height: u16, pub zoom: f32, pub ortho: Ortho<f32>, pub projection_mat_ortho: Matrix4<f32>, }
Represents a camera ("view") positioned and oriented in a 2D scene with a 2D transformation and a 2D projection
Fields
position: Point2<f32>
Position in 2D world space
yaw: Rad<f32>
Yaw represents a counter-clockwise rotation restricted to the range $[0, 2\pi)$.
orientation: Basis2<f32>
Basis derived from yaw
.
transform_mat_world_to_view: Matrix4<f32>
Transforms points from 2D world space to 2D camera (view, eye) space as specified by the camera position and orientation.
viewport_width: u16
viewport_height: u16
zoom: f32
Determines the extent of the view represented in the ortho
structure
ortho: Ortho<f32>
Used to create the ortho projection matrix
projection_mat_ortho: Matrix4<f32>
Constructed from the parameters in ortho
to transform points in 2D view
space to 4D homogenous clip coordinates.
Methods
impl Camera2d
[src]
impl Camera2d
pub fn new(viewport_width: u16, viewport_height: u16) -> Self
[src]
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 fn set_viewport_dimensions(
&mut self,
viewport_width: u16,
viewport_height: u16
)
[src]
pub fn set_viewport_dimensions(
&mut self,
viewport_width: u16,
viewport_height: u16
)
Should be called when the screen resolution changes to update the orthographic projection state.
Panics
Panics if the viewport width or height are zero:
use cgmath::{EuclideanSpace, One, Transform}; let mut camera2d = Camera2d::new (320, 240); camera2d.set_viewport_dimensions (0, 0); // panics
pub fn set_zoom(&mut self, zoom: f32)
[src]
pub fn set_zoom(&mut self, zoom: f32)
Set the zoom level.
Panics
Panics if scale factor is zero or negative:
use cgmath::{EuclideanSpace, One, Transform}; let mut camera2d = Camera2d::new (320, 240); camera2d.set_zoom (-1.0); // panics
pub fn rotate(&mut self, delta_yaw: Rad<f32>)
[src]
pub fn rotate(&mut self, delta_yaw: Rad<f32>)
pub fn move_local(&mut self, delta_x: f32, delta_y: f32)
[src]
pub fn move_local(&mut self, delta_x: f32, delta_y: f32)
Move by delta X and Y values in local coordinates
pub fn scale_zoom(&mut self, scale: f32)
[src]
pub fn scale_zoom(&mut self, scale: f32)
Multiply the current zoom by the given scale factor.
Panics
Panics if scale factor is zero or negative:
use cgmath::{EuclideanSpace, One, Transform}; let mut camera2d = Camera2d::new (320, 240); camera2d.scale_zoom (-1.0); // panics
pub fn view_ortho_mats(&self) -> (&[[f32; 4]; 4], &[[f32; 4]; 4])
[src]
pub fn view_ortho_mats(&self) -> (&[[f32; 4]; 4], &[[f32; 4]; 4])
Returns the raw world to view transform and ortho projection matrix data, suitable for use as shader uniforms.