diff --git a/nalgebra-glm/Cargo.toml b/nalgebra-glm/Cargo.toml index e5de7b77..02708ef1 100644 --- a/nalgebra-glm/Cargo.toml +++ b/nalgebra-glm/Cargo.toml @@ -12,32 +12,6 @@ categories = [ "science" ] keywords = [ "linear", "algebra", "matrix", "vector", "math" ] license = "BSD-3-Clause" -[features] - -## Default to produce opengl compatible matrices and conventions -default = ["opengl_projection"] - -## Produce projection matrices and default to coordinate space behaviour that is compatible with OpenGL's NDC space -opengl_projection = ["right_hand_default", "negone_to_one_clip_default"] - -## Produce projection matrices and default to coordinate space behaviour that is compatible with Vulkan's NDC space -vulkan_projection = ["right_hand_default", "zero_to_one_clip_default", "projection_y_flip"] - -## Produce projection matrices and default to coordinate space behaviour that is compatible with DirectX's NDC space -directx_projection = ["left_hand_default", "zero_to_one_clip_default"] - -## Applies an implicit `mat[(1,1)] *= -1` to all projection matrices. Essentially flips the output of using the matrix -## about the x axis (vertical flip) -projection_y_flip = [] - -## Whether to default to left hand (DirectX) or right hand (OpenGL/Vulkan) coordinate system behaviour -left_hand_default = [] -right_hand_default = [] - -## Whether to default to 0 to 1 depth range (DirectX, Vulkan, Metal) or -1 to 1 (OpenGL) behaviour -zero_to_one_clip_default = [] -negone_to_one_clip_default = [] - [dependencies] num-traits = { version = "0.2", default-features = false } approx = { version = "0.3", default-features = false } diff --git a/nalgebra-glm/src/ext/matrix_clip_space.rs b/nalgebra-glm/src/ext/matrix_clip_space.rs index 8739d018..bedc34ac 100644 --- a/nalgebra-glm/src/ext/matrix_clip_space.rs +++ b/nalgebra-glm/src/ext/matrix_clip_space.rs @@ -53,8 +53,7 @@ use na::{Real}; // unimplemented!() //} -/// Creates a matrix for a orthographic-view frustum with a handedness and depth range defined by -/// the defaults configured for the library at build time +/// Creates a matrix for a right hand orthographic-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -65,69 +64,8 @@ use na::{Real}; /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 3 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. left_hand_default/right_hand_default -/// 3. zero_to_one_clip_default/negone_to_one_clip_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### left_hand_default/right_hand_default -/// Depending on which option is set the function will return either a left hand or a right -/// hand orthographic matrix. -/// -/// ##### zero_to_one_clip_default/negone_to_one_clip_default -/// Depending on which option is set the function will return a orthographic matrix meant for a -/// 0 to 1 depth clip space or a -1 to 1 depth clip space. -/// pub fn ortho(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - if cfg!(feature="zero_to_one_clip_default") { - ortho_zo(left, right, bottom, top, znear, zfar) - } else if cfg!(feature="negone_to_one_clip_default") { - ortho_no(left, right, bottom, top, znear, zfar) - } else { - unimplemented!() - } -} - -/// Creates a left hand matrix for a orthographic-view frustum with a depth range defined by the -/// default configured for the library at build time -/// -/// # Parameters -/// -/// * `left` - Coordinate for left bound of matrix -/// * `right` - Coordinate for right bound of matrix -/// * `bottom` - Coordinate for bottom bound of matrix -/// * `top` - Coordinate for top bound of matrix -/// * `znear` - Distance from the viewer to the near clipping plane -/// * `zfar` - Distance from the viewer to the far clipping plane -/// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. zero_to_one_clip_default/negone_to_one_clip_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### zero_to_one_clip_default/negone_to_one_clip_default -/// Depending on which option is set the function will return a orthographic matrix meant for a -/// 0 to 1 depth clip space or a -1 to 1 depth clip space. -/// -pub fn ortho_lh(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - if cfg!(feature="zero_to_one_clip_default") { - ortho_zo(left, right, bottom, top, znear, zfar) - } else if cfg!(feature="negone_to_one_clip_default") { - ortho_no(left, right, bottom, top, znear, zfar) - } else { - unimplemented!() - } + ortho_rh_no(left, right, bottom, top, znear, zfar) } /// Creates a left hand matrix for a orthographic-view frustum with a depth range of -1 to 1 @@ -141,34 +79,28 @@ pub fn ortho_lh(left: N, right: N, bottom: N, top: N, znear: N, zfar: N /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -/// # Compile Options +pub fn ortho_lh(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { + ortho_lh_no(left, right, bottom, top, znear, zfar) +} + +/// Creates a left hand matrix for a orthographic-view frustum with a depth range of -1 to 1 /// -/// There are 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip +/// # Parameters /// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. +/// * `left` - Coordinate for left bound of matrix +/// * `right` - Coordinate for right bound of matrix +/// * `bottom` - Coordinate for bottom bound of matrix +/// * `top` - Coordinate for top bound of matrix +/// * `znear` - Distance from the viewer to the near clipping plane +/// * `zfar` - Distance from the viewer to the far clipping plane /// pub fn ortho_lh_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - let zero : N = ::convert(0.0); - let one : N = ::convert(1.0); - let two : N = ::convert(2.0); - let mut mat : TMat4 = TMat4::::new(one ,zero,zero,zero, - zero,one ,zero,zero, - zero,zero,one ,zero, - zero,zero,zero,one ); - - let m11 = - if cfg!(feature="projection_y_flip") { - (two/(top-bottom)) * ::convert(-1.0) - } else { - (two/(top-bottom)) - }; + let two : N = ::convert(2.0); + let mut mat : TMat4 = TMat4::::identity(); mat[(0,0)] = two / (right - left); mat[(0,3)] = -(right + left) / (right - left); - mat[(1,1)] = m11; + mat[(1,1)] = two / (top-bottom); mat[(1,3)] = -(top + bottom) / (top - bottom); mat[(2,2)] = two / (zfar - znear); mat[(2,3)] = -(zfar + znear) / (zfar - znear); @@ -176,7 +108,7 @@ pub fn ortho_lh_no(left: N, right: N, bottom: N, top: N, znear: N, zfar mat } -/// Creates a left hand matrix for a orthographic-view frustum with a depth range of 0 to 1 +/// Creates a matrix for a left hand orthographic-view frustum with a depth range of 0 to 1 /// /// # Parameters /// @@ -187,34 +119,14 @@ pub fn ortho_lh_no(left: N, right: N, bottom: N, top: N, znear: N, zfar /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// pub fn ortho_lh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - let zero : N = ::convert(0.0); - let one : N = ::convert(1.0); + let one : N = N::one(); let two : N = ::convert(2.0); - let mut mat : TMat4 = TMat4::::new(one ,zero,zero,zero, - zero,one ,zero,zero, - zero,zero,one ,zero, - zero,zero,zero,one ); - - let m11 = - if cfg!(feature="projection_y_flip") { - (two/(top-bottom)) * ::convert(-1.0) - } else { - (two/(top-bottom)) - }; + let mut mat : TMat4 = TMat4::::identity(); mat[(0,0)] = two / (right - left); mat[(0,3)] = - (right + left) / (right - left); - mat[(1,1)] = m11; + mat[(1,1)] = two / (top - bottom); mat[(1,3)] = - (top + bottom) / (top - bottom); mat[(2,2)] = one / (zfar - znear); mat[(2,3)] = - znear / (zfar - znear); @@ -222,8 +134,7 @@ pub fn ortho_lh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar mat } -/// Creates a matrix for a orthographic-view frustum with a handedness defined by the defaults -/// configured for the library at build time and a depth range of -1 to 1 +/// Creates a matrix for a right hand orthographic-view frustum with a depth range of 0 to 1 /// /// # Parameters /// @@ -234,32 +145,11 @@ pub fn ortho_lh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. left_hand_default/right_hand_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### left_hand_default/right_hand_default -/// Depending on which option is set the function will return either a left hand or a right -/// hand orthographic matrix. -/// pub fn ortho_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - if cfg!(feature="left_hand_default") { - ortho_lh_no(left, right, bottom, top, znear, zfar) - } else if cfg!(feature="right_hand_default") { - ortho_rh_no(left, right, bottom, top, znear, zfar) - } else { - unimplemented!() - } + ortho_rh_no(left, right, bottom, top, znear, zfar) } -/// Creates a right hand matrix for a orthographic-view frustum with a depth range defined by the -/// default configured for the library at build time +/// Creates a matrix for a right hand orthographic-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -270,31 +160,11 @@ pub fn ortho_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. zero_to_one_clip_default/negone_to_one_clip_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### zero_to_one_clip_default/negone_to_one_clip_default -/// Depending on which option is set the function will return a orthographic matrix meant for a -/// 0 to 1 depth clip space or a -1 to 1 depth clip space. -/// pub fn ortho_rh(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - if cfg!(feature="zero_to_one_clip_default") { - ortho_rh_zo(left, right, bottom, top, znear, zfar) - } else if cfg!(feature="negone_to_one_clip_default") { - ortho_rh_no(left, right, bottom, top, znear, zfar) - } else { - unimplemented!() - } + ortho_rh_no(left, right, bottom, top, znear, zfar) } -/// Creates a right hand matrix for a orthographic-view frustum with a depth range of -1 to 1 +/// Creates a matrix for a right hand orthographic-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -305,34 +175,13 @@ pub fn ortho_rh(left: N, right: N, bottom: N, top: N, znear: N, zfar: N /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// pub fn ortho_rh_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - let zero : N = ::convert(0.0); - let one : N = ::convert(1.0); - let two : N = ::convert(2.0); - let mut mat : TMat4 = TMat4::::new(one ,zero,zero,zero, - zero,one ,zero,zero, - zero,zero,one ,zero, - zero,zero,zero,one ); - - let m11 = - if cfg!(feature="projection_y_flip") { - (two/(top-bottom)) * ::convert(-1.0) - } else { - (two/(top-bottom)) - }; + let two : N = ::convert(2.0); + let mut mat : TMat4 = TMat4::::identity(); mat[(0,0)] = two / (right - left); mat[(0,3)] = - (right + left) / (right - left); - mat[(1,1)] = m11; + mat[(1,1)] = two/(top-bottom); mat[(1,3)] = - (top + bottom) / (top - bottom); mat[(2,2)] = - two / (zfar - znear); mat[(2,3)] = - (zfar + znear) / (zfar - znear); @@ -351,34 +200,14 @@ pub fn ortho_rh_no(left: N, right: N, bottom: N, top: N, znear: N, zfar /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// pub fn ortho_rh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - let zero : N = ::convert(0.0); - let one : N = ::convert(1.0); - let two : N = ::convert(2.0); - let mut mat : TMat4 = TMat4::::new(one ,zero,zero,zero, - zero,one ,zero,zero, - zero,zero,one ,zero, - zero,zero,zero,one ); - - let m11 = - if cfg!(feature="projection_y_flip") { - (two/(top-bottom)) * ::convert(-1.0) - } else { - (two/(top-bottom)) - }; + let one : N = N::one(); + let two : N = ::convert(2.0); + let mut mat : TMat4 = TMat4::::identity(); mat[(0,0)] = two / (right - left); mat[(0,3)] = - (right + left) / (right - left); - mat[(1,1)] = m11; + mat[(1,1)] = two/(top-bottom); mat[(1,3)] = - (top + bottom) / (top - bottom); mat[(2,2)] = - one / (zfar - znear); mat[(2,3)] = - znear / (zfar - znear); @@ -386,8 +215,7 @@ pub fn ortho_rh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar mat } -/// Creates a matrix for a orthographic-view frustum with a handedness defined by the defaults -/// configured for the library at build time and a depth range of 0 to 1 +/// Creates a right hand matrix for a orthographic-view frustum with a depth range of 0 to 1 /// /// # Parameters /// @@ -398,32 +226,11 @@ pub fn ortho_rh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. left_hand_default/right_hand_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### left_hand_default/right_hand_default -/// Depending on which option is set the function will return either a left hand or a right -/// hand orthographic matrix. -/// pub fn ortho_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - if cfg!(feature="left_hand_default") { - ortho_lh_zo(left, right, bottom, top, znear, zfar) - } else if cfg!(feature="right_hand_default") { - ortho_rh_zo(left, right, bottom, top, znear, zfar) - } else { - unimplemented!() - } + ortho_rh_zo(left, right, bottom, top, znear, zfar) } -/// Creates a matrix for a perspective-view frustum with a handedness and depth range defined by the -/// defaults configured for the library at build time +/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -433,37 +240,11 @@ pub fn ortho_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 3 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. left_hand_default/right_hand_default -/// 3. zero_to_one_clip_default/negone_to_one_clip_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### left_hand_default/right_hand_default -/// Depending on which option is set the function will return either a left hand or a right -/// hand perspective matrix. -/// -/// ##### zero_to_one_clip_default/negone_to_one_clip_default -/// Depending on which option is set the function will return a perspective matrix meant for a -/// 0 to 1 depth clip space or a -1 to 1 depth clip space. -/// pub fn perspective_fov(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { - if cfg!(feature="zero_to_one_clip_default") { - perspective_fov_zo(fov, width, height, near, far) - } else if cfg!(feature="negone_to_one_clip_default") { - perspective_fov_no(fov, width, height, near, far) - } else { - unimplemented!() - } + perspective_fov_rh_no(fov, width, height, near, far) } -/// Creates a left handed matrix for a perspective-view frustum with a depth range defined by the -/// defaults configured for the library at build time +/// Creates a matrix for a left hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -473,31 +254,11 @@ pub fn perspective_fov(fov: N, width: N, height: N, near: N, far: N) -> /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. zero_to_one_clip_default/negone_to_one_clip_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### zero_to_one_clip_default/negone_to_one_clip_default -/// Depending on which option is set the function will return a perspective matrix meant for a -/// 0 to 1 depth clip space or a -1 to 1 depth clip space. -/// pub fn perspective_fov_lh(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { - if cfg!(feature="zero_to_one_clip_default") { - perspective_fov_lh_zo(fov, width, height, near, far) - } else if cfg!(feature="negone_to_one_clip_default") { - perspective_fov_lh_no(fov, width, height, near, far) - } else { - unimplemented!() - } + perspective_fov_lh_no(fov, width, height, near, far) } -/// Creates a left hand matrix for a perspective-view frustum with a -1 to 1 depth range +/// Creates a matrix for a left hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -507,15 +268,6 @@ pub fn perspective_fov_lh(fov: N, width: N, height: N, near: N, far: N) /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There is 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// pub fn perspective_fov_lh_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { assert!( width > N::zero(), @@ -530,7 +282,7 @@ pub fn perspective_fov_lh_no(fov: N, width: N, height: N, near: N, far: "The fov must be greater than zero" ); - let zero : N = ::convert( 0.0); + let zero : N = N::zero(); let mut mat : TMat4 = TMat4::::new(zero,zero,zero,zero, zero,zero,zero,zero, zero,zero,zero,zero, @@ -540,23 +292,16 @@ pub fn perspective_fov_lh_no(fov: N, width: N, height: N, near: N, far: let h = (rad * ::convert(0.5)).cos() / (rad * ::convert(0.5)).sin(); let w = h * height / width; - let m11 = - if cfg!(feature="projection_y_flip") { - h * ::convert(-1.0) - } else { - h - }; - mat[(0,0)] = w; - mat[(1,1)] = m11; + mat[(1,1)] = h; mat[(2,2)] = (far + near) / (far - near); mat[(2,3)] = - (far * near * ::convert(2.0)) / (far - near); - mat[(3,2)] = ::convert(1.0); + mat[(3,2)] = N::one(); mat } -/// Creates a left hand matrix for a perspective-view frustum with a 0 to 1 depth range +/// Creates a matrix for a left hand perspective-view frustum with a depth range of 0 to 1 /// /// # Parameters /// @@ -566,15 +311,6 @@ pub fn perspective_fov_lh_no(fov: N, width: N, height: N, near: N, far: /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There is 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// pub fn perspective_fov_lh_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { assert!( width > N::zero(), @@ -589,7 +325,7 @@ pub fn perspective_fov_lh_zo(fov: N, width: N, height: N, near: N, far: "The fov must be greater than zero" ); - let zero : N = ::convert( 0.0); + let zero : N = N::zero(); let mut mat : TMat4 = TMat4::::new(zero,zero,zero,zero, zero,zero,zero,zero, zero,zero,zero,zero, @@ -599,24 +335,16 @@ pub fn perspective_fov_lh_zo(fov: N, width: N, height: N, near: N, far: let h = (rad * ::convert(0.5)).cos() / (rad * ::convert(0.5)).sin(); let w = h * height / width; - let m11 = - if cfg!(feature="projection_y_flip") { - h * ::convert(-1.0) - } else { - h - }; - mat[(0,0)] = w; - mat[(1,1)] = m11; + mat[(1,1)] = h; mat[(2,2)] = far / (far - near); mat[(2,3)] = -(far * near) / (far - near); - mat[(3,2)] = ::convert(1.0); + mat[(3,2)] = N::one(); mat } -/// Creates a matrix for a perspective-view frustum with a handedness defined by the defaults -/// configured for the library at build time and a depth range of -1 to 1 +/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -626,32 +354,11 @@ pub fn perspective_fov_lh_zo(fov: N, width: N, height: N, near: N, far: /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. left_hand_default/right_hand_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### left_hand_default/right_hand_default -/// Depending on which option is set the function will return either a left hand or a right -/// hand perspective matrix. -/// pub fn perspective_fov_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { - if cfg!(feature="left_hand_default") { - perspective_fov_lh_no(fov, width, height, near, far) - } else if cfg!(feature="right_hand_default") { - perspective_fov_rh_no(fov, width, height, near, far) - } else { - unimplemented!() - } + perspective_fov_rh_no(fov, width, height, near, far) } -/// Creates a right handed matrix for a perspective-view frustum with a depth range defined by the -/// defaults configured for the library at build time +/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -661,31 +368,11 @@ pub fn perspective_fov_no(fov: N, width: N, height: N, near: N, far: N) /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. zero_to_one_clip_default/negone_to_one_clip_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### zero_to_one_clip_default/negone_to_one_clip_default -/// Depending on which option is set the function will return a perspective matrix meant for a -/// 0 to 1 depth clip space or a -1 to 1 depth clip space. -/// pub fn perspective_fov_rh(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { - if cfg!(feature="zero_to_one_clip_default") { - perspective_fov_rh_zo(fov, width, height, near, far) - } else if cfg!(feature="negone_to_one_clip_default") { - perspective_fov_rh_no(fov, width, height, near, far) - } else { - unimplemented!() - } + perspective_fov_rh_no(fov, width, height, near, far) } -/// Creates a right hand matrix for a perspective-view frustum with a -1 to 1 depth range +/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -695,15 +382,6 @@ pub fn perspective_fov_rh(fov: N, width: N, height: N, near: N, far: N) /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There is 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// pub fn perspective_fov_rh_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { assert!( width > N::zero(), @@ -718,8 +396,7 @@ pub fn perspective_fov_rh_no(fov: N, width: N, height: N, near: N, far: "The fov must be greater than zero" ); - let negone : N = ::convert(-1.0); - let zero : N = ::convert( 0.0); + let zero : N = N::zero(); let mut mat : TMat4 = TMat4::::new(zero,zero,zero,zero, zero,zero,zero,zero, zero,zero,zero,zero, @@ -729,23 +406,16 @@ pub fn perspective_fov_rh_no(fov: N, width: N, height: N, near: N, far: let h = (rad * ::convert(0.5)).cos() / (rad * ::convert(0.5)).sin(); let w = h * height / width; - let m11 = - if cfg!(feature="projection_y_flip") { - h * ::convert(-1.0) - } else { - h - }; - mat[(0,0)] = w; - mat[(1,1)] = m11; + mat[(1,1)] = h; mat[(2,2)] = - (far + near) / (far - near); mat[(2,3)] = - (far * near * ::convert(2.0)) / (far - near); - mat[(3,2)] = negone; + mat[(3,2)] = -N::one(); mat } -/// Creates a right hand matrix for a perspective-view frustum with a 0 to 1 depth range +/// Creates a matrix for a right hand perspective-view frustum with a depth range of 0 to 1 /// /// # Parameters /// @@ -755,15 +425,6 @@ pub fn perspective_fov_rh_no(fov: N, width: N, height: N, near: N, far: /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There is 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// pub fn perspective_fov_rh_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { assert!( width > N::zero(), @@ -778,8 +439,7 @@ pub fn perspective_fov_rh_zo(fov: N, width: N, height: N, near: N, far: "The fov must be greater than zero" ); - let negone : N = ::convert(-1.0); - let zero : N = ::convert( 0.0); + let zero : N = N::zero(); let mut mat : TMat4 = TMat4::::new(zero,zero,zero,zero, zero,zero,zero,zero, zero,zero,zero,zero, @@ -789,24 +449,16 @@ pub fn perspective_fov_rh_zo(fov: N, width: N, height: N, near: N, far: let h = (rad * ::convert(0.5)).cos() / (rad * ::convert(0.5)).sin(); let w = h * height / width; - let m11 = - if cfg!(feature="projection_y_flip") { - h * ::convert(-1.0) - } else { - h - }; - mat[(0,0)] = w; - mat[(1,1)] = m11; + mat[(1,1)] = h; mat[(2,2)] = far / (near - far); mat[(2,3)] = -(far * near) / (far - near); - mat[(3,2)] = negone; + mat[(3,2)] = -N::one(); mat } -/// Creates a matrix for a perspective-view frustum with a handedness defined by the defaults -/// configured for the library at build time and a depth range of 0 to 1 +/// Creates a matrix for a right hand perspective-view frustum with a depth range of 0 to 1 /// /// # Parameters /// @@ -816,32 +468,11 @@ pub fn perspective_fov_rh_zo(fov: N, width: N, height: N, near: N, far: /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. left_hand_default/right_hand_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### left_hand_default/right_hand_default -/// Depending on which option is set the function will return either a left hand or a right -/// hand perspective matrix. -/// pub fn perspective_fov_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { - if cfg!(feature="left_hand_default") { - perspective_fov_lh_zo(fov, width, height, near, far) - } else if cfg!(feature="right_hand_default") { - perspective_fov_rh_zo(fov, width, height, near, far) - } else { - unimplemented!() - } + perspective_fov_rh_zo(fov, width, height, near, far) } -/// Creates a matrix for a perspective-view frustum with a handedness and depth range defined by the -/// defaults configured for the library at build time +/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -850,25 +481,6 @@ pub fn perspective_fov_zo(fov: N, width: N, height: N, near: N, far: N) /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 3 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. left_hand_default/right_hand_default -/// 3. zero_to_one_clip_default/negone_to_one_clip_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### left_hand_default/right_hand_default -/// Depending on which option is set the function will return either a left hand or a right -/// hand perspective matrix. -/// -/// ##### zero_to_one_clip_default/negone_to_one_clip_default -/// Depending on which option is set the function will return a perspective matrix meant for a -/// 0 to 1 depth clip space or a -1 to 1 depth clip space. -/// pub fn perspective(aspect: N, fovy: N, near: N, far: N) -> TMat4 { // TODO: Breaking change - the arguments can be reversed back to proper glm conventions // @@ -884,17 +496,10 @@ pub fn perspective(aspect: N, fovy: N, near: N, far: N) -> TMat4 { // people's code. Reordering to glm isn't a huge deal but if it is done it will have to be // in a major API breaking update. // - if cfg!(feature="zero_to_one_clip_default") { - perspective_zo(aspect, fovy, near, far) - } else if cfg!(feature="negone_to_one_clip_default") { - perspective_no(aspect, fovy, near, far) - } else { - unimplemented!() - } + perspective_rh_no(aspect, fovy, near, far) } -/// Creates a left handed matrix for a perspective-view frustum with a depth range defined by the -/// defaults configured for the library at build time +/// Creates a matrix for a left hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -903,31 +508,11 @@ pub fn perspective(aspect: N, fovy: N, near: N, far: N) -> TMat4 { /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. zero_to_one_clip_default/negone_to_one_clip_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### zero_to_one_clip_default/negone_to_one_clip_default -/// Depending on which option is set the function will return a perspective matrix meant for a -/// 0 to 1 depth clip space or a -1 to 1 depth clip space. -/// pub fn perspective_lh(aspect: N, fovy: N, near: N, far: N) -> TMat4 { - if cfg!(feature="zero_to_one_clip_default") { - perspective_lh_zo(fovy, aspect, near, far) - } else if cfg!(feature="negone_to_one_clip_default") { - perspective_lh_no(fovy, aspect, near, far) - } else { - unimplemented!() - } + perspective_lh_no(fovy, aspect, near, far) } -/// Creates a left hand matrix for a perspective-view frustum with a -1 to 1 depth range +/// Creates a matrix for a left hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -936,15 +521,6 @@ pub fn perspective_lh(aspect: N, fovy: N, near: N, far: N) -> TMat4 /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There is 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// pub fn perspective_lh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4 { assert!( !relative_eq!(far - near, N::zero()), @@ -955,8 +531,8 @@ pub fn perspective_lh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4< "The apsect ratio must not be zero." ); - let zero : N = ::convert( 0.0); - let one : N = ::convert( 1.0); + let zero : N = N::zero(); + let one : N = N::one(); let two : N = ::convert( 2.0); let mut mat : TMat4 = TMat4::::new(zero,zero,zero,zero, zero,zero,zero,zero, @@ -965,15 +541,8 @@ pub fn perspective_lh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4< let tan_half_fovy = (fovy / two).tan(); - let m11 = - if cfg!(feature="projection_y_flip") { - (one / tan_half_fovy) * ::convert(-1.0) - } else { - (one / tan_half_fovy) - }; - mat[(0,0)] = one / (aspect * tan_half_fovy); - mat[(1,1)] = m11; + mat[(1,1)] = one / tan_half_fovy; mat[(2,2)] = (far + near) / (far - near); mat[(2,3)] = -(two * far * near) / (far - near); mat[(3,2)] = one; @@ -981,7 +550,7 @@ pub fn perspective_lh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4< mat } -/// Creates a left hand matrix for a perspective-view frustum with a 0 to 1 depth range +/// Creates a matrix for a left hand perspective-view frustum with a depth range of 0 to 1 /// /// # Parameters /// @@ -990,15 +559,6 @@ pub fn perspective_lh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4< /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There is 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// pub fn perspective_lh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4 { assert!( !relative_eq!(far - near, N::zero()), @@ -1009,8 +569,8 @@ pub fn perspective_lh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4< "The apsect ratio must not be zero." ); - let zero : N = ::convert( 0.0); - let one : N = ::convert( 1.0); + let zero : N = N::zero(); + let one : N = N::one(); let two : N = ::convert( 2.0); let mut mat : TMat4 = TMat4::::new(zero,zero,zero,zero, zero,zero,zero,zero, @@ -1019,15 +579,8 @@ pub fn perspective_lh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4< let tan_half_fovy = (fovy / two).tan(); - let m11 = - if cfg!(feature="projection_y_flip") { - (one / tan_half_fovy) * ::convert(-1.0) - } else { - (one / tan_half_fovy) - }; - mat[(0,0)] = one / (aspect * tan_half_fovy); - mat[(1,1)] = m11; + mat[(1,1)] = one / tan_half_fovy; mat[(2,2)] = far / (far - near); mat[(2,3)] = -(far * near) / (far - near); mat[(3,2)] = one; @@ -1035,8 +588,7 @@ pub fn perspective_lh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4< mat } -/// Creates a matrix for a perspective-view frustum with a handedness defined by the defaults -/// configured for the library at build time and a depth range of -1 to 1 +/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -1045,32 +597,11 @@ pub fn perspective_lh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4< /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. left_hand_default/right_hand_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### left_hand_default/right_hand_default -/// Depending on which option is set the function will return either a left hand or a right -/// hand perspective matrix. -/// pub fn perspective_no(aspect: N, fovy: N, near: N, far: N) -> TMat4 { - if cfg!(feature="left_hand_default") { - perspective_lh_no(aspect, fovy, near, far) - } else if cfg!(feature="right_hand_default") { - perspective_rh_no(aspect, fovy, near, far) - } else { - unimplemented!() - } + perspective_rh_no(aspect, fovy, near, far) } -/// Creates a right handed matrix for a perspective-view frustum with a depth range defined by the -/// defaults configured for the library at build time +/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -1079,31 +610,11 @@ pub fn perspective_no(aspect: N, fovy: N, near: N, far: N) -> TMat4 /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. zero_to_one_clip_default/negone_to_one_clip_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### zero_to_one_clip_default/negone_to_one_clip_default -/// Depending on which option is set the function will return a perspective matrix meant for a -/// 0 to 1 depth clip space or a -1 to 1 depth clip space. -/// pub fn perspective_rh(aspect: N, fovy: N, near: N, far: N) -> TMat4 { - if cfg!(feature="zero_to_one_clip_default") { - perspective_rh_zo(aspect, fovy, near, far) - } else if cfg!(feature="negone_to_one_clip_default") { - perspective_rh_no(aspect, fovy, near, far) - } else { - unimplemented!() - } + perspective_rh_no(aspect, fovy, near, far) } -/// Creates a right hand matrix for a perspective-view frustum with a -1 to 1 depth range +/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1 /// /// # Parameters /// @@ -1112,15 +623,6 @@ pub fn perspective_rh(aspect: N, fovy: N, near: N, far: N) -> TMat4 /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There is 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// pub fn perspective_rh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4 { assert!( !relative_eq!(far - near, N::zero()), @@ -1131,10 +633,10 @@ pub fn perspective_rh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4< "The apsect ratio must not be zero." ); - let negone : N = ::convert(-1.0); - let zero : N = ::convert( 0.0); - let one : N = ::convert( 1.0); - let two : N = ::convert( 2.0); + let negone : N = -N::one(); + let zero : N = N::zero(); + let one : N = N::one(); + let two : N = ::convert( 2.0); let mut mat : TMat4 = TMat4::::new(zero,zero,zero,zero, zero,zero,zero,zero, zero,zero,zero,zero, @@ -1142,15 +644,8 @@ pub fn perspective_rh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4< let tan_half_fovy = (fovy / two).tan(); - let m11 = - if cfg!(feature="projection_y_flip") { - (one / tan_half_fovy) * ::convert(-1.0) - } else { - (one / tan_half_fovy) - }; - mat[(0,0)] = one / (aspect * tan_half_fovy); - mat[(1,1)] = m11; + mat[(1,1)] = one / tan_half_fovy; mat[(2,2)] = - (far + near) / (far - near); mat[(2,3)] = -(two * far * near) / (far - near); mat[(3,2)] = negone; @@ -1158,7 +653,7 @@ pub fn perspective_rh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4< mat } -/// Creates a right hand matrix for a perspective-view frustum with a 0 to 1 depth range +/// Creates a matrix for a right hand perspective-view frustum with a depth range of 0 to 1 /// /// # Parameters /// @@ -1167,15 +662,6 @@ pub fn perspective_rh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4< /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There is 1 compile option that changes the behaviour of the function: -/// 1. projection_y_flip -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// pub fn perspective_rh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4 { assert!( !relative_eq!(far - near, N::zero()), @@ -1186,10 +672,10 @@ pub fn perspective_rh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4< "The apsect ratio must not be zero." ); - let negone : N = ::convert(-1.0); - let zero : N = ::convert( 0.0); - let one : N = ::convert( 1.0); - let two : N = ::convert( 2.0); + let negone : N = -N::one(); + let zero : N = N::zero(); + let one : N = N::one(); + let two : N = ::convert( 2.0); let mut mat : TMat4 = TMat4::::new(zero,zero,zero,zero, zero,zero,zero,zero, zero,zero,zero,zero, @@ -1197,15 +683,8 @@ pub fn perspective_rh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4< let tan_half_fovy = (fovy / two).tan(); - let m11 = - if cfg!(feature="projection_y_flip") { - (one / tan_half_fovy) * ::convert(-1.0) - } else { - (one / tan_half_fovy) - }; - mat[(0,0)] = one / (aspect * tan_half_fovy); - mat[(1,1)] = m11; + mat[(1,1)] = one / tan_half_fovy; mat[(2,2)] = far / (near - far); mat[(2,3)] = -(far * near) / (far - near); mat[(3,2)] = negone; @@ -1213,8 +692,7 @@ pub fn perspective_rh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4< mat } -/// Creates a matrix for a perspective-view frustum with a handedness defined by the defaults -/// configured for the library at build time and a depth range of 0 to 1 +/// Creates a matrix for a right hand perspective-view frustum with a depth range of 0 to 1 /// /// # Parameters /// @@ -1223,28 +701,8 @@ pub fn perspective_rh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4< /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. projection_y_flip -/// 2. left_hand_default/right_hand_default -/// -/// ##### projection_y_flip -/// When enabled will perform a `matrix[(1,1)] *= 1` implicitly. Primary use case is for Vulkan -/// where the viewport coordinate origin is the top left, unlike OpenGL which is the bottom left. -/// -/// ##### left_hand_default/right_hand_default -/// Depending on which option is set the function will return either a left hand or a right -/// hand perspective matrix. -/// pub fn perspective_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4 { - if cfg!(feature="left_hand_default") { - perspective_lh_zo(aspect, fovy, near, far) - } else if cfg!(feature="right_hand_default") { - perspective_rh_zo(aspect, fovy, near, far) - } else { - unimplemented!() - } + perspective_rh_zo(aspect, fovy, near, far) } //pub fn tweaked_infinite_perspective(fovy: N, aspect: N, near: N) -> TMat4 { diff --git a/nalgebra-glm/src/ext/matrix_projection.rs b/nalgebra-glm/src/ext/matrix_projection.rs index 4d6f090b..4ed23fb3 100644 --- a/nalgebra-glm/src/ext/matrix_projection.rs +++ b/nalgebra-glm/src/ext/matrix_projection.rs @@ -24,8 +24,8 @@ pub fn pick_matrix(center: &TVec2, delta: &TVec2, viewport: &TVec )) } -/// Map the specified object coordinates `(obj.x, obj.y, obj.z)` into window coordinates using -/// the default configured depth range +/// Map the specified object coordinates `(obj.x, obj.y, obj.z)` into window coordinates with a +/// depth range of -1 to 1 /// /// # Parameters: /// @@ -34,15 +34,6 @@ pub fn pick_matrix(center: &TVec2, delta: &TVec2, viewport: &TVec /// * `proj` - Specifies the current projection matrix. /// * `viewport` - Specifies the current viewport. /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. zero_to_one_clip_default/negone_to_one_clip_default -/// -/// ##### zero_to_one_clip_default/negone_to_one_clip_default -/// Depending on which option is set the function will return a point un-projected with the depth -/// range of either 0 to 1 or -1 to 1 -/// /// # See also: /// /// * [`project_no`](fn.project_no.html) @@ -57,13 +48,7 @@ pub fn project( viewport: TVec4, ) -> TVec3 { - if cfg!(feature="negone_to_one_clip_default") { - project_no(obj, model, proj, viewport) - } else if cfg!(feature="zero_to_one_clip_default") { - project_zo(obj, model, proj, viewport) - } else { - unimplemented!() - } + project_no(obj, model, proj, viewport) } /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. @@ -130,8 +115,8 @@ pub fn project_zo( ) } -/// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates using the -/// default configured depth range +/// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates using a +/// depth range of -1 to 1 /// /// # Parameters: /// @@ -140,15 +125,6 @@ pub fn project_zo( /// * `proj` - Specifies the current projection matrix. /// * `viewport` - Specifies the current viewport. /// -/// # Compile Options -/// -/// There are 2 compile options that change the behaviour of the function: -/// 1. zero_to_one_clip_default/negone_to_one_clip_default -/// -/// ##### zero_to_one_clip_default/negone_to_one_clip_default -/// Depending on which option is set the function will return a point un-projected with the depth -/// range of either 0 to 1 or -1 to 1 -/// /// # See also: /// /// * [`project`](fn.project.html) @@ -163,13 +139,7 @@ pub fn unproject( viewport: TVec4, ) -> TVec3 { - if cfg!(feature="negone_to_one_clip_default") { - unproject_no(win, model, proj, viewport) - } else if cfg!(feature="zero_to_one_clip_default") { - unproject_zo(win, model, proj, viewport) - } else { - unimplemented!() - } + unproject_no(win, model, proj, viewport) } /// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates. diff --git a/nalgebra-glm/src/ext/matrix_transform.rs b/nalgebra-glm/src/ext/matrix_transform.rs index 04fba4f7..c901a1d0 100644 --- a/nalgebra-glm/src/ext/matrix_transform.rs +++ b/nalgebra-glm/src/ext/matrix_transform.rs @@ -9,9 +9,7 @@ where DefaultAllocator: Alloc { TMat::::identity() } -/// Build a look at view matrix with a handedness based on the defaults configured for the library -/// at compile time. -/// Build a look at view matrix based on the right handedness. +/// Build a right hand look at view matrix /// /// # Parameters: /// @@ -19,27 +17,12 @@ where DefaultAllocator: Alloc { /// * `center` − Position where the camera is looking at. /// * `u` − Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)`. /// -/// # Compile Options -/// -/// There is 1 compile option that changes the behaviour of the function: -/// 1. left_hand_default/right_hand_default -/// -/// #### left_hand_default/right_hand_default -/// Depending on which option is set the function will return either a left hand or a right -/// hand matrix. It switches between using look_at_lh and look_at_rh. -/// /// # See also: /// /// * [`look_at_lh`](fn.look_at_lh.html) /// * [`look_at_rh`](fn.look_at_rh.html) pub fn look_at(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { - if cfg!(feature="right_hand_default") { - look_at_rh(eye, center, up) - } else if cfg!(feature="left_hand_default") { - look_at_lh(eye, center, up) - } else { - unimplemented!() - } + look_at_rh(eye, center, up) } /// Build a left handed look at view matrix. diff --git a/nalgebra-glm/src/gtc/quaternion.rs b/nalgebra-glm/src/gtc/quaternion.rs index 051ac360..61501776 100644 --- a/nalgebra-glm/src/gtc/quaternion.rs +++ b/nalgebra-glm/src/gtc/quaternion.rs @@ -34,30 +34,15 @@ pub fn quat_cast(x: &Qua) -> TMat4 { ::quat_to_mat4(x) } -/// Computes a look-at quaternion based on the defaults configured for the library at build time +/// Computes a right hand look-at quaternion /// /// # Parameters /// /// * `direction` - Direction vector point at where to look /// * `up` - Object up vector /// -/// # Compile Options -/// -/// There is 1 compile option that changes the behaviour of the function: -/// 1. left_hand_default/right_hand_default -/// -/// ##### left_hand_default/right_hand_default -/// Depending on which option is set the function will return either a left hand or a right -/// hand look at quaternion. -/// pub fn quat_look_at(direction: &TVec3, up: &TVec3) -> Qua { - if cfg!(feature="right_hand_default") { - quat_look_at_rh(direction, up) - } else if cfg!(feature="left_hand_default") { - quat_look_at_lh(direction, up) - } else { - unimplemented!() - } + quat_look_at_rh(direction, up) } /// Computes a left-handed look-at quaternion (equivalent to a left-handed look-at matrix). diff --git a/nalgebra-glm/src/lib.rs b/nalgebra-glm/src/lib.rs index d0cf4330..71ffc251 100644 --- a/nalgebra-glm/src/lib.rs +++ b/nalgebra-glm/src/lib.rs @@ -91,74 +91,6 @@ This must be used with care! This is actually the recommended method to convert between homogeneous transformations generated by `nalgebra-glm` and specific transformation types from **nalgebra** like `Isometry3`. Just be careful you know your conversions make sense. - ### Compile Features/Options - There are a few compile features that alters the default behaviour of some functions. The current set of compile options includes: - * opengl_projection - * vulkan_projection - * directx_projection - * projection_y_flip - * left_hand_default - * right_hand_default - * zero_to_one_clip_default - * negone_to_one_clip_default - - The default is to compile with the `opengl_projection` feature enabled - - #### opengl_projection - This is a "macro" feature that exists as an alias to `right_hand_default` and - `negone_to_one_clip_default` - - #### vulkan_projection - This is a "macro" feature that exists as an alias to `right_hand_default`, - `zero_to_one_clip_default` and `projection_y_flip` - - #### directx_projection - This is a "macro" feature that exists as an alias to `left_hand_default` and - `zero_to_one_clip_default` - - #### projection_y_flip - Applies an implicit `mat[(1,1)] *= -1` to all projection matrices created through the - nalgebra-glm interface. This feature should be enabled when using Vulkan so the generated - matrices conform to Vulkan's NDC (normalized device coordinates). - - #### left_hand_default / right_hand_default - These two options are used to change the default handedness of the coordinate system the library - will use. Depending on which option is set it would cause a function like `ortho` to switch - between using `ortho_rh` and `ortho_lh`. - - DO NOT set both of these options at the same time. There is no guarantee that all functions will - follow the same convention if you were to do so - - #### zero_to_one_clip_default / negone_to_one_clip_default - These options are used to change the default depth range for projection matrices generated by - the nalgebra-glm interface. Depending on which option is set functions like `ortho` will - statically switch between calling `ortho_zo` and `ortho_no`. - - DO NOT set both of these options at the same time. There is no guarantee that all functions will - follow the same convention if you were to do so - - #### Functions Affected - - * [`perspective`](fn.perspective.html) - * [`perspective_no`](fn.perspective_no.html) - * [`perspective_zo`](fn.perspective_zo.html) - * [`perspective_rh`](fn.perspective_rh.html) - * [`perspective_lh`](fn.perspective_lh.html) - * [`perspective_fov`](fn.perspective_fov.html) - * [`perspective_fov_no`](fn.perspective_fov_no.html) - * [`perspective_fov_zo`](fn.perspective_fov_zo.html) - * [`perspective_fov_rh`](fn.perspective_fov_rh.html) - * [`perspective_fov_lh`](fn.perspective_fov_lh.html) - * [`ortho`](fn.ortho.html) - * [`ortho_no`](fn.ortho_no.html) - * [`ortho_zo`](fn.ortho_zo.html) - * [`ortho_rh`](fn.ortho_rh.html) - * [`ortho_lh`](fn.ortho_lh.html) - * [`project`](fn.project.html) - * [`unproject`](fn.unproject.html) - * [`look_at`](fn.look_at.html) - * [`quat_look_at`](fn.quat_look_at.html) - ### Should I use nalgebra or nalgebra-glm? Well that depends on your tastes and your background. **nalgebra** is more powerful overall since it allows stronger typing, and goes much further than simple computer graphics math. However, has a bit of a learning curve for diff --git a/nalgebra-glm/tests/lib.rs b/nalgebra-glm/tests/lib.rs index 0813a7bc..88ec1a44 100644 --- a/nalgebra-glm/tests/lib.rs +++ b/nalgebra-glm/tests/lib.rs @@ -6,47 +6,31 @@ use na::Orthographic3; use glm::Mat4; use glm::Vec4; -// Ensure that under default conditions the library doesn't break interface with old convention #[test] pub fn orthographic_glm_nalgebra_same() { let na_mat : Mat4 = Orthographic3::new(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).unwrap(); - let gl_mat : Mat4 = glm::ortho_rh_no(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32); - - // ortho_rh_no is the same as the standard nalgebra orthographic matrix - // - // we cant use plain ortho here as the library could be configured to produce different values + let gl_mat : Mat4 = glm::ortho(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32); assert_eq!(na_mat, gl_mat); } -// Ensure that under default conditions the library doesn't break interface with old convention #[test] pub fn perspective_glm_nalgebra_same() { let na_mat : Mat4 = Perspective3::new(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32).unwrap(); - let gl_mat : Mat4 = glm::perspective_rh_no(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32); - - // perspective_rh_no is the same as the standard nalgebra perspective matrix - // - // we cant use plain perspective here as the library could be configured to produce different - // values + let gl_mat : Mat4 = glm::perspective(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32); assert_eq!(na_mat, gl_mat); } -// Ensure that under default conditions the library doesn't break interface with old convention #[test] pub fn orthographic_glm_nalgebra_project_same() { let point = Vec4::new(1.0,0.0,-20.0,1.0); let na_mat : Mat4 = Orthographic3::new(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).unwrap(); - let gl_mat : Mat4 = glm::ortho_rh_no(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32); - - // ortho_rh_no is the same as the standard nalgebra orthographic matrix - // - // we cant use plain ortho here as the library could be configured to produce different values + let gl_mat : Mat4 = glm::ortho(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32); let na_pt = na_mat * point; let gl_pt = gl_mat * point; @@ -55,19 +39,13 @@ pub fn orthographic_glm_nalgebra_project_same() assert_eq!(na_pt, gl_pt); } -// Ensure that under default conditions the library doesn't break interface with old convention #[test] pub fn perspective_glm_nalgebra_project_same() { let point = Vec4::new(1.0,0.0,-20.0,1.0); let na_mat : Mat4 = Perspective3::new(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32).unwrap(); - let gl_mat : Mat4 = glm::perspective_rh_no(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32); - - // perspective_rh_no is the same as the standard nalgebra perspective matrix - // - // we cant use plain perspective here as the library could be configured to produce different - // values + let gl_mat : Mat4 = glm::perspective(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32); let na_pt = na_mat * point; let gl_pt = gl_mat * point;