diff --git a/src/geometry/mod.rs b/src/geometry/mod.rs index a339e141..47b895c7 100644 --- a/src/geometry/mod.rs +++ b/src/geometry/mod.rs @@ -83,6 +83,7 @@ mod transform_simba; mod reflection; +mod ndc; mod orthographic; mod perspective; @@ -112,7 +113,7 @@ pub use self::transform_alias::*; pub use self::reflection::*; +pub use self::ndc::*; pub use self::orthographic::Orthographic3; pub use self::perspective::Perspective3; pub use self::perspective::Perspective3OpenGL; -pub use self::perspective::{OpenGL, Vulkan, VulkanX}; diff --git a/src/geometry/ndc.rs b/src/geometry/ndc.rs new file mode 100644 index 00000000..e951ece4 --- /dev/null +++ b/src/geometry/ndc.rs @@ -0,0 +1,22 @@ +/// Normalized device coordinates (NDC) system. +pub trait System {} + +/// Left handed with a depth range of -1 to 1. +#[derive(Default)] +pub struct LhNo {} + +impl System for LhNo {} + +/// Right handed with a depth range of 0 to 1. +#[derive(Default)] +pub struct RhZo {} + +impl System for RhZo {} + +// Aliases for commonly used NDCs. + +/// OpenGL NDC (left handed with a depth range of -1 to 1). +pub type OpenGL = LhNo; + +/// Vulkan NDC (right handed with a depth range of 0 to 1). +pub type Vulkan = RhZo; diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index b877142f..35e4f0b6 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -16,32 +16,9 @@ use crate::base::helper; use crate::base::storage::Storage; use crate::base::{Matrix4, Scalar, Vector, Vector3}; +use crate::geometry::ndc::*; use crate::geometry::{Point3, Projective3}; -/// Normalized device coordinates systems -pub trait System {} - -/// OpenGL -/// Note that we will probably want to go with more generic names that encode the handedness and depth range -/// Please consider all names as placeholders -#[derive(Default)] -pub struct OpenGL {} - -/// OpenGL is a System -impl System for OpenGL {} - -/// Vulkan is also a System -#[derive(Default)] -pub struct Vulkan {} - -/// Vulkan is also a System -impl System for Vulkan {} - -/// Note that it is possible to alias systems (OpenGL and Vulkan would be aliases of generic systems) -//pub type OpenGL = RHS_NO; -//pub type OpenGL = LHS_ZO; -pub type VulkanX = Vulkan; - /// A 3D perspective projection stored as a homogeneous 4x4 matrix. /// Perspective3 is now generic over System /// Note that : @@ -265,11 +242,8 @@ impl Perspective3 { } } -// OpenGL specialization -// For now not all required functions are specialized for sake of illustration. -// Specializating the other functions should be trivial. - -impl Perspective3 { +/// LhNo specialization (Left handed with a depth range of -1 to 1). +impl Perspective3 { /// Implementation note: new() must be specialized because it calls other specialized functions. pub fn new(aspect: N, fovy: N, znear: N, zfar: N) -> Self { assert!( @@ -318,9 +292,8 @@ impl Perspective3 { } } -// Vulkan specialization - -impl Perspective3 { +// RhZo specialization (right handed with a depth range of 0 to 1). +impl Perspective3 { /// Implementation note: new() must be specialized because it calls other specialized functions. pub fn new(aspect: N, fovy: N, znear: N, zfar: N) -> Self { assert!(