diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7bae7fa8..d76638f1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,18 +7,53 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [0.17.0] - WIP
### Added
- * Add swizzling up to dimension 3. For example, you can do `v.zxy()` as an equivalent to `Vector3::new(v.z, v.x, v.w)`.
+ * Add swizzling up to dimension 3 for vectors. For example, you can do `v.zxy()` as an equivalent to `Vector3::new(v.z, v.x, v.y)`.
+ * Add swizzling up to dimension 3 for points. For example, you can do `p.zxy()` as an equivalent to `Point3::new(p.z, p.x, p.y)`.
* Add `.copy_from_slice` to copy matrix components from a slice in column-major order.
* Add `.dot` to quaternions.
* Add `.zip_zip_map` for iterating on three matrices simultaneously, and applying a closure to them.
* Add `.slerp` and `.try_slerp` to unit vectors.
+ * Add `.lerp` to vectors.
* Add `.to_projective` and `.as_projective` to `Perspective3` and `Orthographic3` in order to
use them as `Projective3` structures.
* Add `From/Into` impls to allow the conversion of any transformation type to a matrix.
* Add `Into` impls to convert a matrix slice into an owned matrix.
* Add `Point*::from_slice` to create a point from a slice.
- * Add `.map_with_location` to matrices to apply a map which passes the component indices to the user-defined closure alongide
+ * Add `.map_with_location` to matrices to apply a map which passes the component indices to the user-defined closure alongside
the component itself.
+ * Add impl `From` for `Point`.
+ * Add impl `From` for `Quaternion`.
+ * Add impl `From` for `Translation`.
+ * Add the `::from_vec` constructor to construct a matrix from a `Vec` (a `DMatrix` will reuse the original `Vec`
+ as-is for its storage).
+ * Add `.to_homogeneous` to square matrices (and with dimensions higher than 1x1). This will increase their number of row
+ and columns by 1. The new column and row are filled with 0, except for the diagonal element which is set to 1.
+ * Implement `Extend` for matrices with a dynamic storage. The provided `Vec` is assumed to represent a column-major
+ matrix with the same number of rows as the one being extended. This will effectively append new columns on the right of
+ the matrix being extended.
+ * Implement `Extend` for vectors with a dynamic storage. This will concatenate the vector with the given `Vec`.
+ * Implement `Extend>` for matrices with dynamic storage. This will concatenate the columns of both matrices.
+ * Implement `Into` for the `MatrixVec` storage.
+ * Implement `Hash` for all matrices.
+ * Add a `.len()` method to retrieve the size of a `MatrixVec`.
+
+### Modified
+ * The orthographic projection no longer require that `bottom < top`, that `left < right`, and that `znear < zfar`. The
+ only restriction now ith that they must not be equal (in which case the projection would be singular).
+ * The `Point::from_coordinates` methods is deprecated. Use `Point::from` instead.
+ * The `.transform_point` and `.transform_vector` methods are now inherent methods for matrices so that the user does not have to
+ explicitly import the `Transform` trait from the alga crate.
+ * Renamed the matrix storage types: `MatrixArray` -> `ArrayStorage` and `MatrixVec` -> `VecStorage`.
+ * Renamed `.unwrap()` to `.into_inner()` for geometric types that wrap another type.
+ This is for the case of `Unit`, `Transform`, `Orthographic3`, `Perspective3`, `Rotation`.
+ * Deprecate several functions at the root of the crate (replaced by methods).
+
+### Removed
+ * Remove the `Deref` impl for `MatrixVec` as it could cause hard-to-understand compilation errors.
+
+### nalgebra-glm
+ * Add several alternative projection computations, e.g., `ortho_lh`, `ortho_lh_no`, `perspective_lh`, etc.
+ * Add features matching those of nalgebra, in particular: `serde-serialize`, `abmonation-serialize`, std` (enabled by default).
## [0.16.0]
All dependencies have been updated to their latest versions.
diff --git a/Cargo.toml b/Cargo.toml
index 7e2e21dd..048ec557 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "nalgebra"
-version = "0.16.12"
+version = "0.16.13"
authors = [ "Sébastien Crozet " ]
description = "Linear algebra library with transformations and statically-sized or dynamically-sized matrices."
@@ -30,23 +30,24 @@ io = [ "pest", "pest_derive" ]
[dependencies]
typenum = "1.10"
-generic-array = "0.11"
-rand = { version = "0.5", default-features = false }
+generic-array = "0.12"
+rand = { version = "0.6", default-features = false }
num-traits = { version = "0.2", default-features = false }
num-complex = { version = "0.2", default-features = false }
approx = { version = "0.3", default-features = false }
alga = { version = "0.7", default-features = false }
-matrixmultiply = { version = "0.1", optional = true }
+matrixmultiply = { version = "0.2", optional = true }
serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
-abomonation = { version = "0.5", optional = true }
+abomonation = { version = "0.7", optional = true }
mint = { version = "0.5", optional = true }
-quickcheck = { version = "0.6", optional = true }
+quickcheck = { version = "0.7", optional = true }
pest = { version = "2.0", optional = true }
pest_derive = { version = "2.0", optional = true }
[dev-dependencies]
serde_json = "1.0"
+rand_xorshift = "0.1"
[workspace]
members = [ "nalgebra-lapack", "nalgebra-glm" ]
diff --git a/README.md b/README.md
index a4c84a68..17a312be 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,9 @@
+
+
+
diff --git a/benches/common/macros.rs b/benches/common/macros.rs
index 55d6ba3c..758336a8 100644
--- a/benches/common/macros.rs
+++ b/benches/common/macros.rs
@@ -4,7 +4,8 @@ macro_rules! bench_binop(
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
#[bench]
fn $name(bh: &mut Bencher) {
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
let a = rng.gen::<$t1>();
let b = rng.gen::<$t2>();
@@ -19,7 +20,8 @@ macro_rules! bench_binop_ref(
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
#[bench]
fn $name(bh: &mut Bencher) {
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
let a = rng.gen::<$t1>();
let b = rng.gen::<$t2>();
@@ -34,7 +36,8 @@ macro_rules! bench_binop_fn(
($name: ident, $t1: ty, $t2: ty, $binop: path) => {
#[bench]
fn $name(bh: &mut Bencher) {
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
let a = rng.gen::<$t1>();
let b = rng.gen::<$t2>();
@@ -51,7 +54,8 @@ macro_rules! bench_unop_na(
fn $name(bh: &mut Bencher) {
const LEN: usize = 1 << 13;
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
let elems: Vec<$t> = (0usize .. LEN).map(|_| rng.gen::<$t>()).collect();
let mut i = 0;
@@ -73,7 +77,8 @@ macro_rules! bench_unop(
fn $name(bh: &mut Bencher) {
const LEN: usize = 1 << 13;
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
let mut elems: Vec<$t> = (0usize .. LEN).map(|_| rng.gen::<$t>()).collect();
let mut i = 0;
@@ -95,7 +100,8 @@ macro_rules! bench_construction(
fn $name(bh: &mut Bencher) {
const LEN: usize = 1 << 13;
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
$(let $args: Vec<$types> = (0usize .. LEN).map(|_| rng.gen::<$types>()).collect();)*
let mut i = 0;
diff --git a/benches/core/vector.rs b/benches/core/vector.rs
index 35e25e2d..837eb7ca 100644
--- a/benches/core/vector.rs
+++ b/benches/core/vector.rs
@@ -50,7 +50,8 @@ bench_binop_ref!(vec10000_dot_f32, VectorN, VectorN, d
#[bench]
fn vec10000_axpy_f64(bh: &mut Bencher) {
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
let mut a = DVector::new_random(10000);
let b = DVector::new_random(10000);
let n = rng.gen::();
@@ -60,7 +61,8 @@ fn vec10000_axpy_f64(bh: &mut Bencher) {
#[bench]
fn vec10000_axpy_beta_f64(bh: &mut Bencher) {
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
let mut a = DVector::new_random(10000);
let b = DVector::new_random(10000);
let n = rng.gen::();
@@ -71,7 +73,8 @@ fn vec10000_axpy_beta_f64(bh: &mut Bencher) {
#[bench]
fn vec10000_axpy_f64_slice(bh: &mut Bencher) {
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
let mut a = DVector::new_random(10000);
let b = DVector::new_random(10000);
let n = rng.gen::();
@@ -86,7 +89,8 @@ fn vec10000_axpy_f64_slice(bh: &mut Bencher) {
#[bench]
fn vec10000_axpy_f64_static(bh: &mut Bencher) {
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
let mut a = VectorN::::new_random();
let b = VectorN::::new_random();
let n = rng.gen::();
@@ -97,7 +101,8 @@ fn vec10000_axpy_f64_static(bh: &mut Bencher) {
#[bench]
fn vec10000_axpy_f32(bh: &mut Bencher) {
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
let mut a = DVector::new_random(10000);
let b = DVector::new_random(10000);
let n = rng.gen::();
@@ -107,7 +112,8 @@ fn vec10000_axpy_f32(bh: &mut Bencher) {
#[bench]
fn vec10000_axpy_beta_f32(bh: &mut Bencher) {
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
let mut a = DVector::new_random(10000);
let b = DVector::new_random(10000);
let n = rng.gen::();
diff --git a/benches/lib.rs b/benches/lib.rs
index 1ad3a2be..f788c998 100644
--- a/benches/lib.rs
+++ b/benches/lib.rs
@@ -14,6 +14,7 @@ mod geometry;
mod linalg;
fn reproductible_dmatrix(nrows: usize, ncols: usize) -> DMatrix {
- let mut rng = IsaacRng::new_unseeded();
+ use rand::SeedableRng;
+ let mut rng = IsaacRng::seed_from_u64(0);
DMatrix::::from_fn(nrows, ncols, |_, _| rng.gen())
}
diff --git a/examples/linear_system_resolution.rs b/examples/linear_system_resolution.rs
new file mode 100644
index 00000000..2d0dc183
--- /dev/null
+++ b/examples/linear_system_resolution.rs
@@ -0,0 +1,39 @@
+#![cfg_attr(rustfmt, rustfmt_skip)]
+#[macro_use]
+extern crate approx; // for assert_relative_eq
+extern crate nalgebra as na;
+use na::{Matrix4, Matrix4x3, Vector4};
+
+fn main() {
+ let a = Matrix4::new(
+ 1.0, 1.0, 2.0, -5.0,
+ 2.0, 5.0, -1.0, -9.0,
+ 2.0, 1.0, -1.0, 3.0,
+ 1.0, 3.0, 2.0, 7.0,
+ );
+ let mut b = Vector4::new(3.0, -3.0, -11.0, -5.0);
+ let decomp = a.lu();
+ let x = decomp.solve(&b).expect("Linear resolution failed.");
+ assert_relative_eq!(a * x, b);
+
+ /*
+ * It is possible to perform the resolution in-place.
+ * This is particularly useful to avoid allocations when
+ * `b` is a `DVector` or a `DMatrix`.
+ */
+ assert!(decomp.solve_mut(&mut b), "Linear resolution failed.");
+ assert_relative_eq!(x, b);
+
+ /*
+ * It is possible to solve multiple systems
+ * simultaneously by using a matrix for `b`.
+ */
+ let b = Matrix4x3::new(
+ 3.0, 2.0, 0.0,
+ -3.0, 0.0, 0.0,
+ -11.0, 5.0, -3.0,
+ -5.0, 10.0, 4.0,
+ );
+ let x = decomp.solve(&b).expect("Linear resolution failed.");
+ assert_relative_eq!(a * x, b);
+}
diff --git a/examples/point_construction.rs b/examples/point_construction.rs
index 7fc32838..19430997 100644
--- a/examples/point_construction.rs
+++ b/examples/point_construction.rs
@@ -8,7 +8,7 @@ fn main() {
// Build from a coordinates vector.
let coords = Vector3::new(2.0, 3.0, 4.0);
- let p1 = Point3::from_coordinates(coords);
+ let p1 = Point3::from(coords);
// Build by translating the origin.
let translation = Vector3::new(2.0, 3.0, 4.0);
diff --git a/examples/transform_matrix4.rs b/examples/transform_matrix4.rs
index c877206e..a9e6cd6e 100644
--- a/examples/transform_matrix4.rs
+++ b/examples/transform_matrix4.rs
@@ -3,7 +3,6 @@ extern crate alga;
extern crate approx;
extern crate nalgebra as na;
-use alga::linear::Transformation;
use na::{Matrix4, Point3, Vector3};
fn main() {
diff --git a/examples/transform_vector_point3.rs b/examples/transform_vector_point3.rs
index cd36cad1..57a189cc 100644
--- a/examples/transform_vector_point3.rs
+++ b/examples/transform_vector_point3.rs
@@ -1,7 +1,6 @@
extern crate alga;
extern crate nalgebra as na;
-use alga::linear::Transformation;
use na::{Matrix4, Point3, Vector3, Vector4};
fn main() {
diff --git a/nalgebra-glm/Cargo.toml b/nalgebra-glm/Cargo.toml
index 8e8b7130..0ba77cd6 100644
--- a/nalgebra-glm/Cargo.toml
+++ b/nalgebra-glm/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "nalgebra-glm"
-version = "0.1.3"
+version = "0.2.1"
authors = ["sebcrozet "]
description = "A computer-graphics oriented API for nalgebra, inspired by the C++ GLM library."
@@ -12,8 +12,16 @@ categories = [ "science" ]
keywords = [ "linear", "algebra", "matrix", "vector", "math" ]
license = "BSD-3-Clause"
+[features]
+default = [ "std" ]
+std = [ "nalgebra/std", "alga/std" ]
+stdweb = [ "nalgebra/stdweb" ]
+arbitrary = [ "nalgebra/arbitrary" ]
+serde-serialize = [ "nalgebra/serde-serialize" ]
+abomonation-serialize = [ "nalgebra/abomonation-serialize" ]
+
[dependencies]
num-traits = { version = "0.2", default-features = false }
approx = { version = "0.3", default-features = false }
-alga = "0.7"
-nalgebra = { path = "..", version = "^0.16.4" }
+alga = { version = "0.7", default-features = false }
+nalgebra = { path = "..", version = "^0.16.13", default-features = false }
diff --git a/nalgebra-glm/src/common.rs b/nalgebra-glm/src/common.rs
index e6a3dc0f..021ac3ef 100644
--- a/nalgebra-glm/src/common.rs
+++ b/nalgebra-glm/src/common.rs
@@ -315,13 +315,151 @@ where DefaultAllocator: Alloc {
// x * (exp).exp2()
//}
-/// Returns `x * (1.0 - a) + y * a`, i.e., the linear blend of x and y using the floating-point value a.
+/// Returns `x * (1.0 - a) + y * a`, i.e., the linear blend of the scalars x and y using the scalar value a.
///
/// The value for a is not restricted to the range `[0, 1]`.
-pub fn mix(x: N, y: N, a: N) -> N {
+///
+/// # Examples:
+///
+/// ```
+/// # use nalgebra_glm as glm;
+/// assert_eq!(glm::mix_scalar(2.0, 20.0, 0.1), 3.8);
+/// ```
+///
+/// # See also:
+///
+/// * [`mix`](fn.mix.html)
+/// * [`mix_vec`](fn.mix_vec.html)
+pub fn mix_scalar(x: N, y: N, a: N) -> N {
x * (N::one() - a) + y * a
}
+/// Returns `x * (1.0 - a) + y * a`, i.e., the linear blend of the vectors x and y using the scalar value a.
+///
+/// The value for a is not restricted to the range `[0, 1]`.
+///
+/// # Examples:
+///
+/// ```
+/// # use nalgebra_glm as glm;
+/// let x = glm::vec3(1.0, 2.0, 3.0);
+/// let y = glm::vec3(10.0, 20.0, 30.0);
+/// assert_eq!(glm::mix(&x, &y, 0.1), glm::vec3(1.9, 3.8, 5.7));
+/// ```
+///
+/// # See also:
+///
+/// * [`mix_scalar`](fn.mix_scalar.html)
+/// * [`mix_vec`](fn.mix_vec.html)
+pub fn mix(x: &TVec, y: &TVec, a: N) -> TVec
+where DefaultAllocator: Alloc {
+ x * (N::one() - a) + y * a
+}
+
+/// Returns `x * (1.0 - a) + y * a`, i.e., the component-wise linear blend of `x` and `y` using the components of
+/// the vector `a` as coefficients.
+///
+/// The value for a is not restricted to the range `[0, 1]`.
+///
+/// # Examples:
+///
+/// ```
+/// # use nalgebra_glm as glm;
+/// let x = glm::vec3(1.0, 2.0, 3.0);
+/// let y = glm::vec3(10.0, 20.0, 30.0);
+/// let a = glm::vec3(0.1, 0.2, 0.3);
+/// assert_eq!(glm::mix_vec(&x, &y, &a), glm::vec3(1.9, 5.6, 11.1));
+/// ```
+///
+/// # See also:
+///
+/// * [`mix_scalar`](fn.mix_scalar.html)
+/// * [`mix`](fn.mix.html)
+pub fn mix_vec(
+ x: &TVec,
+ y: &TVec,
+ a: &TVec,
+) -> TVec
+where
+ DefaultAllocator: Alloc,
+{
+ x.component_mul(&(TVec::::repeat(N::one()) - a)) + y.component_mul(&a)
+}
+
+/// Returns `x * (1.0 - a) + y * a`, i.e., the linear blend of the scalars x and y using the scalar value a.
+///
+/// The value for a is not restricted to the range `[0, 1]`.
+/// This is an alias for `mix_scalar`.
+///
+/// # Examples:
+///
+/// ```
+/// # use nalgebra_glm as glm;
+/// assert_eq!(glm::lerp_scalar(2.0, 20.0, 0.1), 3.8);
+/// ```
+///
+/// # See also:
+///
+/// * [`lerp`](fn.lerp.html)
+/// * [`lerp_vec`](fn.lerp_vec.html)
+pub fn lerp_scalar(x: N, y: N, a: N) -> N {
+ mix_scalar(x, y, a)
+}
+
+/// Returns `x * (1.0 - a) + y * a`, i.e., the linear blend of the vectors x and y using the scalar value a.
+///
+/// The value for a is not restricted to the range `[0, 1]`.
+/// This is an alias for `mix`.
+///
+/// # Examples:
+///
+/// ```
+/// # use nalgebra_glm as glm;
+/// let x = glm::vec3(1.0, 2.0, 3.0);
+/// let y = glm::vec3(10.0, 20.0, 30.0);
+/// assert_eq!(glm::lerp(&x, &y, 0.1), glm::vec3(1.9, 3.8, 5.7));
+/// ```
+///
+/// # See also:
+///
+/// * [`lerp_scalar`](fn.lerp_scalar.html)
+/// * [`lerp_vec`](fn.lerp_vec.html)
+pub fn lerp(x: &TVec, y: &TVec, a: N) -> TVec
+where DefaultAllocator: Alloc {
+ mix(x, y, a)
+}
+
+/// Returns `x * (1.0 - a) + y * a`, i.e., the component-wise linear blend of `x` and `y` using the components of
+/// the vector `a` as coefficients.
+///
+/// The value for a is not restricted to the range `[0, 1]`.
+/// This is an alias for `mix_vec`.
+///
+/// # Examples:
+///
+/// ```
+/// # use nalgebra_glm as glm;
+/// let x = glm::vec3(1.0, 2.0, 3.0);
+/// let y = glm::vec3(10.0, 20.0, 30.0);
+/// let a = glm::vec3(0.1, 0.2, 0.3);
+/// assert_eq!(glm::lerp_vec(&x, &y, &a), glm::vec3(1.9, 5.6, 11.1));
+/// ```
+///
+/// # See also:
+///
+/// * [`lerp_scalar`](fn.lerp_scalar.html)
+/// * [`lerp`](fn.lerp.html)
+pub fn lerp_vec(
+ x: &TVec,
+ y: &TVec,
+ a: &TVec,
+) -> TVec
+where
+ DefaultAllocator: Alloc,
+{
+ mix_vec(x, y, a)
+}
+
/// Component-wise modulus.
///
/// Returns `x - y * floor(x / y)` for each component in `x` using the corresponding component of `y`.
diff --git a/nalgebra-glm/src/constructors.rs b/nalgebra-glm/src/constructors.rs
index 210a10d4..1651dd20 100644
--- a/nalgebra-glm/src/constructors.rs
+++ b/nalgebra-glm/src/constructors.rs
@@ -1,8 +1,9 @@
-use aliases::{
- Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1,
- TVec2, TVec3, TVec4,
-};
-use na::{Real, Scalar, U2, U3, U4};
+#![cfg_attr(rustfmt, rustfmt_skip)]
+
+use na::{Scalar, Real, U2, U3, U4};
+use aliases::{TMat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4,
+ TMat4, TMat4x2, TMat4x3};
+
/// Creates a new 1D vector.
///
@@ -33,173 +34,136 @@ pub fn vec4(x: N, y: N, z: N, w: N) -> TVec4 {
TVec4::new(x, y, z, w)
}
+
/// Create a new 2x2 matrix.
-pub fn mat2(m11: N, m12: N, m21: N, m22: N) -> TMat2 {
- TMat::::new(m11, m12, m21, m22)
+pub fn mat2(m11: N, m12: N,
+ m21: N, m22: N) -> TMat2 {
+ TMat::::new(
+ m11, m12,
+ m21, m22,
+ )
}
/// Create a new 2x2 matrix.
-pub fn mat2x2(m11: N, m12: N, m21: N, m22: N) -> TMat2 {
- TMat::::new(m11, m12, m21, m22)
+pub fn mat2x2(m11: N, m12: N,
+ m21: N, m22: N) -> TMat2 {
+ TMat::::new(
+ m11, m12,
+ m21, m22,
+ )
}
/// Create a new 2x3 matrix.
-pub fn mat2x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat2x3 {
- TMat::::new(m11, m12, m13, m21, m22, m23)
+pub fn mat2x3(m11: N, m12: N, m13: N,
+ m21: N, m22: N, m23: N) -> TMat2x3 {
+ TMat::::new(
+ m11, m12, m13,
+ m21, m22, m23,
+ )
}
/// Create a new 2x4 matrix.
-pub fn mat2x4(
- m11: N,
- m12: N,
- m13: N,
- m14: N,
- m21: N,
- m22: N,
- m23: N,
- m24: N,
-) -> TMat2x4
-{
- TMat::::new(m11, m12, m13, m14, m21, m22, m23, m24)
+pub fn mat2x4(m11: N, m12: N, m13: N, m14: N,
+ m21: N, m22: N, m23: N, m24: N) -> TMat2x4 {
+ TMat::::new(
+ m11, m12, m13, m14,
+ m21, m22, m23, m24,
+ )
}
/// Create a new 3x3 matrix.
-pub fn mat3(
- m11: N,
- m12: N,
- m13: N,
- m21: N,
- m22: N,
- m23: N,
- m31: N,
- m32: N,
- m33: N,
-) -> TMat3
-{
- TMat::::new(m11, m12, m13, m21, m22, m23, m31, m32, m33)
+pub fn mat3(m11: N, m12: N, m13: N,
+ m21: N, m22: N, m23: N,
+ m31: N, m32: N, m33: N) -> TMat3 {
+ TMat::::new(
+ m11, m12, m13,
+ m21, m22, m23,
+ m31, m32, m33,
+ )
}
/// Create a new 3x2 matrix.
-pub fn mat3x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat3x2 {
- TMat::::new(m11, m12, m21, m22, m31, m32)
+pub fn mat3x2(m11: N, m12: N,
+ m21: N, m22: N,
+ m31: N, m32: N) -> TMat3x2 {
+ TMat::::new(
+ m11, m12,
+ m21, m22,
+ m31, m32,
+ )
}
/// Create a new 3x3 matrix.
-pub fn mat3x3(
- m11: N,
- m12: N,
- m13: N,
- m21: N,
- m22: N,
- m23: N,
- m31: N,
- m32: N,
- m33: N,
-) -> TMat3
-{
- TMat::::new(m11, m12, m13, m31, m32, m33, m21, m22, m23)
+pub fn mat3x3(m11: N, m12: N, m13: N,
+ m21: N, m22: N, m23: N,
+ m31: N, m32: N, m33: N) -> TMat3 {
+ TMat::::new(
+ m11, m12, m13,
+ m31, m32, m33,
+ m21, m22, m23,
+ )
}
/// Create a new 3x4 matrix.
-pub fn mat3x4(
- m11: N,
- m12: N,
- m13: N,
- m14: N,
- m21: N,
- m22: N,
- m23: N,
- m24: N,
- m31: N,
- m32: N,
- m33: N,
- m34: N,
-) -> TMat3x4
-{
- TMat::::new(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34)
+pub fn mat3x4(m11: N, m12: N, m13: N, m14: N,
+ m21: N, m22: N, m23: N, m24: N,
+ m31: N, m32: N, m33: N, m34: N) -> TMat3x4 {
+ TMat::::new(
+ m11, m12, m13, m14,
+ m21, m22, m23, m24,
+ m31, m32, m33, m34,
+ )
}
/// Create a new 4x2 matrix.
-pub fn mat4x2(
- m11: N,
- m12: N,
- m21: N,
- m22: N,
- m31: N,
- m32: N,
- m41: N,
- m42: N,
-) -> TMat4x2
-{
- TMat::::new(m11, m12, m21, m22, m31, m32, m41, m42)
+pub fn mat4x2(m11: N, m12: N,
+ m21: N, m22: N,
+ m31: N, m32: N,
+ m41: N, m42: N) -> TMat4x2 {
+ TMat::::new(
+ m11, m12,
+ m21, m22,
+ m31, m32,
+ m41, m42,
+ )
}
/// Create a new 4x3 matrix.
-pub fn mat4x3(
- m11: N,
- m12: N,
- m13: N,
- m21: N,
- m22: N,
- m23: N,
- m31: N,
- m32: N,
- m33: N,
- m41: N,
- m42: N,
- m43: N,
-) -> TMat4x3
-{
- TMat::::new(m11, m12, m13, m21, m22, m23, m31, m32, m33, m41, m42, m43)
-}
-
-/// Create a new 4x4 matrix.
-pub fn mat4x4(
- m11: N,
- m12: N,
- m13: N,
- m14: N,
- m21: N,
- m22: N,
- m23: N,
- m24: N,
- m31: N,
- m32: N,
- m33: N,
- m34: N,
- m41: N,
- m42: N,
- m43: N,
- m44: N,
-) -> TMat4
-{
- TMat::::new(
- m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44,
+pub fn mat4x3(m11: N, m12: N, m13: N,
+ m21: N, m22: N, m23: N,
+ m31: N, m32: N, m33: N,
+ m41: N, m42: N, m43: N) -> TMat4x3 {
+ TMat::::new(
+ m11, m12, m13,
+ m21, m22, m23,
+ m31, m32, m33,
+ m41, m42, m43,
)
}
/// Create a new 4x4 matrix.
-pub fn mat4(
- m11: N,
- m12: N,
- m13: N,
- m14: N,
- m21: N,
- m22: N,
- m23: N,
- m24: N,
- m31: N,
- m32: N,
- m33: N,
- m34: N,
- m41: N,
- m42: N,
- m43: N,
- m44: N,
-) -> TMat4
-{
+pub fn mat4x4(m11: N, m12: N, m13: N, m14: N,
+ m21: N, m22: N, m23: N, m24: N,
+ m31: N, m32: N, m33: N, m34: N,
+ m41: N, m42: N, m43: N, m44: N) -> TMat4 {
TMat::::new(
- m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44,
+ m11, m12, m13, m14,
+ m21, m22, m23, m24,
+ m31, m32, m33, m34,
+ m41, m42, m43, m44,
+ )
+}
+
+/// Create a new 4x4 matrix.
+pub fn mat4(m11: N, m12: N, m13: N, m14: N,
+ m21: N, m22: N, m23: N, m24: N,
+ m31: N, m32: N, m33: N, m34: N,
+ m41: N, m42: N, m43: N, m44: N) -> TMat4 {
+ TMat::::new(
+ m11, m12, m13, m14,
+ m21, m22, m23, m24,
+ m31, m32, m33, m34,
+ m41, m42, m43, m44,
)
}
diff --git a/nalgebra-glm/src/ext/matrix_clip_space.rs b/nalgebra-glm/src/ext/matrix_clip_space.rs
index 89c137ea..02179759 100644
--- a/nalgebra-glm/src/ext/matrix_clip_space.rs
+++ b/nalgebra-glm/src/ext/matrix_clip_space.rs
@@ -1,5 +1,5 @@
use aliases::TMat4;
-use na::{Orthographic3, Perspective3, Real};
+use na::{Real};
//pub fn frustum(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 {
// unimplemented!()
@@ -53,119 +53,644 @@ use na::{Orthographic3, Perspective3, Real};
// unimplemented!()
//}
-/// Creates a matrix for an orthographic parallel viewing volume, using the right handedness and OpenGL near and far clip planes definition.
+/// Creates a matrix for a right hand orthographic-view frustum with a depth range of -1 to 1
+///
+/// # 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
+///
pub fn ortho(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
- Orthographic3::new(left, right, bottom, top, znear, zfar).unwrap()
+ ortho_rh_no(left, right, bottom, top, znear, zfar)
}
-//pub fn ortho_lh(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn ortho_lh_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn ortho_lh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn ortho_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn ortho_rh(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn ortho_rh_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn ortho_rh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn ortho_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
-// unimplemented!()
-//}
+/// Creates a left hand matrix for a orthographic-view frustum with a depth range of -1 to 1
+///
+/// # 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
+///
+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 matrix for a perspective-view frustum based on the right handedness and OpenGL near and far clip planes definition.
+/// Creates a left hand matrix for a orthographic-view frustum with a depth range of -1 to 1
+///
+/// # 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
+///
+pub fn ortho_lh_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
+ 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)] = two / (top-bottom);
+ mat[(1, 3)] = -(top + bottom) / (top - bottom);
+ mat[(2, 2)] = two / (zfar - znear);
+ mat[(2, 3)] = -(zfar + znear) / (zfar - znear);
+
+ mat
+}
+
+/// Creates a matrix for a left hand orthographic-view frustum with a depth range of 0 to 1
+///
+/// # 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
+///
+pub fn ortho_lh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
+ 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)] = two / (top - bottom);
+ mat[(1, 3)] = - (top + bottom) / (top - bottom);
+ mat[(2, 2)] = one / (zfar - znear);
+ mat[(2, 3)] = - znear / (zfar - znear);
+
+ mat
+}
+
+/// Creates a matrix for a right hand orthographic-view frustum with a depth range of -1 to 1
+///
+/// # 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
+///
+pub fn ortho_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
+ ortho_rh_no(left, right, bottom, top, znear, zfar)
+}
+
+/// Creates a matrix for a right hand orthographic-view frustum with a depth range of -1 to 1
+///
+/// # 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
+///
+pub fn ortho_rh(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
+ ortho_rh_no(left, right, bottom, top, znear, zfar)
+}
+
+/// Creates a matrix for a right hand orthographic-view frustum with a depth range of -1 to 1
+///
+/// # 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
+///
+pub fn ortho_rh_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
+ 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)] = two/(top-bottom);
+ mat[(1, 3)] = - (top + bottom) / (top - bottom);
+ mat[(2, 2)] = - two / (zfar - znear);
+ mat[(2, 3)] = - (zfar + znear) / (zfar - znear);
+
+ mat
+}
+
+/// Creates a right hand matrix for a orthographic-view frustum with a depth range of 0 to 1
+///
+/// # 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
+///
+pub fn ortho_rh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
+ 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)] = two/(top-bottom);
+ mat[(1, 3)] = - (top + bottom) / (top - bottom);
+ mat[(2, 2)] = - one / (zfar - znear);
+ mat[(2, 3)] = - znear / (zfar - znear);
+
+ mat
+}
+
+/// Creates a right hand matrix for a orthographic-view frustum with a depth range of 0 to 1
+///
+/// # 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
+///
+pub fn ortho_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 {
+ ortho_rh_zo(left, right, bottom, top, znear, zfar)
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fov` - Field of view, in radians
+/// * `width` - Width of the viewport
+/// * `height` - Height of the viewport
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+pub fn perspective_fov(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
+ perspective_fov_rh_no(fov, width, height, near, far)
+}
+
+/// Creates a matrix for a left hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fov` - Field of view, in radians
+/// * `width` - Width of the viewport
+/// * `height` - Height of the viewport
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+pub fn perspective_fov_lh(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
+ perspective_fov_lh_no(fov, width, height, near, far)
+}
+
+/// Creates a matrix for a left hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fov` - Field of view, in radians
+/// * `width` - Width of the viewport
+/// * `height` - Height of the viewport
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+pub fn perspective_fov_lh_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
+ assert!(
+ width > N::zero(),
+ "The width must be greater than zero"
+ );
+ assert!(
+ height > N::zero(),
+ "The height must be greater than zero."
+ );
+ assert!(
+ fov > N::zero(),
+ "The fov must be greater than zero"
+ );
+
+ let mut mat = TMat4::zeros();
+
+ let rad = fov;
+ let h = (rad * ::convert(0.5)).cos() / (rad * ::convert(0.5)).sin();
+ let w = h * height / width;
+
+ mat[(0, 0)] = w;
+ mat[(1, 1)] = h;
+ mat[(2, 2)] = (far + near) / (far - near);
+ mat[(2, 3)] = - (far * near * ::convert(2.0)) / (far - near);
+ mat[(3, 2)] = N::one();
+
+ mat
+}
+
+/// Creates a matrix for a left hand perspective-view frustum with a depth range of 0 to 1
+///
+/// # Parameters
+///
+/// * `fov` - Field of view, in radians
+/// * `width` - Width of the viewport
+/// * `height` - Height of the viewport
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+pub fn perspective_fov_lh_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
+ assert!(
+ width > N::zero(),
+ "The width must be greater than zero"
+ );
+ assert!(
+ height > N::zero(),
+ "The height must be greater than zero."
+ );
+ assert!(
+ fov > N::zero(),
+ "The fov must be greater than zero"
+ );
+
+ let mut mat = TMat4::zeros();
+
+ let rad = fov;
+ let h = (rad * ::convert(0.5)).cos() / (rad * ::convert(0.5)).sin();
+ let w = h * height / width;
+
+ mat[(0, 0)] = w;
+ mat[(1, 1)] = h;
+ mat[(2, 2)] = far / (far - near);
+ mat[(2, 3)] = -(far * near) / (far - near);
+ mat[(3, 2)] = N::one();
+
+ mat
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fov` - Field of view, in radians
+/// * `width` - Width of the viewport
+/// * `height` - Height of the viewport
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+pub fn perspective_fov_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
+ perspective_fov_rh_no(fov, width, height, near, far)
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fov` - Field of view, in radians
+/// * `width` - Width of the viewport
+/// * `height` - Height of the viewport
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+pub fn perspective_fov_rh(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
+ perspective_fov_rh_no(fov, width, height, near, far)
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fov` - Field of view, in radians
+/// * `width` - Width of the viewport
+/// * `height` - Height of the viewport
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+pub fn perspective_fov_rh_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
+ assert!(
+ width > N::zero(),
+ "The width must be greater than zero"
+ );
+ assert!(
+ height > N::zero(),
+ "The height must be greater than zero."
+ );
+ assert!(
+ fov > N::zero(),
+ "The fov must be greater than zero"
+ );
+
+ let mut mat = TMat4::zeros();
+
+ let rad = fov;
+ let h = (rad * ::convert(0.5)).cos() / (rad * ::convert(0.5)).sin();
+ let w = h * height / width;
+
+ mat[(0, 0)] = w;
+ mat[(1, 1)] = h;
+ mat[(2, 2)] = - (far + near) / (far - near);
+ mat[(2, 3)] = - (far * near * ::convert(2.0)) / (far - near);
+ mat[(3, 2)] = -N::one();
+
+ mat
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of 0 to 1
+///
+/// # Parameters
+///
+/// * `fov` - Field of view, in radians
+/// * `width` - Width of the viewport
+/// * `height` - Height of the viewport
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+pub fn perspective_fov_rh_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
+ assert!(
+ width > N::zero(),
+ "The width must be greater than zero"
+ );
+ assert!(
+ height > N::zero(),
+ "The height must be greater than zero."
+ );
+ assert!(
+ fov > N::zero(),
+ "The fov must be greater than zero"
+ );
+
+ let mut mat = TMat4::zeros();
+
+ let rad = fov;
+ let h = (rad * ::convert(0.5)).cos() / (rad * ::convert(0.5)).sin();
+ let w = h * height / width;
+
+ mat[(0, 0)] = w;
+ mat[(1, 1)] = h;
+ mat[(2, 2)] = far / (near - far);
+ mat[(2, 3)] = -(far * near) / (far - near);
+ mat[(3, 2)] = -N::one();
+
+ mat
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of 0 to 1
+///
+/// # Parameters
+///
+/// * `fov` - Field of view, in radians
+/// * `width` - Width of the viewport
+/// * `height` - Height of the viewport
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+pub fn perspective_fov_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
+ perspective_fov_rh_zo(fov, width, height, near, far)
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fovy` - Field of view, in radians
+/// * `aspect` - Ratio of viewport width to height (width/height)
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
///
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
pub fn perspective(aspect: N, fovy: N, near: N, far: N) -> TMat4 {
- Perspective3::new(aspect, fovy, near, far).unwrap()
+ // TODO: Breaking change - revert back to proper glm conventions?
+ //
+ // Prior to changes to support configuring the behaviour of this function it was simply
+ // a wrapper around Perspective3::new(). The argument order for that function is different
+ // than the glm convention, but reordering the arguments would've caused pointlessly
+ // un-optimal code to be generated so they were rearranged so the function would just call
+ // straight through.
+ //
+ // Now this call to Perspective3::new() is no longer made so the functions can have their
+ // arguments reordered to the glm convention. Unfortunately this is a breaking change so
+ // can't be cleanly integrated into the existing library version without breaking other
+ // 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.
+ //
+ perspective_rh_no(aspect, fovy, near, far)
+}
+
+/// Creates a matrix for a left hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fovy` - Field of view, in radians
+/// * `aspect` - Ratio of viewport width to height (width/height)
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+/// # Important note
+/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
+pub fn perspective_lh(aspect: N, fovy: N, near: N, far: N) -> TMat4 {
+ perspective_lh_no(aspect, fovy, near, far)
+}
+
+/// Creates a matrix for a left hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fovy` - Field of view, in radians
+/// * `aspect` - Ratio of viewport width to height (width/height)
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+/// # Important note
+/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
+pub fn perspective_lh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4 {
+ assert!(
+ !relative_eq!(far - near, N::zero()),
+ "The near-plane and far-plane must not be superimposed."
+ );
+ assert!(
+ !relative_eq!(aspect, N::zero()),
+ "The apsect ratio must not be zero."
+ );
+
+ let one = N::one();
+ let two: N = ::convert( 2.0);
+ let mut mat : TMat4 = TMat4::zeros();
+
+ let tan_half_fovy = (fovy / two).tan();
+
+ mat[(0, 0)] = one / (aspect * tan_half_fovy);
+ 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;
+
+ mat
+}
+
+/// Creates a matrix for a left hand perspective-view frustum with a depth range of 0 to 1
+///
+/// # Parameters
+///
+/// * `fovy` - Field of view, in radians
+/// * `aspect` - Ratio of viewport width to height (width/height)
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+/// # Important note
+/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
+pub fn perspective_lh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4 {
+ assert!(
+ !relative_eq!(far - near, N::zero()),
+ "The near-plane and far-plane must not be superimposed."
+ );
+ assert!(
+ !relative_eq!(aspect, N::zero()),
+ "The apsect ratio must not be zero."
+ );
+
+ let one = N::one();
+ let two: N = ::convert( 2.0);
+ let mut mat: TMat4 = TMat4::zeros();
+
+ let tan_half_fovy = (fovy / two).tan();
+
+ mat[(0, 0)] = one / (aspect * tan_half_fovy);
+ mat[(1, 1)] = one / tan_half_fovy;
+ mat[(2, 2)] = far / (far - near);
+ mat[(2, 3)] = -(far * near) / (far - near);
+ mat[(3, 2)] = one;
+
+ mat
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fovy` - Field of view, in radians
+/// * `aspect` - Ratio of viewport width to height (width/height)
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+/// # Important note
+/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
+pub fn perspective_no(aspect: N, fovy: N, near: N, far: N) -> TMat4 {
+ perspective_rh_no(aspect, fovy, near, far)
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fovy` - Field of view, in radians
+/// * `aspect` - Ratio of viewport width to height (width/height)
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+/// # Important note
+/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
+pub fn perspective_rh(aspect: N, fovy: N, near: N, far: N) -> TMat4 {
+ perspective_rh_no(aspect, fovy, near, far)
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of -1 to 1
+///
+/// # Parameters
+///
+/// * `fovy` - Field of view, in radians
+/// * `aspect` - Ratio of viewport width to height (width/height)
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+/// # Important note
+/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
+pub fn perspective_rh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4 {
+ assert!(
+ !relative_eq!(far - near, N::zero()),
+ "The near-plane and far-plane must not be superimposed."
+ );
+ assert!(
+ !relative_eq!(aspect, N::zero()),
+ "The apsect ratio must not be zero."
+ );
+
+ let negone = -N::one();
+ let one = N::one();
+ let two: N = ::convert( 2.0);
+ let mut mat = TMat4::zeros();
+
+ let tan_half_fovy = (fovy / two).tan();
+
+ mat[(0, 0)] = one / (aspect * tan_half_fovy);
+ 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;
+
+ mat
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of 0 to 1
+///
+/// # Parameters
+///
+/// * `fovy` - Field of view, in radians
+/// * `aspect` - Ratio of viewport width to height (width/height)
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+/// # Important note
+/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
+pub fn perspective_rh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4 {
+ assert!(
+ !relative_eq!(far - near, N::zero()),
+ "The near-plane and far-plane must not be superimposed."
+ );
+ assert!(
+ !relative_eq!(aspect, N::zero()),
+ "The apsect ratio must not be zero."
+ );
+
+ let negone = -N::one();
+ let one = N::one();
+ let two = ::convert( 2.0);
+ let mut mat = TMat4::zeros();
+
+ let tan_half_fovy = (fovy / two).tan();
+
+ mat[(0, 0)] = one / (aspect * tan_half_fovy);
+ mat[(1, 1)] = one / tan_half_fovy;
+ mat[(2, 2)] = far / (near - far);
+ mat[(2, 3)] = -(far * near) / (far - near);
+ mat[(3, 2)] = negone;
+
+ mat
+}
+
+/// Creates a matrix for a right hand perspective-view frustum with a depth range of 0 to 1
+///
+/// # Parameters
+///
+/// * `fovy` - Field of view, in radians
+/// * `aspect` - Ratio of viewport width to height (width/height)
+/// * `near` - Distance from the viewer to the near clipping plane
+/// * `far` - Distance from the viewer to the far clipping plane
+///
+/// # Important note
+/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
+pub fn perspective_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4 {
+ perspective_rh_zo(aspect, fovy, near, far)
}
-//pub fn perspective_fov(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_fov_lh(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_fov_lh_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_fov_lh_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_fov_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_fov_rh(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_fov_rh_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_fov_rh_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_fov_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_lh(fovy: N, aspect: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_lh_no(fovy: N, aspect: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_lh_zo(fovy: N, aspect: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_no(fovy: N, aspect: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_rh(fovy: N, aspect: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_rh_no(fovy: N, aspect: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_rh_zo(fovy: N, aspect: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
-//pub fn perspective_zo(fovy: N, aspect: N, near: N, far: N) -> TMat4 {
-// unimplemented!()
-//}
-//
//pub fn tweaked_infinite_perspective(fovy: N, aspect: N, near: N) -> TMat4 {
// unimplemented!()
//}
diff --git a/nalgebra-glm/src/ext/matrix_projection.rs b/nalgebra-glm/src/ext/matrix_projection.rs
index d56103a6..4ed23fb3 100644
--- a/nalgebra-glm/src/ext/matrix_projection.rs
+++ b/nalgebra-glm/src/ext/matrix_projection.rs
@@ -24,7 +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 OpenGL near and far clip planes definition.
+/// Map the specified object coordinates `(obj.x, obj.y, obj.z)` into window coordinates with a
+/// depth range of -1 to 1
///
/// # Parameters:
///
@@ -114,7 +115,8 @@ pub fn project_zo(
)
}
-/// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates using OpenGL near and far clip planes definition.
+/// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates using a
+/// depth range of -1 to 1
///
/// # Parameters:
///
diff --git a/nalgebra-glm/src/ext/matrix_transform.rs b/nalgebra-glm/src/ext/matrix_transform.rs
index fb23efc9..82926249 100644
--- a/nalgebra-glm/src/ext/matrix_transform.rs
+++ b/nalgebra-glm/src/ext/matrix_transform.rs
@@ -38,11 +38,7 @@ pub fn look_at(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMa
/// * [`look_at`](fn.look_at.html)
/// * [`look_at_rh`](fn.look_at_rh.html)
pub fn look_at_lh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 {
- TMat::look_at_lh(
- &Point3::from_coordinates(*eye),
- &Point3::from_coordinates(*center),
- up,
- )
+ TMat::look_at_lh(&Point3::from(*eye), &Point3::from(*center), up)
}
/// Build a right handed look at view matrix.
@@ -58,11 +54,7 @@ pub fn look_at_lh(eye: &TVec3, center: &TVec3, up: &TVec3) ->
/// * [`look_at`](fn.look_at.html)
/// * [`look_at_lh`](fn.look_at_lh.html)
pub fn look_at_rh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4