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 in 2D world space

Yaw represents a counter-clockwise rotation restricted to the range $[0, 2\pi)$.

Basis derived from yaw.

Transforms points from 2D world space to 2D camera (view, eye) space as specified by the camera position and orientation.

Determines the extent of the view represented in the ortho structure

Used to create the ortho projection matrix

Constructed from the parameters in ortho to transform points in 2D view space to 4D homogenous clip coordinates.

Methods

impl Camera2d
[src]

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.

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

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

Move by delta X and Y values in local coordinates

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

Returns the raw world to view transform and ortho projection matrix data, suitable for use as shader uniforms.

Auto Trait Implementations

impl Send for Camera2d

impl Sync for Camera2d