Add methods to see a Perspective3 or Orthographic3 as a Projective3.
This commit is contained in:
parent
350cd98a9b
commit
38c7ed3a11
|
@ -5,6 +5,7 @@ use rand::Rng;
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ use base::helper;
|
||||||
use base::storage::Storage;
|
use base::storage::Storage;
|
||||||
use base::{Matrix4, Vector, Vector3};
|
use base::{Matrix4, Vector, Vector3};
|
||||||
|
|
||||||
use geometry::Point3;
|
use geometry::{Projective3, Point3};
|
||||||
|
|
||||||
/// A 3D orthographic projection stored as an homogeneous 4x4 matrix.
|
/// A 3D orthographic projection stored as an homogeneous 4x4 matrix.
|
||||||
pub struct Orthographic3<N: Real> {
|
pub struct Orthographic3<N: Real> {
|
||||||
|
@ -158,6 +159,18 @@ impl<N: Real> Orthographic3<N> {
|
||||||
&self.matrix
|
&self.matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A reference to this transformation seen as a `Projective3`.
|
||||||
|
#[inline]
|
||||||
|
pub fn as_projective(&self) -> &Projective3<N> {
|
||||||
|
unsafe { mem::transmute(self) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This transformation seen as a `Projective3`.
|
||||||
|
#[inline]
|
||||||
|
pub fn to_projective(&self) -> Projective3<N> {
|
||||||
|
Projective3::from_matrix_unchecked(self.matrix)
|
||||||
|
}
|
||||||
|
|
||||||
/// Retrieves the underlying homogeneous matrix.
|
/// Retrieves the underlying homogeneous matrix.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn unwrap(self) -> Matrix4<N> {
|
pub fn unwrap(self) -> Matrix4<N> {
|
||||||
|
|
|
@ -6,6 +6,7 @@ use rand::Rng;
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ use base::helper;
|
||||||
use base::storage::Storage;
|
use base::storage::Storage;
|
||||||
use base::{Matrix4, Scalar, Vector, Vector3};
|
use base::{Matrix4, Scalar, Vector, Vector3};
|
||||||
|
|
||||||
use geometry::Point3;
|
use geometry::{Projective3, Point3};
|
||||||
|
|
||||||
/// A 3D perspective projection stored as an homogeneous 4x4 matrix.
|
/// A 3D perspective projection stored as an homogeneous 4x4 matrix.
|
||||||
pub struct Perspective3<N: Scalar> {
|
pub struct Perspective3<N: Scalar> {
|
||||||
|
@ -130,6 +131,18 @@ impl<N: Real> Perspective3<N> {
|
||||||
&self.matrix
|
&self.matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A reference to this transformation seen as a `Projective3`.
|
||||||
|
#[inline]
|
||||||
|
pub fn as_projective(&self) -> &Projective3<N> {
|
||||||
|
unsafe { mem::transmute(self) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This transformation seen as a `Projective3`.
|
||||||
|
#[inline]
|
||||||
|
pub fn to_projective(&self) -> Projective3<N> {
|
||||||
|
Projective3::from_matrix_unchecked(self.matrix)
|
||||||
|
}
|
||||||
|
|
||||||
/// Retrieves the underlying homogeneous matrix.
|
/// Retrieves the underlying homogeneous matrix.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn unwrap(self) -> Matrix4<N> {
|
pub fn unwrap(self) -> Matrix4<N> {
|
||||||
|
|
Loading…
Reference in New Issue