Struct rin::math::geometry::Orthographic3[][src]

pub struct Orthographic3<N> where
    N: RealField
{ /* fields omitted */ }

A 3D orthographic projection stored as a homogeneous 4x4 matrix.

Implementations

impl<N> Orthographic3<N> where
    N: RealField
[src]

pub fn new(
    left: N,
    right: N,
    bottom: N,
    top: N,
    znear: N,
    zfar: N
) -> Orthographic3<N>
[src]

Creates a new orthographic projection matrix.

This follows the OpenGL convention, so this will flip the z axis.

Example

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
// Check this projection actually transforms the view cuboid into the double-unit cube.
// See https://www.nalgebra.org/projections/#orthographic-projection for more details.
let p1 = Point3::new(1.0, 2.0, -0.1);
let p2 = Point3::new(1.0, 2.0, -1000.0);
let p3 = Point3::new(1.0, 20.0, -0.1);
let p4 = Point3::new(1.0, 20.0, -1000.0);
let p5 = Point3::new(10.0, 2.0, -0.1);
let p6 = Point3::new(10.0, 2.0, -1000.0);
let p7 = Point3::new(10.0, 20.0, -0.1);
let p8 = Point3::new(10.0, 20.0, -1000.0);

assert_relative_eq!(proj.project_point(&p1), Point3::new(-1.0, -1.0, -1.0));
assert_relative_eq!(proj.project_point(&p2), Point3::new(-1.0, -1.0,  1.0));
assert_relative_eq!(proj.project_point(&p3), Point3::new(-1.0,  1.0, -1.0));
assert_relative_eq!(proj.project_point(&p4), Point3::new(-1.0,  1.0,  1.0));
assert_relative_eq!(proj.project_point(&p5), Point3::new( 1.0, -1.0, -1.0));
assert_relative_eq!(proj.project_point(&p6), Point3::new( 1.0, -1.0,  1.0));
assert_relative_eq!(proj.project_point(&p7), Point3::new( 1.0,  1.0, -1.0));
assert_relative_eq!(proj.project_point(&p8), Point3::new( 1.0,  1.0,  1.0));

// This also works with flipped axis. In other words, we allow that
// `left > right`, `bottom > top`, and/or `znear > zfar`.
let proj = Orthographic3::new(10.0, 1.0, 20.0, 2.0, 1000.0, 0.1);

assert_relative_eq!(proj.project_point(&p1), Point3::new( 1.0,  1.0,  1.0));
assert_relative_eq!(proj.project_point(&p2), Point3::new( 1.0,  1.0, -1.0));
assert_relative_eq!(proj.project_point(&p3), Point3::new( 1.0, -1.0,  1.0));
assert_relative_eq!(proj.project_point(&p4), Point3::new( 1.0, -1.0, -1.0));
assert_relative_eq!(proj.project_point(&p5), Point3::new(-1.0,  1.0,  1.0));
assert_relative_eq!(proj.project_point(&p6), Point3::new(-1.0,  1.0, -1.0));
assert_relative_eq!(proj.project_point(&p7), Point3::new(-1.0, -1.0,  1.0));
assert_relative_eq!(proj.project_point(&p8), Point3::new(-1.0, -1.0, -1.0));

pub fn from_matrix_unchecked(
    matrix: Matrix<N, U4, U4, <DefaultAllocator as Allocator<N, U4, U4>>::Buffer>
) -> Orthographic3<N>
[src]

Wraps the given matrix to interpret it as a 3D orthographic matrix.

It is not checked whether or not the given matrix actually represents an orthographic projection.

Example

let mat = Matrix4::new(
    2.0 / 9.0, 0.0,        0.0,         -11.0 / 9.0,
    0.0,       2.0 / 18.0, 0.0,         -22.0 / 18.0,
    0.0,       0.0,       -2.0 / 999.9, -1000.1 / 999.9,
    0.0,       0.0,        0.0,         1.0
);
let proj = Orthographic3::from_matrix_unchecked(mat);
assert_eq!(proj, Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0));

pub fn from_fov(aspect: N, vfov: N, znear: N, zfar: N) -> Orthographic3<N>[src]

Creates a new orthographic projection matrix from an aspect ratio and the vertical field of view.

pub fn inverse(
    &self
) -> Matrix<N, U4, U4, <DefaultAllocator as Allocator<N, U4, U4>>::Buffer>
[src]

Retrieves the inverse of the underlying homogeneous matrix.

Example

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
let inv = proj.inverse();

assert_relative_eq!(inv * proj.as_matrix(), Matrix4::identity());
assert_relative_eq!(proj.as_matrix() * inv, Matrix4::identity());

let proj = Orthographic3::new(10.0, 1.0, 20.0, 2.0, 1000.0, 0.1);
let inv = proj.inverse();
assert_relative_eq!(inv * proj.as_matrix(), Matrix4::identity());
assert_relative_eq!(proj.as_matrix() * inv, Matrix4::identity());

pub fn to_homogeneous(
    &self
) -> Matrix<N, U4, U4, <DefaultAllocator as Allocator<N, U4, U4>>::Buffer>
[src]

Computes the corresponding homogeneous matrix.

Example

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
let expected = Matrix4::new(
    2.0 / 9.0, 0.0,        0.0,         -11.0 / 9.0,
    0.0,       2.0 / 18.0, 0.0,         -22.0 / 18.0,
    0.0,       0.0,       -2.0 / 999.9, -1000.1 / 999.9,
    0.0,       0.0,        0.0,         1.0
);
assert_eq!(proj.to_homogeneous(), expected);

pub fn as_matrix(
    &self
) -> &Matrix<N, U4, U4, <DefaultAllocator as Allocator<N, U4, U4>>::Buffer>
[src]

A reference to the underlying homogeneous transformation matrix.

Example

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
let expected = Matrix4::new(
    2.0 / 9.0, 0.0,        0.0,         -11.0 / 9.0,
    0.0,       2.0 / 18.0, 0.0,         -22.0 / 18.0,
    0.0,       0.0,       -2.0 / 999.9, -1000.1 / 999.9,
    0.0,       0.0,        0.0,         1.0
);
assert_eq!(*proj.as_matrix(), expected);

pub fn as_projective(&self) -> &Transform<N, U3, TProjective>[src]

A reference to this transformation seen as a Projective3.

Example

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
assert_eq!(proj.as_projective().to_homogeneous(), proj.to_homogeneous());

pub fn to_projective(&self) -> Transform<N, U3, TProjective>[src]

This transformation seen as a Projective3.

Example

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
assert_eq!(proj.to_projective().to_homogeneous(), proj.to_homogeneous());

pub fn into_inner(
    self
) -> Matrix<N, U4, U4, <DefaultAllocator as Allocator<N, U4, U4>>::Buffer>
[src]

Retrieves the underlying homogeneous matrix.

Example

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
let expected = Matrix4::new(
    2.0 / 9.0, 0.0,        0.0,         -11.0 / 9.0,
    0.0,       2.0 / 18.0, 0.0,         -22.0 / 18.0,
    0.0,       0.0,       -2.0 / 999.9, -1000.1 / 999.9,
    0.0,       0.0,        0.0,         1.0
);
assert_eq!(proj.into_inner(), expected);

pub fn unwrap(
    self
) -> Matrix<N, U4, U4, <DefaultAllocator as Allocator<N, U4, U4>>::Buffer>
[src]

👎 Deprecated:

use .into_inner() instead

Retrieves the underlying homogeneous matrix. Deprecated: Use Orthographic3::into_inner instead.

pub fn left(&self) -> N[src]

The left offset of the view cuboid.

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
assert_relative_eq!(proj.left(), 1.0, epsilon = 1.0e-6);

let proj = Orthographic3::new(10.0, 1.0, 20.0, 2.0, 1000.0, 0.1);
assert_relative_eq!(proj.left(), 10.0, epsilon = 1.0e-6);

pub fn right(&self) -> N[src]

The right offset of the view cuboid.

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
assert_relative_eq!(proj.right(), 10.0, epsilon = 1.0e-6);

let proj = Orthographic3::new(10.0, 1.0, 20.0, 2.0, 1000.0, 0.1);
assert_relative_eq!(proj.right(), 1.0, epsilon = 1.0e-6);

pub fn bottom(&self) -> N[src]

The bottom offset of the view cuboid.

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
assert_relative_eq!(proj.bottom(), 2.0, epsilon = 1.0e-6);

let proj = Orthographic3::new(10.0, 1.0, 20.0, 2.0, 1000.0, 0.1);
assert_relative_eq!(proj.bottom(), 20.0, epsilon = 1.0e-6);

pub fn top(&self) -> N[src]

The top offset of the view cuboid.

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
assert_relative_eq!(proj.top(), 20.0, epsilon = 1.0e-6);

let proj = Orthographic3::new(10.0, 1.0, 20.0, 2.0, 1000.0, 0.1);
assert_relative_eq!(proj.top(), 2.0, epsilon = 1.0e-6);

pub fn znear(&self) -> N[src]

The near plane offset of the view cuboid.

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
assert_relative_eq!(proj.znear(), 0.1, epsilon = 1.0e-6);

let proj = Orthographic3::new(10.0, 1.0, 20.0, 2.0, 1000.0, 0.1);
assert_relative_eq!(proj.znear(), 1000.0, epsilon = 1.0e-6);

pub fn zfar(&self) -> N[src]

The far plane offset of the view cuboid.

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
assert_relative_eq!(proj.zfar(), 1000.0, epsilon = 1.0e-6);

let proj = Orthographic3::new(10.0, 1.0, 20.0, 2.0, 1000.0, 0.1);
assert_relative_eq!(proj.zfar(), 0.1, epsilon = 1.0e-6);

pub fn project_point(&self, p: &Point<N, U3>) -> Point<N, U3>[src]

Projects a point. Faster than matrix multiplication.

Example

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);

let p1 = Point3::new(1.0, 2.0, -0.1);
let p2 = Point3::new(1.0, 2.0, -1000.0);
let p3 = Point3::new(1.0, 20.0, -0.1);
let p4 = Point3::new(1.0, 20.0, -1000.0);
let p5 = Point3::new(10.0, 2.0, -0.1);
let p6 = Point3::new(10.0, 2.0, -1000.0);
let p7 = Point3::new(10.0, 20.0, -0.1);
let p8 = Point3::new(10.0, 20.0, -1000.0);

assert_relative_eq!(proj.project_point(&p1), Point3::new(-1.0, -1.0, -1.0));
assert_relative_eq!(proj.project_point(&p2), Point3::new(-1.0, -1.0,  1.0));
assert_relative_eq!(proj.project_point(&p3), Point3::new(-1.0,  1.0, -1.0));
assert_relative_eq!(proj.project_point(&p4), Point3::new(-1.0,  1.0,  1.0));
assert_relative_eq!(proj.project_point(&p5), Point3::new( 1.0, -1.0, -1.0));
assert_relative_eq!(proj.project_point(&p6), Point3::new( 1.0, -1.0,  1.0));
assert_relative_eq!(proj.project_point(&p7), Point3::new( 1.0,  1.0, -1.0));
assert_relative_eq!(proj.project_point(&p8), Point3::new( 1.0,  1.0,  1.0));

pub fn unproject_point(&self, p: &Point<N, U3>) -> Point<N, U3>[src]

Un-projects a point. Faster than multiplication by the underlying matrix inverse.

Example

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);

let p1 = Point3::new(-1.0, -1.0, -1.0);
let p2 = Point3::new(-1.0, -1.0,  1.0);
let p3 = Point3::new(-1.0,  1.0, -1.0);
let p4 = Point3::new(-1.0,  1.0,  1.0);
let p5 = Point3::new( 1.0, -1.0, -1.0);
let p6 = Point3::new( 1.0, -1.0,  1.0);
let p7 = Point3::new( 1.0,  1.0, -1.0);
let p8 = Point3::new( 1.0,  1.0,  1.0);

assert_relative_eq!(proj.unproject_point(&p1), Point3::new(1.0, 2.0, -0.1), epsilon = 1.0e-6);
assert_relative_eq!(proj.unproject_point(&p2), Point3::new(1.0, 2.0, -1000.0), epsilon = 1.0e-6);
assert_relative_eq!(proj.unproject_point(&p3), Point3::new(1.0, 20.0, -0.1), epsilon = 1.0e-6);
assert_relative_eq!(proj.unproject_point(&p4), Point3::new(1.0, 20.0, -1000.0), epsilon = 1.0e-6);
assert_relative_eq!(proj.unproject_point(&p5), Point3::new(10.0, 2.0, -0.1), epsilon = 1.0e-6);
assert_relative_eq!(proj.unproject_point(&p6), Point3::new(10.0, 2.0, -1000.0), epsilon = 1.0e-6);
assert_relative_eq!(proj.unproject_point(&p7), Point3::new(10.0, 20.0, -0.1), epsilon = 1.0e-6);
assert_relative_eq!(proj.unproject_point(&p8), Point3::new(10.0, 20.0, -1000.0), epsilon = 1.0e-6);

pub fn project_vector<SB>(
    &self,
    p: &Matrix<N, U3, U1, SB>
) -> Matrix<N, U3, U1, <DefaultAllocator as Allocator<N, U3, U1>>::Buffer> where
    SB: Storage<N, U3, U1>, 
[src]

Projects a vector. Faster than matrix multiplication.

Vectors are not affected by the translation part of the projection.

Example

let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);

let v1 = Vector3::x();
let v2 = Vector3::y();
let v3 = Vector3::z();

assert_relative_eq!(proj.project_vector(&v1), Vector3::x() * 2.0 / 9.0);
assert_relative_eq!(proj.project_vector(&v2), Vector3::y() * 2.0 / 18.0);
assert_relative_eq!(proj.project_vector(&v3), Vector3::z() * -2.0 / 999.9);

pub fn set_left(&mut self, left: N)[src]

Sets the left offset of the view cuboid.

let mut proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
proj.set_left(2.0);
assert_relative_eq!(proj.left(), 2.0, epsilon = 1.0e-6);

// It is OK to set a left offset greater than the current right offset.
proj.set_left(20.0);
assert_relative_eq!(proj.left(), 20.0, epsilon = 1.0e-6);

pub fn set_right(&mut self, right: N)[src]

Sets the right offset of the view cuboid.

let mut proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
proj.set_right(15.0);
assert_relative_eq!(proj.right(), 15.0, epsilon = 1.0e-6);

// It is OK to set a right offset smaller than the current left offset.
proj.set_right(-3.0);
assert_relative_eq!(proj.right(), -3.0, epsilon = 1.0e-6);

pub fn set_bottom(&mut self, bottom: N)[src]

Sets the bottom offset of the view cuboid.

let mut proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
proj.set_bottom(8.0);
assert_relative_eq!(proj.bottom(), 8.0, epsilon = 1.0e-6);

// It is OK to set a bottom offset greater than the current top offset.
proj.set_bottom(50.0);
assert_relative_eq!(proj.bottom(), 50.0, epsilon = 1.0e-6);

pub fn set_top(&mut self, top: N)[src]

Sets the top offset of the view cuboid.

let mut proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
proj.set_top(15.0);
assert_relative_eq!(proj.top(), 15.0, epsilon = 1.0e-6);

// It is OK to set a top offset smaller than the current bottom offset.
proj.set_top(-3.0);
assert_relative_eq!(proj.top(), -3.0, epsilon = 1.0e-6);

pub fn set_znear(&mut self, znear: N)[src]

Sets the near plane offset of the view cuboid.

let mut proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
proj.set_znear(8.0);
assert_relative_eq!(proj.znear(), 8.0, epsilon = 1.0e-6);

// It is OK to set a znear greater than the current zfar.
proj.set_znear(5000.0);
assert_relative_eq!(proj.znear(), 5000.0, epsilon = 1.0e-6);

pub fn set_zfar(&mut self, zfar: N)[src]

Sets the far plane offset of the view cuboid.

let mut proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
proj.set_zfar(15.0);
assert_relative_eq!(proj.zfar(), 15.0, epsilon = 1.0e-6);

// It is OK to set a zfar smaller than the current znear.
proj.set_zfar(-3.0);
assert_relative_eq!(proj.zfar(), -3.0, epsilon = 1.0e-6);

pub fn set_left_and_right(&mut self, left: N, right: N)[src]

Sets the view cuboid offsets along the x axis.

let mut proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
proj.set_left_and_right(7.0, 70.0);
assert_relative_eq!(proj.left(), 7.0, epsilon = 1.0e-6);
assert_relative_eq!(proj.right(), 70.0, epsilon = 1.0e-6);

// It is also OK to have `left > right`.
proj.set_left_and_right(70.0, 7.0);
assert_relative_eq!(proj.left(), 70.0, epsilon = 1.0e-6);
assert_relative_eq!(proj.right(), 7.0, epsilon = 1.0e-6);

pub fn set_bottom_and_top(&mut self, bottom: N, top: N)[src]

Sets the view cuboid offsets along the y axis.

let mut proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
proj.set_bottom_and_top(7.0, 70.0);
assert_relative_eq!(proj.bottom(), 7.0, epsilon = 1.0e-6);
assert_relative_eq!(proj.top(), 70.0, epsilon = 1.0e-6);

// It is also OK to have `bottom > top`.
proj.set_bottom_and_top(70.0, 7.0);
assert_relative_eq!(proj.bottom(), 70.0, epsilon = 1.0e-6);
assert_relative_eq!(proj.top(), 7.0, epsilon = 1.0e-6);

pub fn set_znear_and_zfar(&mut self, znear: N, zfar: N)[src]

Sets the near and far plane offsets of the view cuboid.

let mut proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0);
proj.set_znear_and_zfar(50.0, 5000.0);
assert_relative_eq!(proj.znear(), 50.0, epsilon = 1.0e-6);
assert_relative_eq!(proj.zfar(), 5000.0, epsilon = 1.0e-6);

// It is also OK to have `znear > zfar`.
proj.set_znear_and_zfar(5000.0, 0.5);
assert_relative_eq!(proj.znear(), 5000.0, epsilon = 1.0e-6);
assert_relative_eq!(proj.zfar(), 0.5, epsilon = 1.0e-6);

Trait Implementations

impl<T> AsMat<Matrix<T, U4, U4, <DefaultAllocator as Allocator<T, U4, U4>>::Buffer>> for Orthographic3<T> where
    T: RealField
[src]

impl<N> Clone for Orthographic3<N> where
    N: RealField
[src]

impl<N> Debug for Orthographic3<N> where
    N: RealField
[src]

impl<'a, N> Deserialize<'a> for Orthographic3<N> where
    N: RealField + Deserialize<'a>, 
[src]

impl<N> From<Orthographic3<N>> for Matrix<N, U4, U4, <DefaultAllocator as Allocator<N, U4, U4>>::Buffer> where
    N: RealField
[src]

impl<N> PartialEq<Orthographic3<N>> for Orthographic3<N> where
    N: RealField
[src]

impl<N> Serialize for Orthographic3<N> where
    N: RealField + Serialize
[src]

impl<T> ToMat<Matrix<T, U4, U4, <DefaultAllocator as Allocator<T, U4, U4>>::Buffer>> for Orthographic3<T> where
    T: RealField
[src]

impl<N> Copy for Orthographic3<N> where
    N: RealField
[src]

Auto Trait Implementations

impl<N> RefUnwindSafe for Orthographic3<N> where
    N: RefUnwindSafe

impl<N> Send for Orthographic3<N>

impl<N> Sync for Orthographic3<N>

impl<N> Unpin for Orthographic3<N> where
    N: Unpin

impl<N> UnwindSafe for Orthographic3<N> where
    N: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any
[src]

impl<T> DowncastSync for T where
    T: Any + Send + Sync
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoPnt<Point<T, U2>> for T where
    T: Scalar
[src]

impl<T> IntoPnt<Point<T, U3>> for T where
    T: Scalar
[src]

impl<T> IntoPnt<Point<T, U4>> for T where
    T: Scalar
[src]

impl<V> IntoPnt<V> for V[src]

impl<V> IntoVec<V> for V[src]

impl<T> JoinPnt<T, Point<T, U2>> for T where
    T: Scalar
[src]

type Output = Point<T, U3>

impl<T> JoinPnt<T, Point<T, U3>> for T where
    T: Scalar
[src]

type Output = Point<T, U4>

impl<T> JoinPnt<T, T> for T where
    T: Scalar
[src]

type Output = Point<T, U2>

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T> Scalar for T where
    T: Copy + PartialEq<T> + Debug + Any
[src]

impl<T> Serialize for T where
    T: Serialize + ?Sized
[src]

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 
[src]

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> Slottable for T where
    T: Copy
[src]