Struct draw2d::camera::OrthoCamera [−][src]
pub struct OrthoCamera { /* fields omitted */ }
Implementations
Build a new camera with a given viewport height and aspect ratio.
Params
viewport_height
defines the height of the view rectangle in world space.aspect_ratio
is the ratio of the desired viewport’swidth/height
.
Get the camera’s full transformation matrix. This can be passed to a shader for transformations.
The camera’s bounds in world-space.
Example
let ortho = OrthoCamera::with_viewport(1.0, 2.0); let bounds = ortho.bounds(); assert_relative_eq!(bounds.left, -1.0); assert_relative_eq!(bounds.right, 1.0); assert_relative_eq!(bounds.top, 0.5); assert_relative_eq!(bounds.bottom, -0.5);
Set the camera’s position in world-space.
Example
let mut ortho = OrthoCamera::with_viewport(2.0, 1.0); ortho.set_world_position(&na::Point2::new(30.0, -0.5)); assert_relative_eq!( ortho.world_position(), na::Point2::new(30.0, -0.5) ); let bounds = ortho.bounds(); assert_relative_eq!(bounds.left, -1.0 + 30.0); assert_relative_eq!(bounds.right, 1.0 + 30.0); assert_relative_eq!(bounds.top, 1.0 - 0.5); assert_relative_eq!(bounds.bottom, -1.0 - 0.5);
Get the camera’s position in world space.
Example
let pos = OrthoCamera::with_viewport(1.0, 1.0).world_position(); assert_relative_eq!(pos, na::Point2::new(0.0, 0.0));
Resize the viewport’s width such that the viewing rectangle has the desired aspect ratio.
Example
let mut ortho = OrthoCamera::with_viewport(1.0, 1.0); ortho.set_aspect_ratio(2.0); let bounds = ortho.bounds(); assert_relative_eq!(bounds.left, -1.0); assert_relative_eq!(bounds.right, 1.0); assert_relative_eq!(bounds.top, 0.5); assert_relative_eq!(bounds.bottom, -0.5);
The camera viewport’s aspect ratio.
Get the height of the viewport.
Get the width of the viewport.
Set the viewport’s height to a new value.
Automatically resizes the viewport’s width to maintain the current aspect ratio.
Example
// a camera which is 3x as wide as it is tall let mut ortho = OrthoCamera::with_viewport(2.0, 3.0); assert_relative_eq!(ortho.aspect_ratio(), 3.0); assert_relative_eq!(ortho.viewport_height(), 2.0); assert_relative_eq!(ortho.viewport_width(), 6.0); ortho.set_viewport_height(3.3); assert_relative_eq!(ortho.aspect_ratio(), 3.0); assert_relative_eq!(ortho.viewport_height(), 3.3); assert_relative_eq!(ortho.viewport_width(), 9.9);
Unproject a vector from normalized device coordinates (NDC) to view space.
Vectors are just a direction and a magnitude, so this transformation does not apply the camera’s translation in world space.
Example
// a camera which is 3x as wide as it is tall let mut ortho = OrthoCamera::with_viewport(2.0, 3.0); // the camera's world position is ignored when unprojecting a vector ortho.set_world_position(&na::Point2::new(100.0, -34523.0)); // Vulkan ndc coords have Y ranging from -1 at the top of the screen, // to 1 at the bottom of the screen. let top_right_ndc = na::Vector2::new(1.0, -1.0); // The unprojected vector should point to the top right of the viewport // rectangle, but is not influenced by the camera's world position. let unprojected = ortho.unproject_vec(&top_right_ndc); assert_relative_eq!(unprojected, na::Vector2::new(3.0, 1.0));
Unproject a point from normalized device coordinates (NDC) to world space.
Points are logically a specific location in space. As such, the point’s coordinates will be transformed b ythe camera’s location in world space.
e.g. this method returns where the ndc point would actually be located in world coordinates.
Example
// a camera which is 3x as wide as it is tall let mut ortho = OrthoCamera::with_viewport(2.0, 3.0); // the camera's world position is ignored when unprojecting a vector ortho.set_world_position(&na::Point2::new(100.0, -34523.0)); // Vulkan ndc coords have Y ranging from -1 at the top of the screen, // to 1 at the bottom of the screen. let bottom_left_ndc = na::Point2::new(-1.0, 1.0); // The unprojected point should account for both the camera's viewing // rectangle, and the camera's world position. let unprojected = ortho.unproject_point(&bottom_left_ndc); assert_relative_eq!( unprojected, na::Point2::new(-3.0, -1.0) + ortho.world_position().coords );
Trait Implementations
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for OrthoCamera
impl Send for OrthoCamera
impl Sync for OrthoCamera
impl Unpin for OrthoCamera
impl UnwindSafe for OrthoCamera
Blanket Implementations
Mutably borrows from an owned value. Read more
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
Checks if self
is actually part of its subset T
(and can be converted to it).
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
The inclusion map: converts self
to the equivalent element of its superset.