Add the TVec* and TMat* aliases.

This commit is contained in:
sebcrozet 2018-09-23 14:41:56 +02:00 committed by Sébastien Crozet
parent ea668dea90
commit 975e0a8b6b
26 changed files with 380 additions and 355 deletions

View File

@ -11,6 +11,14 @@ pub type Vec<N, R> = VectorN<N, R>;
/// A quaternion with components of type `N`. /// A quaternion with components of type `N`.
pub type Qua<N> = Quaternion<N>; pub type Qua<N> = Quaternion<N>;
/// A 1D vector with components of type `N`.
pub type TVec1<N> = Vector1<N>;
/// A 2D vector with components of type `N`.
pub type TVec2<N> = Vector2<N>;
/// A 3D vector with components of type `N`.
pub type TVec3<N> = Vector3<N>;
/// A 4D vector with components of type `N`.
pub type TVec4<N> = Vector4<N>;
/// A 1D vector with boolean components. /// A 1D vector with boolean components.
pub type BVec1 = Vector1<bool>; pub type BVec1 = Vector1<bool>;
/// A 2D vector with boolean components. /// A 2D vector with boolean components.
@ -121,7 +129,31 @@ pub type I8Vec3 = Vector3<i8>;
pub type I8Vec4 = Vector4<i8>; pub type I8Vec4 = Vector4<i8>;
/// A 2x2 matrix with `f64` components. /// A 2x2 matrix with components of type `N`.
pub type TMat2<N> = Matrix2<N>;
/// A 2x2 matrix with components of type `N`.
pub type TMat2x2<N> = Matrix2<N>;
/// A 2x3 matrix with components of type `N`.
pub type TMat2x3<N> = Matrix2x3<N>;
/// A 2x4 matrix with components of type `N`.
pub type TMat2x4<N> = Matrix2x4<N>;
/// A 3x3 matrix with components of type `N`.
pub type TMat3<N> = Matrix3<N>;
/// A 3x2 matrix with components of type `N`.
pub type TMat3x2<N> = Matrix3x2<N>;
/// A 3x3 matrix with components of type `N`.
pub type TMat3x3<N> = Matrix3<N>;
/// A 3x4 matrix with components of type `N`.
pub type TMat3x4<N> = Matrix3x4<N>;
/// A 4x4 matrix with components of type `N`.
pub type TMat4<N> = Matrix4<N>;
/// A 4x2 matrix with components of type `N`.
pub type TMat4x2<N> = Matrix4x2<N>;
/// A 4x3 matrix with components of type `N`.
pub type TMat4x3<N> = Matrix4x3<N>;
/// A 4x4 matrix with components of type `N`.
pub type TMat4x4<N> = Matrix4<N>;
/// A 2x2 matrix with components of type `N`.
pub type DMat2 = Matrix2<f64>; pub type DMat2 = Matrix2<f64>;
/// A 2x2 matrix with `f64` components. /// A 2x2 matrix with `f64` components.
pub type DMat2x2 = Matrix2<f64>; pub type DMat2x2 = Matrix2<f64>;

View File

@ -1,30 +1,31 @@
use na::{Scalar, Real, U1, U2, U3, U4}; use na::{Scalar, Real, U2, U3, U4};
use aliases::{Vec, Mat, Qua}; use aliases::{Mat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4,
TMat4, TMat4x2, TMat4x3};
/// Creates a new 1D vector. /// Creates a new 1D vector.
pub fn vec1<N: Scalar>(x: N) -> Vec<N, U1> { pub fn vec1<N: Scalar>(x: N) -> TVec1<N> {
Vec::<N, U1>::new(x) TVec1::new(x)
} }
/// Creates a new 2D vector. /// Creates a new 2D vector.
pub fn vec2<N: Scalar>(x: N, y: N) -> Vec<N, U2> { pub fn vec2<N: Scalar>(x: N, y: N) -> TVec2<N> {
Vec::<N, U2>::new(x, y) TVec2::new(x, y)
} }
/// Creates a new 3D vector. /// Creates a new 3D vector.
pub fn vec3<N: Scalar>(x: N, y: N, z: N) -> Vec<N, U3> { pub fn vec3<N: Scalar>(x: N, y: N, z: N) -> TVec3<N> {
Vec::<N, U3>::new(x, y, z) TVec3::new(x, y, z)
} }
/// Creates a new 4D vector. /// Creates a new 4D vector.
pub fn vec4<N: Scalar>(x: N, y: N, z: N, w: N) -> Vec<N, U4> { pub fn vec4<N: Scalar>(x: N, y: N, z: N, w: N) -> TVec4<N> {
Vec::<N, U4>::new(x, y, z, w) TVec4::new(x, y, z, w)
} }
/// Create a new 2x2 matrix. /// Create a new 2x2 matrix.
pub fn mat2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> Mat<N, U2, U2> { pub fn mat2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
Mat::<N, U2, U2>::new( Mat::<N, U2, U2>::new(
m11, m12, m11, m12,
m21, m22, m21, m22,
@ -32,7 +33,7 @@ pub fn mat2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> Mat<N, U2, U2> {
} }
/// Create a new 2x2 matrix. /// Create a new 2x2 matrix.
pub fn mat2x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> Mat<N, U2, U2> { pub fn mat2x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
Mat::<N, U2, U2>::new( Mat::<N, U2, U2>::new(
m11, m12, m11, m12,
m21, m22, m21, m22,
@ -40,7 +41,7 @@ pub fn mat2x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> Mat<N, U2, U2> {
} }
/// Create a new 2x3 matrix. /// Create a new 2x3 matrix.
pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> Mat<N, U2, U3> { pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat2x3<N> {
Mat::<N, U2, U3>::new( Mat::<N, U2, U3>::new(
m11, m12, m13, m11, m12, m13,
m21, m22, m23, m21, m22, m23,
@ -48,7 +49,7 @@ pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> Mat<
} }
/// Create a new 2x4 matrix. /// Create a new 2x4 matrix.
pub fn mat2x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N) -> Mat<N, U2, U4> { pub fn mat2x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N) -> TMat2x4<N> {
Mat::<N, U2, U4>::new( Mat::<N, U2, U4>::new(
m11, m12, m13, m14, m11, m12, m13, m14,
m21, m22, m23, m24, m21, m22, m23, m24,
@ -56,7 +57,7 @@ pub fn mat2x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N,
} }
/// Create a new 3x3 matrix. /// Create a new 3x3 matrix.
pub fn mat3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> Mat<N, U3, U3> { pub fn mat3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3<N> {
Mat::<N, U3, U3>::new( Mat::<N, U3, U3>::new(
m11, m12, m13, m11, m12, m13,
m21, m22, m23, m21, m22, m23,
@ -65,7 +66,7 @@ pub fn mat3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m
} }
/// Create a new 3x2 matrix. /// Create a new 3x2 matrix.
pub fn mat3x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> Mat<N, U3, U2> { pub fn mat3x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat3x2<N> {
Mat::<N, U3, U2>::new( Mat::<N, U3, U2>::new(
m11, m12, m11, m12,
m21, m22, m21, m22,
@ -74,7 +75,7 @@ pub fn mat3x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> Mat<
} }
/// Create a new 3x3 matrix. /// Create a new 3x3 matrix.
pub fn mat3x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> Mat<N, U3, U3> { pub fn mat3x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3<N> {
Mat::<N, U3, U3>::new( Mat::<N, U3, U3>::new(
m11, m12, m13, m11, m12, m13,
m31, m32, m33, m31, m32, m33,
@ -83,7 +84,7 @@ pub fn mat3x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N,
} }
/// Create a new 3x4 matrix. /// Create a new 3x4 matrix.
pub fn mat3x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N) -> Mat<N, U3, U4> { pub fn mat3x4<N: Scalar>(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<N> {
Mat::<N, U3, U4>::new( Mat::<N, U3, U4>::new(
m11, m12, m13, m14, m11, m12, m13, m14,
m21, m22, m23, m24, m21, m22, m23, m24,
@ -92,7 +93,7 @@ pub fn mat3x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N,
} }
/// Create a new 4x2 matrix. /// Create a new 4x2 matrix.
pub fn mat4x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N, m42: N) -> Mat<N, U4, U2> { pub fn mat4x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N, m42: N) -> TMat4x2<N> {
Mat::<N, U4, U2>::new( Mat::<N, U4, U2>::new(
m11, m12, m11, m12,
m21, m22, m21, m22,
@ -102,7 +103,7 @@ pub fn mat4x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N,
} }
/// Create a new 4x3 matrix. /// Create a new 4x3 matrix.
pub fn mat4x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N, m41: N, m42: N, m43: N) -> Mat<N, U4, U3> { pub fn mat4x3<N: Scalar>(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<N> {
Mat::<N, U4, U3>::new( Mat::<N, U4, U3>::new(
m11, m12, m13, m11, m12, m13,
m21, m22, m23, m21, m22, m23,
@ -112,7 +113,7 @@ pub fn mat4x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N,
} }
/// Create a new 4x4 matrix. /// Create a new 4x4 matrix.
pub fn mat4x4<N: Scalar>(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) -> Mat<N, U4, U4> { pub fn mat4x4<N: Scalar>(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<N> {
Mat::<N, U4, U4>::new( Mat::<N, U4, U4>::new(
m11, m12, m13, m14, m11, m12, m13, m14,
m21, m22, m23, m24, m21, m22, m23, m24,
@ -122,7 +123,7 @@ pub fn mat4x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N,
} }
/// Create a new 4x4 matrix. /// Create a new 4x4 matrix.
pub fn mat4<N: Scalar>(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) -> Mat<N, U4, U4> { pub fn mat4<N: Scalar>(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<N> {
Mat::<N, U4, U4>::new( Mat::<N, U4, U4>::new(
m11, m12, m13, m14, m11, m12, m13, m14,
m21, m22, m23, m24, m21, m22, m23, m24,

View File

@ -1,172 +1,172 @@
use na::{Real, U4, Orthographic3, Perspective3}; use na::{Real, Orthographic3, Perspective3};
use aliases::Mat; use aliases::TMat4;
//pub fn frustum<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn frustum<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
//pub fn frustum_lh<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn frustum_lh<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn frustum_lr_no<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn frustum_lr_no<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn frustum_lh_zo<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn frustum_lh_zo<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn frustum_no<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn frustum_no<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn frustum_rh<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn frustum_rh<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn frustum_rh_no<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn frustum_rh_no<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn frustum_rh_zo<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn frustum_rh_zo<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn frustum_zo<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn frustum_zo<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
//pub fn infinite_perspective<N: Real>(fovy: N, aspect: N, near: N) -> Mat<N, U4, U4> { //pub fn infinite_perspective<N: Real>(fovy: N, aspect: N, near: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn infinite_perspective_lh<N: Real>(fovy: N, aspect: N, near: N) -> Mat<N, U4, U4> { //pub fn infinite_perspective_lh<N: Real>(fovy: N, aspect: N, near: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn infinite_perspective_rh<N: Real>(fovy: N, aspect: N, near: N) -> Mat<N, U4, U4> { //pub fn infinite_perspective_rh<N: Real>(fovy: N, aspect: N, near: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn infinite_ortho<N: Real>(left: N, right: N, bottom: N, top: N) -> Mat<N, U4, U4> { //pub fn infinite_ortho<N: Real>(left: N, right: N, bottom: N, top: N) -> TMat4<N> {
// unimplemented!() // 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 an orthographic parallel viewing volume, using the right handedness and OpenGL near and far clip planes definition.
pub fn ortho<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Mat<N, U4, U4> { pub fn ortho<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
Orthographic3::new(left, right, bottom, top, znear, zfar).unwrap() Orthographic3::new(left, right, bottom, top, znear, zfar).unwrap()
} }
//pub fn ortho_lh<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Mat<N, U4, U4> { //pub fn ortho_lh<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn ortho_lh_no<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Mat<N, U4, U4> { //pub fn ortho_lh_no<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn ortho_lh_zo<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Mat<N, U4, U4> { //pub fn ortho_lh_zo<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn ortho_no<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Mat<N, U4, U4> { //pub fn ortho_no<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn ortho_rh<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Mat<N, U4, U4> { //pub fn ortho_rh<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn ortho_rh_no<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Mat<N, U4, U4> { //pub fn ortho_rh_no<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn ortho_rh_zo<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Mat<N, U4, U4> { //pub fn ortho_rh_zo<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn ortho_zo<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Mat<N, U4, U4> { //pub fn ortho_zo<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
/// Creates a matrix for a symetric perspective-view frustum based on the right handedness and OpenGL near and far clip planes definition. /// Creates a matrix for a symetric perspective-view frustum based on the right handedness and OpenGL near and far clip planes definition.
pub fn perspective<N: Real>(fovy: N, aspect: N, near: N, far: N) -> Mat<N, U4, U4> { pub fn perspective<N: Real>(fovy: N, aspect: N, near: N, far: N) -> TMat4<N> {
Perspective3::new(fovy, aspect, near, far).unwrap() Perspective3::new(fovy, aspect, near, far).unwrap()
} }
//pub fn perspective_fov<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_fov<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_fov_lh<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_fov_lh<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_fov_lh_no<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_fov_lh_no<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_fov_lh_zo<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_fov_lh_zo<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_fov_no<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_fov_no<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_fov_rh<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_fov_rh<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_fov_rh_no<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_fov_rh_no<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_fov_rh_zo<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_fov_rh_zo<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_fov_zo<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_fov_zo<N: Real>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_lh<N: Real>(fovy: N, aspect: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_lh<N: Real>(fovy: N, aspect: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_lh_no<N: Real>(fovy: N, aspect: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_lh_no<N: Real>(fovy: N, aspect: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_lh_zo<N: Real>(fovy: N, aspect: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_lh_zo<N: Real>(fovy: N, aspect: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_no<N: Real>(fovy: N, aspect: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_no<N: Real>(fovy: N, aspect: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_rh<N: Real>(fovy: N, aspect: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_rh<N: Real>(fovy: N, aspect: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_rh_no<N: Real>(fovy: N, aspect: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_rh_no<N: Real>(fovy: N, aspect: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_rh_zo<N: Real>(fovy: N, aspect: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_rh_zo<N: Real>(fovy: N, aspect: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn perspective_zo<N: Real>(fovy: N, aspect: N, near: N, far: N) -> Mat<N, U4, U4> { //pub fn perspective_zo<N: Real>(fovy: N, aspect: N, near: N, far: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn tweaked_infinite_perspective<N: Real>(fovy: N, aspect: N, near: N) -> Mat<N, U4, U4> { //pub fn tweaked_infinite_perspective<N: Real>(fovy: N, aspect: N, near: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn tweaked_infinite_perspective_ep<N: Real>(fovy: N, aspect: N, near: N, ep: N) -> Mat<N, U4, U4> { //pub fn tweaked_infinite_perspective_ep<N: Real>(fovy: N, aspect: N, near: N, ep: N) -> TMat4<N> {
// unimplemented!() // unimplemented!()
//} //}

View File

@ -1,6 +1,6 @@
use na::{self, Real, U2, U3, U4, Vector3, Vector4, Matrix4}; use na::{self, Real, U3};
use aliases::{Mat, Vec}; use aliases::{TVec2, TVec3, TVec4, TMat4};
/// Define a picking region. /// Define a picking region.
/// ///
@ -8,15 +8,15 @@ use aliases::{Mat, Vec};
/// * `center`: Specify the center of a picking region in window coordinates. /// * `center`: Specify the center of a picking region in window coordinates.
// * `delta`: Specify the width and height, respectively, of the picking region in window coordinates. // * `delta`: Specify the width and height, respectively, of the picking region in window coordinates.
// * `viewport`: Rendering viewport // * `viewport`: Rendering viewport
pub fn pick_matrix<N: Real>(center: &Vec<N, U2>, delta: &Vec<N, U2>, viewport: &Vec<N, U4>) -> Mat<N, U4, U4> { pub fn pick_matrix<N: Real>(center: &TVec2<N>, delta: &TVec2<N>, viewport: &TVec4<N>) -> TMat4<N> {
let shift = Vector3::new( let shift = TVec3::new(
(viewport.z - (center.x - viewport.x) * na::convert(2.0)) / delta.x, (viewport.z - (center.x - viewport.x) * na::convert(2.0)) / delta.x,
(viewport.w - (center.y - viewport.y) * na::convert(2.0)) / delta.y, (viewport.w - (center.y - viewport.y) * na::convert(2.0)) / delta.y,
N::zero() N::zero()
); );
let result = Matrix4::new_translation(&shift); let result = TMat4::new_translation(&shift);
result.prepend_nonuniform_scaling(&Vector3::new(viewport.z / delta.x, viewport.w / delta.y, N::one())) result.prepend_nonuniform_scaling(&TVec3::new(viewport.z / delta.x, viewport.w / delta.y, N::one()))
} }
/// 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 using OpenGL near and far clip planes definition.
@ -26,7 +26,7 @@ pub fn pick_matrix<N: Real>(center: &Vec<N, U2>, delta: &Vec<N, U2>, viewport: &
/// * `model`: Specifies the current modelview matrix. /// * `model`: Specifies the current modelview matrix.
/// * `proj`: Specifies the current projection matrix. /// * `proj`: Specifies the current projection matrix.
/// * `viewport`: Specifies the current viewport. /// * `viewport`: Specifies the current viewport.
pub fn project<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn project<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
project_no(obj, model, proj, viewport) project_no(obj, model, proj, viewport)
} }
@ -39,9 +39,9 @@ pub fn project<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N,
/// * `model`: Specifies the current modelview matrix. /// * `model`: Specifies the current modelview matrix.
/// * `proj`: Specifies the current projection matrix. /// * `proj`: Specifies the current projection matrix.
/// * `viewport`: Specifies the current viewport. /// * `viewport`: Specifies the current viewport.
pub fn project_no<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn project_no<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
let proj = project_zo(obj, model, proj, viewport); let proj = project_zo(obj, model, proj, viewport);
Vector3::new(proj.x, proj.y, proj.z * na::convert(0.5) + na::convert(0.5)) TVec3::new(proj.x, proj.y, proj.z * na::convert(0.5) + na::convert(0.5))
} }
/// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates.
@ -53,11 +53,11 @@ pub fn project_no<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<
/// * `model`: Specifies the current modelview matrix. /// * `model`: Specifies the current modelview matrix.
/// * `proj`: Specifies the current projection matrix. /// * `proj`: Specifies the current projection matrix.
/// * `viewport`: Specifies the current viewport. /// * `viewport`: Specifies the current viewport.
pub fn project_zo<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn project_zo<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
let normalized = proj * model * Vector4::new(obj.x, obj.y, obj.z, N::one()); let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, N::one());
let scale = N::one() / normalized.w; let scale = N::one() / normalized.w;
Vector3::new( TVec3::new(
viewport.x + (viewport.z * (normalized.x * scale + N::one()) * na::convert(0.5)), viewport.x + (viewport.z * (normalized.x * scale + N::one()) * na::convert(0.5)),
viewport.y + (viewport.w * (normalized.y * scale + N::one()) * na::convert(0.5)), viewport.y + (viewport.w * (normalized.y * scale + N::one()) * na::convert(0.5)),
normalized.z * scale, normalized.z * scale,
@ -71,7 +71,7 @@ pub fn project_zo<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<
/// * `model`: Specifies the current modelview matrix. /// * `model`: Specifies the current modelview matrix.
/// * `proj`: Specifies the current projection matrix. /// * `proj`: Specifies the current projection matrix.
/// * `viewport`: Specifies the current viewport. /// * `viewport`: Specifies the current viewport.
pub fn unproject<N: Real>(win: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn unproject<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
unproject_no(win, model, proj, viewport) unproject_no(win, model, proj, viewport)
} }
@ -84,10 +84,10 @@ pub fn unproject<N: Real>(win: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N
/// * `model`: Specifies the current modelview matrix. /// * `model`: Specifies the current modelview matrix.
/// * `proj`: Specifies the current projection matrix. /// * `proj`: Specifies the current projection matrix.
/// * `viewport`: Specifies the current viewport. /// * `viewport`: Specifies the current viewport.
pub fn unproject_no<N: Real>(win: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn unproject_no<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
let _2: N = na::convert(2.0); let _2: N = na::convert(2.0);
let transform = (proj * model).try_inverse().unwrap_or(Matrix4::zeros()); let transform = (proj * model).try_inverse().unwrap_or(TMat4::zeros());
let pt = Vector4::new( let pt = TVec4::new(
_2 * (win.x - viewport.x) / viewport.z - N::one(), _2 * (win.x - viewport.x) / viewport.z - N::one(),
_2 * (win.y - viewport.y) / viewport.w - N::one(), _2 * (win.y - viewport.y) / viewport.w - N::one(),
_2 * win.z - N::one(), _2 * win.z - N::one(),
@ -107,10 +107,10 @@ pub fn unproject_no<N: Real>(win: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Ma
/// * `model`: Specifies the current modelview matrix. /// * `model`: Specifies the current modelview matrix.
/// * `proj`: Specifies the current projection matrix. /// * `proj`: Specifies the current projection matrix.
/// * `viewport`: Specifies the current viewport. /// * `viewport`: Specifies the current viewport.
pub fn unproject_zo<N: Real>(win: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn unproject_zo<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
let _2: N = na::convert(2.0); let _2: N = na::convert(2.0);
let transform = (proj * model).try_inverse().unwrap_or(Matrix4::zeros()); let transform = (proj * model).try_inverse().unwrap_or(TMat4::zeros());
let pt = Vector4::new( let pt = TVec4::new(
_2 * (win.x - viewport.x) / viewport.z - N::one(), _2 * (win.x - viewport.x) / viewport.z - N::one(),
_2 * (win.y - viewport.y) / viewport.w - N::one(), _2 * (win.y - viewport.y) / viewport.w - N::one(),
win.z, win.z,

View File

@ -1,7 +1,7 @@
use na::{DefaultAllocator, Real, U3, U4, Unit, Rotation3, Point3}; use na::{DefaultAllocator, Real, Unit, Rotation3, Point3};
use traits::{Dimension, Number, Alloc}; use traits::{Dimension, Number, Alloc};
use aliases::{Mat, Vec}; use aliases::{Mat, Vec, TVec3, TMat4};
/// The identity matrix. /// The identity matrix.
pub fn identity<N: Number, D: Dimension>() -> Mat<N, D, D> pub fn identity<N: Number, D: Dimension>() -> Mat<N, D, D>
@ -15,7 +15,7 @@ pub fn identity<N: Number, D: Dimension>() -> Mat<N, D, D>
/// * `eye` Position of the camera /// * `eye` Position of the camera
/// * `center` Position where the camera is looking at /// * `center` Position where the camera is looking at
/// * `u` Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)` /// * `u` Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)`
pub fn look_at<N: Real>(eye: &Vec<N, U3>, center: &Vec<N, U3>, up: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn look_at<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
look_at_rh(eye, center, up) look_at_rh(eye, center, up)
} }
@ -25,7 +25,7 @@ pub fn look_at<N: Real>(eye: &Vec<N, U3>, center: &Vec<N, U3>, up: &Vec<N, U3>)
/// * `eye` Position of the camera /// * `eye` Position of the camera
/// * `center` Position where the camera is looking at /// * `center` Position where the camera is looking at
/// * `u` Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)` /// * `u` Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)`
pub fn look_at_lh<N: Real>(eye: &Vec<N, U3>, center: &Vec<N, U3>, up: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn look_at_lh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
Mat::look_at_lh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up) Mat::look_at_lh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up)
} }
@ -35,7 +35,7 @@ pub fn look_at_lh<N: Real>(eye: &Vec<N, U3>, center: &Vec<N, U3>, up: &Vec<N, U3
/// * `eye` Position of the camera /// * `eye` Position of the camera
/// * `center` Position where the camera is looking at /// * `center` Position where the camera is looking at
/// * `u` Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)` /// * `u` Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)`
pub fn look_at_rh<N: Real>(eye: &Vec<N, U3>, center: &Vec<N, U3>, up: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn look_at_rh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
Mat::look_at_rh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up) Mat::look_at_rh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up)
} }
@ -45,7 +45,7 @@ pub fn look_at_rh<N: Real>(eye: &Vec<N, U3>, center: &Vec<N, U3>, up: &Vec<N, U3
/// * m Input matrix multiplied by this rotation matrix. /// * m Input matrix multiplied by this rotation matrix.
/// * angle Rotation angle expressed in radians. /// * angle Rotation angle expressed in radians.
/// * axis Rotation axis, recommended to be normalized. /// * axis Rotation axis, recommended to be normalized.
pub fn rotate<N: Real>(m: &Mat<N, U4, U4>, angle: N, axis: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn rotate<N: Real>(m: &TMat4<N>, angle: N, axis: &TVec3<N>) -> TMat4<N> {
m * Rotation3::from_axis_angle(&Unit::new_normalize(*axis), angle).to_homogeneous() m * Rotation3::from_axis_angle(&Unit::new_normalize(*axis), angle).to_homogeneous()
} }
@ -54,7 +54,7 @@ pub fn rotate<N: Real>(m: &Mat<N, U4, U4>, angle: N, axis: &Vec<N, U3>) -> Mat<N
/// # Parameters /// # Parameters
/// * m Input matrix multiplied by this rotation matrix. /// * m Input matrix multiplied by this rotation matrix.
/// * angle Rotation angle expressed in radians. /// * angle Rotation angle expressed in radians.
pub fn rotate_x<N: Real>(m: &Mat<N, U4, U4>, angle: N) -> Mat<N, U4, U4> { pub fn rotate_x<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
rotate(m, angle, &Vec::x()) rotate(m, angle, &Vec::x())
} }
@ -63,7 +63,7 @@ pub fn rotate_x<N: Real>(m: &Mat<N, U4, U4>, angle: N) -> Mat<N, U4, U4> {
/// # Parameters /// # Parameters
/// * m Input matrix multiplied by this rotation matrix. /// * m Input matrix multiplied by this rotation matrix.
/// * angle Rotation angle expressed in radians. /// * angle Rotation angle expressed in radians.
pub fn rotate_y<N: Real>(m: &Mat<N, U4, U4>, angle: N) -> Mat<N, U4, U4> { pub fn rotate_y<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
rotate(m, angle, &Vec::y()) rotate(m, angle, &Vec::y())
} }
@ -72,7 +72,7 @@ pub fn rotate_y<N: Real>(m: &Mat<N, U4, U4>, angle: N) -> Mat<N, U4, U4> {
/// # Parameters /// # Parameters
/// * m Input matrix multiplied by this rotation matrix. /// * m Input matrix multiplied by this rotation matrix.
/// * angle Rotation angle expressed in radians. /// * angle Rotation angle expressed in radians.
pub fn rotate_z<N: Real>(m: &Mat<N, U4, U4>, angle: N) -> Mat<N, U4, U4> { pub fn rotate_z<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
rotate(m, angle, &Vec::z()) rotate(m, angle, &Vec::z())
} }
@ -81,7 +81,7 @@ pub fn rotate_z<N: Real>(m: &Mat<N, U4, U4>, angle: N) -> Mat<N, U4, U4> {
/// # Parameters /// # Parameters
/// * m Input matrix multiplied by this scale matrix. /// * m Input matrix multiplied by this scale matrix.
/// * v Ratio of scaling for each axis. /// * v Ratio of scaling for each axis.
pub fn scale<N: Number>(m: &Mat<N, U4, U4>, v: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn scale<N: Number>(m: &TMat4<N>, v: &TVec3<N>) -> TMat4<N> {
m.prepend_nonuniform_scaling(v) m.prepend_nonuniform_scaling(v)
} }
@ -90,6 +90,6 @@ pub fn scale<N: Number>(m: &Mat<N, U4, U4>, v: &Vec<N, U3>) -> Mat<N, U4, U4> {
/// # Parameters /// # Parameters
/// * m Input matrix multiplied by this translation matrix. /// * m Input matrix multiplied by this translation matrix.
/// * v Coordinates of a translation vector. /// * v Coordinates of a translation vector.
pub fn translate<N: Number>(m: &Mat<N, U4, U4>, v: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn translate<N: Number>(m: &TMat4<N>, v: &TVec3<N>) -> TMat4<N> {
m.prepend_translation(v) m.prepend_translation(v)
} }

View File

@ -1,6 +1,6 @@
use na::{Real, U3, UnitQuaternion, Unit}; use na::{Real, UnitQuaternion, Unit};
use aliases::{Vec, Qua}; use aliases::{Qua, TVec3};
/// Computes the quaternion exponential. /// Computes the quaternion exponential.
pub fn quat_exp<N: Real>(q: &Qua<N>) -> Qua<N> { pub fn quat_exp<N: Real>(q: &Qua<N>) -> Qua<N> {
@ -18,7 +18,7 @@ pub fn quat_pow<N: Real>(q: &Qua<N>, y: N) -> Qua<N> {
} }
/// Builds a quaternion from an axis and an angle, and right-multiply it to the quaternion `q`. /// Builds a quaternion from an axis and an angle, and right-multiply it to the quaternion `q`.
pub fn quat_rotate<N: Real>(q: &Qua<N>, angle: N, axis: &Vec<N, U3>) -> Qua<N> { pub fn quat_rotate<N: Real>(q: &Qua<N>, angle: N, axis: &TVec3<N>) -> Qua<N> {
q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap() q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap()
} }

View File

@ -1,6 +1,6 @@
use na::{Real, U3, Unit, UnitQuaternion, Vector3}; use na::{Real, Unit, UnitQuaternion};
use aliases::{Vec, Qua}; use aliases::{Qua, TVec3};
/// The rotation angle of this quaternion assumed to be normalized. /// The rotation angle of this quaternion assumed to be normalized.
pub fn quat_angle<N: Real>(x: &Qua<N>) -> N { pub fn quat_angle<N: Real>(x: &Qua<N>) -> N {
@ -8,15 +8,15 @@ pub fn quat_angle<N: Real>(x: &Qua<N>) -> N {
} }
/// Creates a quaternion from an axis and an angle. /// Creates a quaternion from an axis and an angle.
pub fn quat_angle_axis<N: Real>(angle: N, axis: &Vec<N, U3>) -> Qua<N> { pub fn quat_angle_axis<N: Real>(angle: N, axis: &TVec3<N>) -> Qua<N> {
UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap() UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap()
} }
/// The rotation axis of a quaternion assumed to be normalized. /// The rotation axis of a quaternion assumed to be normalized.
pub fn quat_axis<N: Real>(x: &Qua<N>) -> Vec<N, U3> { pub fn quat_axis<N: Real>(x: &Qua<N>) -> TVec3<N> {
if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() { if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() {
a.unwrap() a.unwrap()
} else { } else {
Vector3::zeros() TVec3::zeros()
} }
} }

View File

@ -1,10 +1,10 @@
use na::{Real, U3, DefaultAllocator}; use na::{Real, DefaultAllocator};
use traits::{Number, Alloc, Dimension}; use traits::{Number, Alloc, Dimension};
use aliases::Vec; use aliases::{Vec, TVec3};
/// The cross product of two vectors. /// The cross product of two vectors.
pub fn cross<N: Number, D: Dimension>(x: &Vec<N, U3>, y: &Vec<N, U3>) -> Vec<N, U3> { pub fn cross<N: Number, D: Dimension>(x: &TVec3<N>, y: &TVec3<N>) -> TVec3<N> {
x.cross(y) x.cross(y)
} }

View File

@ -49,7 +49,7 @@ pub fn packInt4x8(v: &I8Vec4) -> i32 {
unimplemented!() unimplemented!()
} }
pub fn packRGBM<N: Scalar>(rgb: &Vec<N, U3>) -> Vec<N, U4> { pub fn packRGBM<N: Scalar>(rgb: &TVec3<N>) -> TVec4<N> {
unimplemented!() unimplemented!()
} }
@ -192,7 +192,7 @@ pub fn unpackInt4x8(p: i32) -> I8Vec4 {
unimplemented!() unimplemented!()
} }
pub fn unpackRGBM<N: Scalar>(rgbm: &Vec<N, U4>) -> Vec<N, U3> { pub fn unpackRGBM<N: Scalar>(rgbm: &TVec4<N>) -> TVec3<N> {
unimplemented!() unimplemented!()
} }

View File

@ -1,13 +1,13 @@
use na::{Real, U3, U4, UnitQuaternion, Vector3}; use na::{Real, U4, UnitQuaternion};
use aliases::{Qua, Vec, Mat}; use aliases::{Qua, Vec, TVec3, TMat4};
/// Euler angles of the quaternion `q` as (pitch, yaw, roll). /// Euler angles of the quaternion `q` as (pitch, yaw, roll).
pub fn quat_euler_angles<N: Real>(x: &Qua<N>) -> Vec<N, U3> { pub fn quat_euler_angles<N: Real>(x: &Qua<N>) -> TVec3<N> {
let q = UnitQuaternion::new_unchecked(*x); let q = UnitQuaternion::new_unchecked(*x);
let a = q.to_euler_angles(); let a = q.to_euler_angles();
Vector3::new(a.2, a.1, a.0) TVec3::new(a.2, a.1, a.0)
} }
/// Component-wise `>` comparison between two quaternions. /// Component-wise `>` comparison between two quaternions.
@ -31,21 +31,21 @@ pub fn quat_less_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
} }
/// Convert a quaternion to a rotation matrix in homogeneous coordinates. /// Convert a quaternion to a rotation matrix in homogeneous coordinates.
pub fn quat_cast<N: Real>(x: &Qua<N>) -> Mat<N, U4, U4> { pub fn quat_cast<N: Real>(x: &Qua<N>) -> TMat4<N> {
::quat_to_mat4(x) ::quat_to_mat4(x)
} }
/// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix). /// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix).
pub fn quat_look_at<N: Real>(direction: &Vec<N, U3>, up: &Vec<N, U3>) -> Qua<N> { pub fn quat_look_at<N: Real>(direction: &TVec3<N>, up: &TVec3<N>) -> Qua<N> {
quat_look_at_rh(direction, up) quat_look_at_rh(direction, up)
} }
/// Computes a left-handed look-at quaternion (equivalent to a left-handed look-at matrix). /// Computes a left-handed look-at quaternion (equivalent to a left-handed look-at matrix).
pub fn quat_look_at_lh<N: Real>(direction: &Vec<N, U3>, up: &Vec<N, U3>) -> Qua<N> { pub fn quat_look_at_lh<N: Real>(direction: &TVec3<N>, up: &TVec3<N>) -> Qua<N> {
UnitQuaternion::look_at_lh(direction, up).unwrap() UnitQuaternion::look_at_lh(direction, up).unwrap()
} }
/// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix). /// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix).
pub fn quat_look_at_rh<N: Real>(direction: &Vec<N, U3>, up: &Vec<N, U3>) -> Qua<N> { pub fn quat_look_at_rh<N: Real>(direction: &TVec3<N>, up: &TVec3<N>) -> Qua<N> {
UnitQuaternion::look_at_rh(direction, up).unwrap() UnitQuaternion::look_at_rh(direction, up).unwrap()
} }

View File

@ -1,76 +1,75 @@
use na::{Scalar, Real, U1, U2, U3, U4, DefaultAllocator, use na::{Scalar, Real, DefaultAllocator, Quaternion};
Quaternion, Matrix2, Matrix3, Matrix4, Vector1, Vector2, Vector3, Vector4,
Matrix2x3, Matrix2x4, Matrix3x2, Matrix3x4, Matrix4x2, Matrix4x3};
use traits::{Number, Alloc, Dimension}; use traits::{Number, Alloc, Dimension};
use aliases::{Qua, Vec, Mat}; use aliases::{Qua, Mat, TMat2, TMat3, TMat4, TVec1, TVec2, TVec3, TVec4,
TMat2x3, TMat2x4, TMat3x2, TMat3x4, TMat4x2, TMat4x3};
/// Creates a 2x2 matrix from a slice arranged in column-major order. /// Creates a 2x2 matrix from a slice arranged in column-major order.
pub fn make_mat2<N: Scalar>(ptr: &[N]) -> Mat<N, U2, U2> { pub fn make_mat2<N: Scalar>(ptr: &[N]) -> TMat2<N> {
Matrix2::from_column_slice(ptr) TMat2::from_column_slice(ptr)
} }
/// Creates a 2x2 matrix from a slice arranged in column-major order. /// Creates a 2x2 matrix from a slice arranged in column-major order.
pub fn make_mat2x2<N: Scalar>(ptr: &[N]) -> Mat<N, U2, U2> { pub fn make_mat2x2<N: Scalar>(ptr: &[N]) -> TMat2<N> {
Matrix2::from_column_slice(ptr) TMat2::from_column_slice(ptr)
} }
/// Creates a 2x3 matrix from a slice arranged in column-major order. /// Creates a 2x3 matrix from a slice arranged in column-major order.
pub fn make_mat2x3<N: Scalar>(ptr: &[N]) -> Mat<N, U2, U3> { pub fn make_mat2x3<N: Scalar>(ptr: &[N]) -> TMat2x3<N> {
Matrix2x3::from_column_slice(ptr) TMat2x3::from_column_slice(ptr)
} }
/// Creates a 2x4 matrix from a slice arranged in column-major order. /// Creates a 2x4 matrix from a slice arranged in column-major order.
pub fn make_mat2x4<N: Scalar>(ptr: &[N]) -> Mat<N, U2, U4> { pub fn make_mat2x4<N: Scalar>(ptr: &[N]) -> TMat2x4<N> {
Matrix2x4::from_column_slice(ptr) TMat2x4::from_column_slice(ptr)
} }
/// Creates a 3 matrix from a slice arranged in column-major order. /// Creates a 3 matrix from a slice arranged in column-major order.
pub fn make_mat3<N: Scalar>(ptr: &[N]) -> Mat<N, U3, U3> { pub fn make_mat3<N: Scalar>(ptr: &[N]) -> TMat3<N> {
Matrix3::from_column_slice(ptr) TMat3::from_column_slice(ptr)
} }
/// Creates a 3x2 matrix from a slice arranged in column-major order. /// Creates a 3x2 matrix from a slice arranged in column-major order.
pub fn make_mat3x2<N: Scalar>(ptr: &[N]) -> Mat<N, U3, U2> { pub fn make_mat3x2<N: Scalar>(ptr: &[N]) -> TMat3x2<N> {
Matrix3x2::from_column_slice(ptr) TMat3x2::from_column_slice(ptr)
} }
/// Creates a 3x3 matrix from a slice arranged in column-major order. /// Creates a 3x3 matrix from a slice arranged in column-major order.
pub fn make_mat3x3<N: Scalar>(ptr: &[N]) -> Mat<N, U3, U3> { pub fn make_mat3x3<N: Scalar>(ptr: &[N]) -> TMat3<N> {
Matrix3::from_column_slice(ptr) TMat3::from_column_slice(ptr)
} }
/// Creates a 3x4 matrix from a slice arranged in column-major order. /// Creates a 3x4 matrix from a slice arranged in column-major order.
pub fn make_mat3x4<N: Scalar>(ptr: &[N]) -> Mat<N, U3, U4> { pub fn make_mat3x4<N: Scalar>(ptr: &[N]) -> TMat3x4<N> {
Matrix3x4::from_column_slice(ptr) TMat3x4::from_column_slice(ptr)
} }
/// Creates a 4x4 matrix from a slice arranged in column-major order. /// Creates a 4x4 matrix from a slice arranged in column-major order.
pub fn make_mat4<N: Scalar>(ptr: &[N]) -> Mat<N, U4, U4> { pub fn make_mat4<N: Scalar>(ptr: &[N]) -> TMat4<N> {
Matrix4::from_column_slice(ptr) TMat4::from_column_slice(ptr)
} }
/// Creates a 4x2 matrix from a slice arranged in column-major order. /// Creates a 4x2 matrix from a slice arranged in column-major order.
pub fn make_mat4x2<N: Scalar>(ptr: &[N]) -> Mat<N, U4, U2> { pub fn make_mat4x2<N: Scalar>(ptr: &[N]) -> TMat4x2<N> {
Matrix4x2::from_column_slice(ptr) TMat4x2::from_column_slice(ptr)
} }
/// Creates a 4x3 matrix from a slice arranged in column-major order. /// Creates a 4x3 matrix from a slice arranged in column-major order.
pub fn make_mat4x3<N: Scalar>(ptr: &[N]) -> Mat<N, U4, U3> { pub fn make_mat4x3<N: Scalar>(ptr: &[N]) -> TMat4x3<N> {
Matrix4x3::from_column_slice(ptr) TMat4x3::from_column_slice(ptr)
} }
/// Creates a 4x4 matrix from a slice arranged in column-major order. /// Creates a 4x4 matrix from a slice arranged in column-major order.
pub fn make_mat4x4<N: Scalar>(ptr: &[N]) -> Mat<N, U4, U4> { pub fn make_mat4x4<N: Scalar>(ptr: &[N]) -> TMat4<N> {
Matrix4::from_column_slice(ptr) TMat4::from_column_slice(ptr)
} }
/// Converts a 2x2 matrix to a 3x3 matrix. /// Converts a 2x2 matrix to a 3x3 matrix.
pub fn mat2_to_mat3<N: Number>(m: &Mat<N, U2, U2>) -> Mat<N, U3, U3> { pub fn mat2_to_mat3<N: Number>(m: &TMat2<N>) -> TMat3<N> {
let _0 = N::zero(); let _0 = N::zero();
let _1 = N::one(); let _1 = N::one();
Matrix3::new( TMat3::new(
m.m11, m.m12, _0, m.m11, m.m12, _0,
m.m21, m.m22, _0, m.m21, m.m22, _0,
_0, _0, _1 _0, _0, _1
@ -78,19 +77,19 @@ pub fn mat2_to_mat3<N: Number>(m: &Mat<N, U2, U2>) -> Mat<N, U3, U3> {
} }
/// Converts a 3x3 matrix to a 2x2 matrix. /// Converts a 3x3 matrix to a 2x2 matrix.
pub fn mat3_to_mat2<N: Scalar>(m: &Mat<N, U3, U3>) -> Mat<N, U2, U2> { pub fn mat3_to_mat2<N: Scalar>(m: &TMat3<N>) -> TMat2<N> {
Matrix2::new( TMat2::new(
m.m11, m.m12, m.m11, m.m12,
m.m21, m.m22 m.m21, m.m22
) )
} }
/// Converts a 3x3 matrix to a 4x4 matrix. /// Converts a 3x3 matrix to a 4x4 matrix.
pub fn mat3_to_mat4<N: Number>(m: &Mat<N, U3, U3>) -> Mat<N, U4, U4> { pub fn mat3_to_mat4<N: Number>(m: &TMat3<N>) -> TMat4<N> {
let _0 = N::zero(); let _0 = N::zero();
let _1 = N::one(); let _1 = N::one();
Matrix4::new( TMat4::new(
m.m11, m.m12, m.m13, _0, m.m11, m.m12, m.m13, _0,
m.m21, m.m22, m.m23, _0, m.m21, m.m22, m.m23, _0,
m.m31, m.m32, m.m33, _0, m.m31, m.m32, m.m33, _0,
@ -99,8 +98,8 @@ pub fn mat3_to_mat4<N: Number>(m: &Mat<N, U3, U3>) -> Mat<N, U4, U4> {
} }
/// Converts a 4x4 matrix to a 3x3 matrix. /// Converts a 4x4 matrix to a 3x3 matrix.
pub fn mat4_to_mat3<N: Scalar>(m: &Mat<N, U4, U4>) -> Mat<N, U3, U3> { pub fn mat4_to_mat3<N: Scalar>(m: &TMat4<N>) -> TMat3<N> {
Matrix3::new( TMat3::new(
m.m11, m.m12, m.m13, m.m11, m.m12, m.m13,
m.m21, m.m22, m.m23, m.m21, m.m22, m.m23,
m.m31, m.m32, m.m33, m.m31, m.m32, m.m33,
@ -108,11 +107,11 @@ pub fn mat4_to_mat3<N: Scalar>(m: &Mat<N, U4, U4>) -> Mat<N, U3, U3> {
} }
/// Converts a 2x2 matrix to a 4x4 matrix. /// Converts a 2x2 matrix to a 4x4 matrix.
pub fn mat2_to_mat4<N: Number>(m: &Mat<N, U2, U2>) -> Mat<N, U4, U4> { pub fn mat2_to_mat4<N: Number>(m: &TMat2<N>) -> TMat4<N> {
let _0 = N::zero(); let _0 = N::zero();
let _1 = N::one(); let _1 = N::one();
Matrix4::new( TMat4::new(
m.m11, m.m12, _0, _0, m.m11, m.m12, _0, _0,
m.m21, m.m22, _0, _0, m.m21, m.m22, _0, _0,
_0, _0, _1, _0, _0, _0, _1, _0,
@ -121,8 +120,8 @@ pub fn mat2_to_mat4<N: Number>(m: &Mat<N, U2, U2>) -> Mat<N, U4, U4> {
} }
/// Converts a 4x4 matrix to a 2x2 matrix. /// Converts a 4x4 matrix to a 2x2 matrix.
pub fn mat4_to_mat2<N: Scalar>(m: &Mat<N, U4, U4>) -> Mat<N, U2, U2> { pub fn mat4_to_mat2<N: Scalar>(m: &TMat4<N>) -> TMat2<N> {
Matrix2::new( TMat2::new(
m.m11, m.m12, m.m11, m.m12,
m.m21, m.m22, m.m21, m.m22,
) )
@ -130,114 +129,114 @@ pub fn mat4_to_mat2<N: Scalar>(m: &Mat<N, U4, U4>) -> Mat<N, U2, U2> {
/// Creates a quaternion from a slice arranged as `[x, y, z, w]`. /// Creates a quaternion from a slice arranged as `[x, y, z, w]`.
pub fn make_quat<N: Real>(ptr: &[N]) -> Qua<N> { pub fn make_quat<N: Real>(ptr: &[N]) -> Qua<N> {
Quaternion::from_vector(Vector4::from_column_slice(ptr)) Quaternion::from_vector(TVec4::from_column_slice(ptr))
} }
/// Creates a 1D vector from a slice. /// Creates a 1D vector from a slice.
pub fn make_vec1<N: Scalar>(v: &Vec<N, U1>) -> Vec<N, U1> { pub fn make_vec1<N: Scalar>(v: &TVec1<N>) -> TVec1<N> {
*v *v
} }
/// Creates a 1D vector from another vector. /// Creates a 1D vector from another vector.
pub fn vec2_to_vec1<N: Scalar>(v: &Vec<N, U2>) -> Vec<N, U1> { pub fn vec2_to_vec1<N: Scalar>(v: &TVec2<N>) -> TVec1<N> {
Vector1::new(v.x) TVec1::new(v.x)
} }
/// Creates a 1D vector from another vector. /// Creates a 1D vector from another vector.
pub fn vec3_to_vec1<N: Scalar>(v: &Vec<N, U3>) -> Vec<N, U1> { pub fn vec3_to_vec1<N: Scalar>(v: &TVec3<N>) -> TVec1<N> {
Vector1::new(v.x) TVec1::new(v.x)
} }
/// Creates a 1D vector from another vector. /// Creates a 1D vector from another vector.
pub fn vec4_to_vec1<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U1> { pub fn vec4_to_vec1<N: Scalar>(v: &TVec4<N>) -> TVec1<N> {
Vector1::new(v.x) TVec1::new(v.x)
} }
/// Creates a 2D vector from another vector. /// Creates a 2D vector from another vector.
/// ///
/// Missing components, if any, are set to 0. /// Missing components, if any, are set to 0.
pub fn vec1_to_vec2<N: Number>(v: &Vec<N, U1>) -> Vec<N, U2> { pub fn vec1_to_vec2<N: Number>(v: &TVec1<N>) -> TVec2<N> {
Vector2::new(v.x, N::zero()) TVec2::new(v.x, N::zero())
} }
/// Creates a 2D vector from another vector. /// Creates a 2D vector from another vector.
pub fn vec2_to_vec2<N: Scalar>(v: &Vec<N, U2>) -> Vec<N, U2> { pub fn vec2_to_vec2<N: Scalar>(v: &TVec2<N>) -> TVec2<N> {
*v *v
} }
/// Creates a 2D vector from another vector. /// Creates a 2D vector from another vector.
pub fn vec3_to_vec2<N: Scalar>(v: &Vec<N, U3>) -> Vec<N, U2> { pub fn vec3_to_vec2<N: Scalar>(v: &TVec3<N>) -> TVec2<N> {
Vector2::new(v.x, v.y) TVec2::new(v.x, v.y)
} }
/// Creates a 2D vector from another vector. /// Creates a 2D vector from another vector.
pub fn vec4_to_vec2<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U2> { pub fn vec4_to_vec2<N: Scalar>(v: &TVec4<N>) -> TVec2<N> {
Vector2::new(v.x, v.y) TVec2::new(v.x, v.y)
} }
/// Creates a 2D vector from a slice. /// Creates a 2D vector from a slice.
pub fn make_vec2<N: Scalar>(ptr: &[N]) -> Vec<N, U2> { pub fn make_vec2<N: Scalar>(ptr: &[N]) -> TVec2<N> {
Vector2::from_column_slice(ptr) TVec2::from_column_slice(ptr)
} }
/// Creates a 3D vector from another vector. /// Creates a 3D vector from another vector.
/// ///
/// Missing components, if any, are set to 0. /// Missing components, if any, are set to 0.
pub fn vec1_to_vec3<N: Number>(v: &Vec<N, U1>) -> Vec<N, U3> { pub fn vec1_to_vec3<N: Number>(v: &TVec1<N>) -> TVec3<N> {
Vector3::new(v.x, N::zero(), N::zero()) TVec3::new(v.x, N::zero(), N::zero())
} }
/// Creates a 3D vector from another vector. /// Creates a 3D vector from another vector.
/// ///
/// Missing components, if any, are set to 0. /// Missing components, if any, are set to 0.
pub fn vec2_to_vec3<N: Number>(v: &Vec<N, U2>) -> Vec<N, U3> { pub fn vec2_to_vec3<N: Number>(v: &TVec2<N>) -> TVec3<N> {
Vector3::new(v.x, v.y, N::zero()) TVec3::new(v.x, v.y, N::zero())
} }
/// Creates a 3D vector from another vector. /// Creates a 3D vector from another vector.
pub fn vec3_to_vec3<N: Scalar>(v: &Vec<N, U3>) -> Vec<N, U3> { pub fn vec3_to_vec3<N: Scalar>(v: &TVec3<N>) -> TVec3<N> {
*v *v
} }
/// Creates a 3D vector from another vector. /// Creates a 3D vector from another vector.
pub fn vec4_to_vec3<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U3> { pub fn vec4_to_vec3<N: Scalar>(v: &TVec4<N>) -> TVec3<N> {
Vector3::new(v.x, v.y, v.z) TVec3::new(v.x, v.y, v.z)
} }
/// Creates a 3D vector from another vector. /// Creates a 3D vector from another vector.
pub fn make_vec3<N: Scalar>(ptr: &[N]) -> Vec<N, U3> { pub fn make_vec3<N: Scalar>(ptr: &[N]) -> TVec3<N> {
Vector3::from_column_slice(ptr) TVec3::from_column_slice(ptr)
} }
/// Creates a 4D vector from another vector. /// Creates a 4D vector from another vector.
/// ///
/// Missing components, if any, are set to 0. /// Missing components, if any, are set to 0.
pub fn vec1_to_vec4<N: Number>(v: &Vec<N, U1>) -> Vec<N, U4> { pub fn vec1_to_vec4<N: Number>(v: &TVec1<N>) -> TVec4<N> {
Vector4::new(v.x, N::zero(), N::zero(), N::zero()) TVec4::new(v.x, N::zero(), N::zero(), N::zero())
} }
/// Creates a 4D vector from another vector. /// Creates a 4D vector from another vector.
/// ///
/// Missing components, if any, are set to 0. /// Missing components, if any, are set to 0.
pub fn vec2_to_vec4<N: Number>(v: &Vec<N, U2>) -> Vec<N, U4> { pub fn vec2_to_vec4<N: Number>(v: &TVec2<N>) -> TVec4<N> {
Vector4::new(v.x, v.y, N::zero(), N::zero()) TVec4::new(v.x, v.y, N::zero(), N::zero())
} }
/// Creates a 4D vector from another vector. /// Creates a 4D vector from another vector.
/// ///
/// Missing components, if any, are set to 0. /// Missing components, if any, are set to 0.
pub fn vec3_to_vec4<N: Number>(v: &Vec<N, U3>) -> Vec<N, U4> { pub fn vec3_to_vec4<N: Number>(v: &TVec3<N>) -> TVec4<N> {
Vector4::new(v.x, v.y, v.z, N::zero()) TVec4::new(v.x, v.y, v.z, N::zero())
} }
/// Creates a 4D vector from another vector. /// Creates a 4D vector from another vector.
pub fn vec4_to_vec4<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U4> { pub fn vec4_to_vec4<N: Scalar>(v: &TVec4<N>) -> TVec4<N> {
*v *v
} }
/// Creates a 4D vector from another vector. /// Creates a 4D vector from another vector.
pub fn make_vec4<N: Scalar>(ptr: &[N]) -> Vec<N, U4> { pub fn make_vec4<N: Scalar>(ptr: &[N]) -> TVec4<N> {
Vector4::from_column_slice(ptr) TVec4::from_column_slice(ptr)
} }
/// Converts a matrix or vector to a slice arranged in column-major order. /// Converts a matrix or vector to a slice arranged in column-major order.

View File

@ -7,7 +7,7 @@ pub fn float_distance<T>(x: T, y: T) -> u64 {
unimplemented!() unimplemented!()
} }
pub fn float_distance2<N: Scalar>(x: &Vec<N, U2>, y: &Vec<N, U2>) -> Vec<u64, U2> { pub fn float_distance2<N: Scalar>(x: &TVec2<N>, y: &TVec2<N>) -> Vec<u64, U2> {
unimplemented!() unimplemented!()
} }

View File

@ -2,162 +2,162 @@ use na::{Real, U3, U4};
use aliases::{Vec, Mat}; use aliases::{Vec, Mat};
pub fn derivedEulerAngleX<N: Real>(angleX: N, angularVelocityX: N) -> Mat<N, U4, U4> { pub fn derivedEulerAngleX<N: Real>(angleX: N, angularVelocityX: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn derivedEulerAngleY<N: Real>(angleY: N, angularVelocityY: N) -> Mat<N, U4, U4> { pub fn derivedEulerAngleY<N: Real>(angleY: N, angularVelocityY: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn derivedEulerAngleZ<N: Real>(angleZ: N, angularVelocityZ: N) -> Mat<N, U4, U4> { pub fn derivedEulerAngleZ<N: Real>(angleZ: N, angularVelocityZ: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleX<N: Real>(angleX: N) -> Mat<N, U4, U4> { pub fn eulerAngleX<N: Real>(angleX: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleXY<N: Real>(angleX: N, angleY: N) -> Mat<N, U4, U4> { pub fn eulerAngleXY<N: Real>(angleX: N, angleY: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleXYX<N: Real>(t1: N, t2: N, t3: N) -> Mat<N, U4, U4> { pub fn eulerAngleXYX<N: Real>(t1: N, t2: N, t3: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleXYZ<N: Real>(t1: N, t2: N, t3: N) -> Mat<N, U4, U4> { pub fn eulerAngleXYZ<N: Real>(t1: N, t2: N, t3: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleXZ<N: Real>(angleX: N, angleZ: N) -> Mat<N, U4, U4> { pub fn eulerAngleXZ<N: Real>(angleX: N, angleZ: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleXZX<N: Real>(t1: N, t2: N, t3: N) -> Mat<N, U4, U4> { pub fn eulerAngleXZX<N: Real>(t1: N, t2: N, t3: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleXZY<N: Real>(t1: N, t2: N, t3: N) -> Mat<N, U4, U4> { pub fn eulerAngleXZY<N: Real>(t1: N, t2: N, t3: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleY<N: Real>(angleY: N) -> Mat<N, U4, U4> { pub fn eulerAngleY<N: Real>(angleY: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleYX<N: Real>(angleY: N, angleX: N) -> Mat<N, U4, U4> { pub fn eulerAngleYX<N: Real>(angleY: N, angleX: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleYXY<N: Real>(t1: N, t2: N, t3: N) -> Mat<N, U4, U4> { pub fn eulerAngleYXY<N: Real>(t1: N, t2: N, t3: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleYXZ<N: Real>(yaw: N, pitch: N, roll: N) -> Mat<N, U4, U4> { pub fn eulerAngleYXZ<N: Real>(yaw: N, pitch: N, roll: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleYZ<N: Real>(angleY: N, angleZ: N) -> Mat<N, U4, U4> { pub fn eulerAngleYZ<N: Real>(angleY: N, angleZ: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleYZX<N: Real>(t1: N, t2: N, t3: N) -> Mat<N, U4, U4> { pub fn eulerAngleYZX<N: Real>(t1: N, t2: N, t3: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleYZY<N: Real>(t1: N, t2: N, t3: N) -> Mat<N, U4, U4> { pub fn eulerAngleYZY<N: Real>(t1: N, t2: N, t3: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleZ<N: Real>(angleZ: N) -> Mat<N, U4, U4> { pub fn eulerAngleZ<N: Real>(angleZ: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleZX<N: Real>(angle: N, angleX: N) -> Mat<N, U4, U4> { pub fn eulerAngleZX<N: Real>(angle: N, angleX: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleZXY<N: Real>(t1: N, t2: N, t3: N) -> Mat<N, U4, U4> { pub fn eulerAngleZXY<N: Real>(t1: N, t2: N, t3: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleZXZ<N: Real>(t1: N, t2: N, t3: N) -> Mat<N, U4, U4> { pub fn eulerAngleZXZ<N: Real>(t1: N, t2: N, t3: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleZY<N: Real>(angleZ: N, angleY: N) -> Mat<N, U4, U4> { pub fn eulerAngleZY<N: Real>(angleZ: N, angleY: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleZYX<N: Real>(t1: N, t2: N, t3: N) -> Mat<N, U4, U4> { pub fn eulerAngleZYX<N: Real>(t1: N, t2: N, t3: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn eulerAngleZYZ<N: Real>(t1: N, t2: N, t3: N) -> Mat<N, U4, U4> { pub fn eulerAngleZYZ<N: Real>(t1: N, t2: N, t3: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleXYX<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleXYX<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleXYZ<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleXYZ<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleXZX<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleXZX<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleXZY<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleXZY<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleYXY<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleYXY<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleYXZ<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleYXZ<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleYZX<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleYZX<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleYZY<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleYZY<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleZXY<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleZXY<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleZXZ<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleZXZ<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleZYX<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleZYX<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn extractEulerAngleZYZ<N: Real>(M: &Mat<N, U4, U4>) -> (N, N, N) { pub fn extractEulerAngleZYZ<N: Real>(M: &TMat4<N>) -> (N, N, N) {
unimplemented!() unimplemented!()
} }
pub fn orientate2<N: Real>(angle: N) -> Mat<N, U3, U3> { pub fn orientate2<N: Real>(angle: N) -> TMat3x3<N> {
unimplemented!() unimplemented!()
} }
pub fn orientate3<N: Real>(angles: Vec<N, U3>) -> Mat<N, U3, U3> { pub fn orientate3<N: Real>(angles: TVec3<N>) -> TMat3x3<N> {
unimplemented!() unimplemented!()
} }
pub fn orientate4<N: Real>(angles: Vec<N, U3>) -> Mat<N, U4, U4> { pub fn orientate4<N: Real>(angles: TVec3<N>) -> TMat4<N> {
unimplemented!() unimplemented!()
} }
pub fn yawPitchRoll<N: Real>(yaw: N, pitch: N, roll: N) -> Mat<N, U4, U4> { pub fn yawPitchRoll<N: Real>(yaw: N, pitch: N, roll: N) -> TMat4<N> {
unimplemented!() unimplemented!()
} }

View File

@ -1,9 +1,7 @@
use na::U2;
use traits::Number; use traits::Number;
use aliases::Vec; use aliases::TVec2;
/// The 2D perpendicular product between two vectors. /// The 2D perpendicular product between two vectors.
pub fn cross2d<N: Number>(v: &Vec<N, U2>, u: &Vec<N, U2>) -> N { pub fn cross2d<N: Number>(v: &TVec2<N>, u: &TVec2<N>) -> N {
v.perp(u) v.perp(u)
} }

View File

@ -1,14 +1,12 @@
use na::U3;
use traits::Number; use traits::Number;
use aliases::Vec; use aliases::TVec3;
/// Returns `true` if `{a, b, c}` forms a left-handed trihedron. /// Returns `true` if `{a, b, c}` forms a left-handed trihedron.
pub fn left_handed<N: Number>(a: &Vec<N, U3>, b: &Vec<N, U3>, c: &Vec<N, U3>) -> bool { pub fn left_handed<N: Number>(a: &TVec3<N>, b: &TVec3<N>, c: &TVec3<N>) -> bool {
a.cross(b).dot(c) < N::zero() a.cross(b).dot(c) < N::zero()
} }
/// Returns `true` if `{a, b, c}` forms a right-handed trihedron. /// Returns `true` if `{a, b, c}` forms a right-handed trihedron.
pub fn right_handed<N: Number>(a: &Vec<N, U3>, b: &Vec<N, U3>, c: &Vec<N, U3>) -> bool { pub fn right_handed<N: Number>(a: &TVec3<N>, b: &TVec3<N>, c: &TVec3<N>) -> bool {
a.cross(b).dot(c) > N::zero() a.cross(b).dot(c) > N::zero()
} }

View File

@ -1,18 +1,18 @@
use na::{Real, U3, U4, Matrix4}; use na::Real;
use aliases::{Vec, Mat}; use aliases::{TMat3, TMat4, TVec3};
/// Builds a 3x3 matrix `m` such that for any `v`: `m * v == cross(x, v)`. /// Builds a 3x3 matrix `m` such that for any `v`: `m * v == cross(x, v)`.
pub fn matrix_cross3<N: Real>(x: &Vec<N, U3>) -> Mat<N, U3, U3> { pub fn matrix_cross3<N: Real>(x: &TVec3<N>) -> TMat3<N> {
x.cross_matrix() x.cross_matrix()
} }
/// Builds a 4x4 matrix `m` such that for any `v`: `m * v == cross(x, v)`. /// Builds a 4x4 matrix `m` such that for any `v`: `m * v == cross(x, v)`.
pub fn matrix_cross<N: Real>(x: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn matrix_cross<N: Real>(x: &TVec3<N>) -> TMat4<N> {
let m = x.cross_matrix(); let m = x.cross_matrix();
// FIXME: use a dedicated constructor from Matrix3 to Matrix4. // FIXME: use a dedicated constructor from Matrix3 to Matrix4.
Matrix4::new( TMat4::new(
m.m11, m.m12, m.m13, N::zero(), m.m11, m.m12, m.m13, N::zero(),
m.m21, m.m22, m.m23, N::zero(), m.m21, m.m22, m.m23, N::zero(),
m.m31, m.m32, m.m33, N::zero(), m.m31, m.m32, m.m33, N::zero(),

View File

@ -1,50 +1,47 @@
use na::{Matrix2, Matrix2x3, Matrix2x4, Matrix3, Matrix3x2, Matrix3x4, Matrix4, Matrix4x2, Matrix4x3,
U2, U3, U4};
use traits::Number; use traits::Number;
use aliases::{Vec, Mat}; use aliases::{TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3};
/// Builds a 2x2 diagonal matrix. /// Builds a 2x2 diagonal matrix.
pub fn diagonal2x2<N: Number>(v: &Vec<N, U2>) -> Mat<N, U2, U2> { pub fn diagonal2x2<N: Number>(v: &TVec2<N>) -> TMat2<N> {
Matrix2::from_diagonal(v) TMat2::from_diagonal(v)
} }
/// Builds a 2x3 diagonal matrix. /// Builds a 2x3 diagonal matrix.
pub fn diagonal2x3<N: Number>(v: &Vec<N, U2>) -> Mat<N, U2, U3> { pub fn diagonal2x3<N: Number>(v: &TVec2<N>) -> TMat2x3<N> {
Matrix2x3::from_partial_diagonal(v.as_slice()) TMat2x3::from_partial_diagonal(v.as_slice())
} }
/// Builds a 2x4 diagonal matrix. /// Builds a 2x4 diagonal matrix.
pub fn diagonal2x4<N: Number>(v: &Vec<N, U2>) -> Mat<N, U2, U4> { pub fn diagonal2x4<N: Number>(v: &TVec2<N>) -> TMat2x4<N> {
Matrix2x4::from_partial_diagonal(v.as_slice()) TMat2x4::from_partial_diagonal(v.as_slice())
} }
/// Builds a 3x2 diagonal matrix. /// Builds a 3x2 diagonal matrix.
pub fn diagonal3x2<N: Number>(v: &Vec<N, U3>) -> Mat<N, U3, U2> { pub fn diagonal3x2<N: Number>(v: &TVec3<N>) -> TMat3x2<N> {
Matrix3x2::from_partial_diagonal(v.as_slice()) TMat3x2::from_partial_diagonal(v.as_slice())
} }
/// Builds a 3x3 diagonal matrix. /// Builds a 3x3 diagonal matrix.
pub fn diagonal3x3<N: Number>(v: &Vec<N, U3>) -> Mat<N, U3, U3> { pub fn diagonal3x3<N: Number>(v: &TVec3<N>) -> TMat3<N> {
Matrix3::from_diagonal(v) TMat3::from_diagonal(v)
} }
/// Builds a 3x4 diagonal matrix. /// Builds a 3x4 diagonal matrix.
pub fn diagonal3x4<N: Number>(v: &Vec<N, U3>) -> Mat<N, U3, U4> { pub fn diagonal3x4<N: Number>(v: &TVec3<N>) -> TMat3x4<N> {
Matrix3x4::from_partial_diagonal(v.as_slice()) TMat3x4::from_partial_diagonal(v.as_slice())
} }
/// Builds a 4x2 diagonal matrix. /// Builds a 4x2 diagonal matrix.
pub fn diagonal4x2<N: Number>(v: &Vec<N, U4>) -> Mat<N, U4, U2> { pub fn diagonal4x2<N: Number>(v: &TVec4<N>) -> TMat4x2<N> {
Matrix4x2::from_partial_diagonal(v.as_slice()) TMat4x2::from_partial_diagonal(v.as_slice())
} }
/// Builds a 4x3 diagonal matrix. /// Builds a 4x3 diagonal matrix.
pub fn diagonal4x3<N: Number>(v: &Vec<N, U4>) -> Mat<N, U4, U3> { pub fn diagonal4x3<N: Number>(v: &TVec4<N>) -> TMat4x3<N> {
Matrix4x3::from_partial_diagonal(v.as_slice()) TMat4x3::from_partial_diagonal(v.as_slice())
} }
/// Builds a 4x4 diagonal matrix. /// Builds a 4x4 diagonal matrix.
pub fn diagonal4x4<N: Number>(v: &Vec<N, U4>) -> Mat<N, U4, U4> { pub fn diagonal4x4<N: Number>(v: &TVec4<N>) -> TMat4<N> {
Matrix4::from_diagonal(v) TMat4::from_diagonal(v)
} }

View File

@ -1,10 +1,10 @@
use na::{Real, U3}; use na::Real;
use aliases::Vec; use aliases::TVec3;
/// The normal vector of the given triangle. /// The normal vector of the given triangle.
/// ///
/// The normal is computed as the normalized vector `cross(p2 - p1, p3 - p1)`. /// The normal is computed as the normalized vector `cross(p2 - p1, p3 - p1)`.
pub fn triangle_normal<N: Real>(p1: &Vec<N, U3>, p2: &Vec<N, U3>, p3: &Vec<N, U3>) -> Vec<N, U3> { pub fn triangle_normal<N: Real>(p1: &TVec3<N>, p2: &TVec3<N>, p3: &TVec3<N>) -> TVec3<N> {
(p2 - p1).cross(&(p3 - p1)).normalize() (p2 - p1).cross(&(p3 - p1)).normalize()
} }

View File

@ -1,14 +1,14 @@
use na::{Real, Unit, Rotation3, Vector4, UnitQuaternion, U3, U4}; use na::{Real, Unit, Rotation3, UnitQuaternion, U3};
use aliases::{Qua, Vec, Mat}; use aliases::{Qua, TMat3, TMat4, TVec3, TVec4};
/// Rotate the vector `v` by the quaternion `q` assumed to be normalized. /// Rotate the vector `v` by the quaternion `q` assumed to be normalized.
pub fn quat_cross_vec<N: Real>(q: &Qua<N>, v: &Vec<N, U3>) -> Vec<N, U3> { pub fn quat_cross_vec<N: Real>(q: &Qua<N>, v: &TVec3<N>) -> TVec3<N> {
UnitQuaternion::new_unchecked(*q) * v UnitQuaternion::new_unchecked(*q) * v
} }
/// Rotate the vector `v` by the inverse of the quaternion `q` assumed to be normalized. /// Rotate the vector `v` by the inverse of the quaternion `q` assumed to be normalized.
pub fn quat_inv_cross_vec<N: Real>(v: &Vec<N, U3>, q: &Qua<N>) -> Vec<N, U3> { pub fn quat_inv_cross_vec<N: Real>(v: &TVec3<N>, q: &Qua<N>) -> TVec3<N> {
UnitQuaternion::new_unchecked(*q).inverse() * v UnitQuaternion::new_unchecked(*q).inverse() * v
} }
@ -42,19 +42,19 @@ pub fn quat_identity<N: Real>() -> Qua<N> {
} }
/// Rotates a vector by a quaternion assumed to be normalized. /// Rotates a vector by a quaternion assumed to be normalized.
pub fn quat_rotate_vec3<N: Real>(q: &Qua<N>, v: &Vec<N, U3>) -> Vec<N, U3> { pub fn quat_rotate_vec3<N: Real>(q: &Qua<N>, v: &TVec3<N>) -> TVec3<N> {
UnitQuaternion::new_unchecked(*q) * v UnitQuaternion::new_unchecked(*q) * v
} }
/// Rotates a vector in homogeneous coordinates by a quaternion assumed to be normalized. /// Rotates a vector in homogeneous coordinates by a quaternion assumed to be normalized.
pub fn quat_rotate_vec<N: Real>(q: &Qua<N>, v: &Vec<N, U4>) -> Vec<N, U4> { pub fn quat_rotate_vec<N: Real>(q: &Qua<N>, v: &TVec4<N>) -> TVec4<N> {
// UnitQuaternion::new_unchecked(*q) * v // UnitQuaternion::new_unchecked(*q) * v
let rotated = Unit::new_unchecked(*q) * v.fixed_rows::<U3>(0); let rotated = Unit::new_unchecked(*q) * v.fixed_rows::<U3>(0);
Vector4::new(rotated.x, rotated.y, rotated.z, v.w) TVec4::new(rotated.x, rotated.y, rotated.z, v.w)
} }
/// The rotation required to align `orig` to `dest`. /// The rotation required to align `orig` to `dest`.
pub fn quat_rotation<N: Real>(orig: &Vec<N, U3>, dest: &Vec<N, U3>) -> Qua<N> { pub fn quat_rotation<N: Real>(orig: &TVec3<N>, dest: &TVec3<N>) -> Qua<N> {
UnitQuaternion::rotation_between(orig, dest).unwrap_or(UnitQuaternion::identity()).unwrap() UnitQuaternion::rotation_between(orig, dest).unwrap_or(UnitQuaternion::identity()).unwrap()
} }
@ -68,23 +68,23 @@ pub fn quat_short_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
//} //}
/// Converts a quaternion to a rotation matrix. /// Converts a quaternion to a rotation matrix.
pub fn quat_to_mat3<N: Real>(x: &Qua<N>) -> Mat<N, U3, U3> { pub fn quat_to_mat3<N: Real>(x: &Qua<N>) -> TMat3<N> {
UnitQuaternion::new_unchecked(*x).to_rotation_matrix().unwrap() UnitQuaternion::new_unchecked(*x).to_rotation_matrix().unwrap()
} }
/// Converts a quaternion to a rotation matrix in homogenous coordinates. /// Converts a quaternion to a rotation matrix in homogenous coordinates.
pub fn quat_to_mat4<N: Real>(x: &Qua<N>) -> Mat<N, U4, U4> { pub fn quat_to_mat4<N: Real>(x: &Qua<N>) -> TMat4<N> {
UnitQuaternion::new_unchecked(*x).to_homogeneous() UnitQuaternion::new_unchecked(*x).to_homogeneous()
} }
/// Converts a rotation matrix to a quaternion. /// Converts a rotation matrix to a quaternion.
pub fn mat3_to_quat<N: Real>(x: &Mat<N, U3, U3>) -> Qua<N> { pub fn mat3_to_quat<N: Real>(x: &TMat3<N>) -> Qua<N> {
let r = Rotation3::from_matrix_unchecked(*x); let r = Rotation3::from_matrix_unchecked(*x);
UnitQuaternion::from_rotation_matrix(&r).unwrap() UnitQuaternion::from_rotation_matrix(&r).unwrap()
} }
/// Converts a rotation matrix in homogeneous coordinates to a quaternion. /// Converts a rotation matrix in homogeneous coordinates to a quaternion.
pub fn to_quat<N: Real>(x: &Mat<N, U4, U4>) -> Qua<N> { pub fn to_quat<N: Real>(x: &TMat4<N>) -> Qua<N> {
let rot = x.fixed_slice::<U3, U3>(0, 0).into_owned(); let rot = x.fixed_slice::<U3, U3>(0, 0).into_owned();
mat3_to_quat(&rot) mat3_to_quat(&rot)
} }

View File

@ -1,6 +1,6 @@
use na::{Real, Rotation3, Unit, UnitQuaternion, U3, U4}; use na::{Real, Rotation3, Unit, UnitQuaternion};
use aliases::{Vec, Mat, Qua}; use aliases::{Qua, TMat4, TVec3};
/// Builds a rotation 4 * 4 matrix created from a normalized axis and an angle. /// Builds a rotation 4 * 4 matrix created from a normalized axis and an angle.
/// ///
@ -8,7 +8,7 @@ use aliases::{Vec, Mat, Qua};
/// * `m` - Input matrix multiplied by this rotation matrix. /// * `m` - Input matrix multiplied by this rotation matrix.
/// * `angle` - Rotation angle expressed in radians. /// * `angle` - Rotation angle expressed in radians.
/// * `axis` - Rotation axis, must be normalized. /// * `axis` - Rotation axis, must be normalized.
pub fn rotate_normalized_axis<N: Real>(m: &Mat<N, U4, U4>, angle: N, axis: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn rotate_normalized_axis<N: Real>(m: &TMat4<N>, angle: N, axis: &TVec3<N>) -> TMat4<N> {
m * Rotation3::from_axis_angle(&Unit::new_unchecked(*axis), angle).to_homogeneous() m * Rotation3::from_axis_angle(&Unit::new_unchecked(*axis), angle).to_homogeneous()
} }
@ -18,6 +18,6 @@ pub fn rotate_normalized_axis<N: Real>(m: &Mat<N, U4, U4>, angle: N, axis: &Vec<
/// * `q` - Source orientation /// * `q` - Source orientation
/// * `angle` - Angle expressed in radians. /// * `angle` - Angle expressed in radians.
/// * `axis` - Normalized axis of the rotation, must be normalized. /// * `axis` - Normalized axis of the rotation, must be normalized.
pub fn quat_rotate_normalized_axis<N: Real>(q: &Qua<N>, angle: N, axis: &Vec<N, U3>) -> Qua<N> { pub fn quat_rotate_normalized_axis<N: Real>(q: &Qua<N>, angle: N, axis: &TVec3<N>) -> Qua<N> {
q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).unwrap() q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).unwrap()
} }

View File

@ -1,62 +1,62 @@
use na::{Real, U2, U3, U4, Rotation3, Vector3, Unit, UnitComplex}; use na::{Real, Rotation3, Unit, UnitComplex};
use aliases::{Vec, Mat}; use aliases::{TVec2, TVec3, TVec4, TMat4};
/// Build the rotation matrix needed to align `normal` and `up`. /// Build the rotation matrix needed to align `normal` and `up`.
pub fn orientation<N: Real>(normal: &Vec<N, U3>, up: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn orientation<N: Real>(normal: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
if let Some(r) = Rotation3::rotation_between(normal, up) { if let Some(r) = Rotation3::rotation_between(normal, up) {
r.to_homogeneous() r.to_homogeneous()
} else { } else {
Mat::<N, U4, U4>::identity() TMat4::identity()
} }
} }
/// Rotate a two dimensional vector. /// Rotate a two dimensional vector.
pub fn rotate_vec2<N: Real>(v: &Vec<N, U2>, angle: N) -> Vec<N, U2> { pub fn rotate_vec2<N: Real>(v: &TVec2<N>, angle: N) -> TVec2<N> {
UnitComplex::new(angle) * v UnitComplex::new(angle) * v
} }
/// Rotate a three dimensional vector around an axis. /// Rotate a three dimensional vector around an axis.
pub fn rotate_vec3<N: Real>(v: &Vec<N, U3>, angle: N, normal: &Vec<N, U3>) -> Vec<N, U3> { pub fn rotate_vec3<N: Real>(v: &TVec3<N>, angle: N, normal: &TVec3<N>) -> TVec3<N> {
Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle) * v Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle) * v
} }
/// Rotate a thee dimensional vector in homogeneous coordinates around an axis. /// Rotate a thee dimensional vector in homogeneous coordinates around an axis.
pub fn rotate_vec4<N: Real>(v: &Vec<N, U4>, angle: N, normal: &Vec<N, U3>) -> Vec<N, U4> { pub fn rotate_vec4<N: Real>(v: &TVec4<N>, angle: N, normal: &TVec3<N>) -> TVec4<N> {
Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle).to_homogeneous() * v Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle).to_homogeneous() * v
} }
/// Rotate a three dimensional vector around the `X` axis. /// Rotate a three dimensional vector around the `X` axis.
pub fn rotate_x_vec3<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> { pub fn rotate_x_vec3<N: Real>(v: &TVec3<N>, angle: N) -> TVec3<N> {
Rotation3::from_axis_angle(&Vector3::x_axis(), angle) * v Rotation3::from_axis_angle(&TVec3::x_axis(), angle) * v
} }
/// Rotate a three dimensional vector in homogeneous coordinates around the `X` axis. /// Rotate a three dimensional vector in homogeneous coordinates around the `X` axis.
pub fn rotate_x_vec4<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> { pub fn rotate_x_vec4<N: Real>(v: &TVec4<N>, angle: N) -> TVec4<N> {
Rotation3::from_axis_angle(&Vector3::x_axis(), angle).to_homogeneous() * v Rotation3::from_axis_angle(&TVec3::x_axis(), angle).to_homogeneous() * v
} }
/// Rotate a three dimensional vector around the `Y` axis. /// Rotate a three dimensional vector around the `Y` axis.
pub fn rotate_y_vec3<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> { pub fn rotate_y_vec3<N: Real>(v: &TVec3<N>, angle: N) -> TVec3<N> {
Rotation3::from_axis_angle(&Vector3::y_axis(), angle) * v Rotation3::from_axis_angle(&TVec3::y_axis(), angle) * v
} }
/// Rotate a three dimensional vector in homogeneous coordinates around the `Y` axis. /// Rotate a three dimensional vector in homogeneous coordinates around the `Y` axis.
pub fn rotate_y_vec4<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> { pub fn rotate_y_vec4<N: Real>(v: &TVec4<N>, angle: N) -> TVec4<N> {
Rotation3::from_axis_angle(&Vector3::y_axis(), angle).to_homogeneous() * v Rotation3::from_axis_angle(&TVec3::y_axis(), angle).to_homogeneous() * v
} }
/// Rotate a three dimensional vector around the `Z` axis. /// Rotate a three dimensional vector around the `Z` axis.
pub fn rotate_z_vec3<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> { pub fn rotate_z_vec3<N: Real>(v: &TVec3<N>, angle: N) -> TVec3<N> {
Rotation3::from_axis_angle(&Vector3::z_axis(), angle) * v Rotation3::from_axis_angle(&TVec3::z_axis(), angle) * v
} }
/// Rotate a three dimensional vector in homogeneous coordinates around the `Z` axis. /// Rotate a three dimensional vector in homogeneous coordinates around the `Z` axis.
pub fn rotate_z_vec4<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> { pub fn rotate_z_vec4<N: Real>(v: &TVec4<N>, angle: N) -> TVec4<N> {
Rotation3::from_axis_angle(&Vector3::z_axis(), angle).to_homogeneous() * v Rotation3::from_axis_angle(&TVec3::z_axis(), angle).to_homogeneous() * v
} }
/// Computes a spehical linear interpolation between the vectors `x` and `y` assumed to be normalized. /// Computes a spehical linear interpolation between the vectors `x` and `y` assumed to be normalized.
pub fn slerp<N: Real>(x: &Vec<N, U3>, y: &Vec<N, U3>, a: N) -> Vec<N, U3> { pub fn slerp<N: Real>(x: &TVec3<N>, y: &TVec3<N>, a: N) -> TVec3<N> {
Unit::new_unchecked(*x).slerp(&Unit::new_unchecked(*y), a).unwrap() Unit::new_unchecked(*x).slerp(&Unit::new_unchecked(*y), a).unwrap()
} }

View File

@ -1,35 +1,35 @@
use na::{Real, Unit, Rotation2, Rotation3, Matrix3, Matrix4, U2, U3, U4}; use na::{Real, Unit, Rotation2, Rotation3};
use traits::Number; use traits::Number;
use aliases::{Vec, Mat}; use aliases::{TVec3, TVec2, TMat3, TMat4};
/// A rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in radians. /// A rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in radians.
pub fn rotation<N: Real>(angle: N, v: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn rotation<N: Real>(angle: N, v: &TVec3<N>) -> TMat4<N> {
Rotation3::from_axis_angle(&Unit::new_normalize(*v), angle).to_homogeneous() Rotation3::from_axis_angle(&Unit::new_normalize(*v), angle).to_homogeneous()
} }
/// A 4 * 4 scale matrix created from a vector of 3 components. /// A 4 * 4 scale matrix created from a vector of 3 components.
pub fn scaling<N: Number>(v: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn scaling<N: Number>(v: &TVec3<N>) -> TMat4<N> {
Matrix4::new_nonuniform_scaling(v) TMat4::new_nonuniform_scaling(v)
} }
/// A 4 * 4 translation matrix created from the scaling factor on each axis. /// A 4 * 4 translation matrix created from the scaling factor on each axis.
pub fn translation<N: Number>(v: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn translation<N: Number>(v: &TVec3<N>) -> TMat4<N> {
Matrix4::new_translation(v) TMat4::new_translation(v)
} }
/// A rotation 3 * 3 matrix created from an angle expressed in radians. /// A rotation 3 * 3 matrix created from an angle expressed in radians.
pub fn rotation2d<N: Real>(angle: N) -> Mat<N, U3, U3> { pub fn rotation2d<N: Real>(angle: N) -> TMat3<N> {
Rotation2::new(angle).to_homogeneous() Rotation2::new(angle).to_homogeneous()
} }
/// A 3 * 3 scale matrix created from a vector of 2 components. /// A 3 * 3 scale matrix created from a vector of 2 components.
pub fn scaling2d<N: Number>(v: &Vec<N, U2>) -> Mat<N, U3, U3> { pub fn scaling2d<N: Number>(v: &TVec2<N>) -> TMat3<N> {
Matrix3::new_nonuniform_scaling(v) TMat3::new_nonuniform_scaling(v)
} }
/// A 3 * 3 translation matrix created from the scaling factor on each axis. /// A 3 * 3 translation matrix created from the scaling factor on each axis.
pub fn translation2d<N: Number>(v: &Vec<N, U2>) -> Mat<N, U3, U3> { pub fn translation2d<N: Number>(v: &TVec2<N>) -> TMat3<N> {
Matrix3::new_translation(v) TMat3::new_translation(v)
} }

View File

@ -1,11 +1,11 @@
use na::{U2, U3, U4, Matrix3, Matrix4}; use na::{U2, U3};
use traits::Number; use traits::Number;
use aliases::{Mat, Vec}; use aliases::{TVec2, TVec3, TMat3, TMat4};
/// Build planar projection matrix along normal axis and right-multiply it to `m`. /// Build planar projection matrix along normal axis and right-multiply it to `m`.
pub fn proj2d<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U3, U3> { pub fn proj2d<N: Number>(m: &TMat3<N>, normal: &TVec2<N>) -> TMat3<N> {
let mut res = Matrix3::identity(); let mut res = TMat3::identity();
{ {
let mut part = res.fixed_slice_mut::<U2, U2>(0, 0); let mut part = res.fixed_slice_mut::<U2, U2>(0, 0);
@ -16,8 +16,8 @@ pub fn proj2d<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U3,
} }
/// Build planar projection matrix along normal axis, and right-multiply it to `m`. /// Build planar projection matrix along normal axis, and right-multiply it to `m`.
pub fn proj<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn proj<N: Number>(m: &TMat4<N>, normal: &TVec3<N>) -> TMat4<N> {
let mut res = Matrix4::identity(); let mut res = TMat4::identity();
{ {
let mut part = res.fixed_slice_mut::<U3, U3>(0, 0); let mut part = res.fixed_slice_mut::<U3, U3>(0, 0);
@ -28,8 +28,8 @@ pub fn proj<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4, U4
} }
/// Builds a reflection matrix and right-multiply it to `m`. /// Builds a reflection matrix and right-multiply it to `m`.
pub fn reflect2d<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U3, U3> { pub fn reflect2d<N: Number>(m: &TMat3<N>, normal: &TVec2<N>) -> TMat3<N> {
let mut res = Matrix3::identity(); let mut res = TMat3::identity();
{ {
let mut part = res.fixed_slice_mut::<U2, U2>(0, 0); let mut part = res.fixed_slice_mut::<U2, U2>(0, 0);
@ -40,8 +40,8 @@ pub fn reflect2d<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U
} }
/// Builds a reflection matrix, and right-multiply it to `m`. /// Builds a reflection matrix, and right-multiply it to `m`.
pub fn reflect<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn reflect<N: Number>(m: &TMat4<N>, normal: &TVec3<N>) -> TMat4<N> {
let mut res = Matrix4::identity(); let mut res = TMat4::identity();
{ {
let mut part = res.fixed_slice_mut::<U3, U3>(0, 0); let mut part = res.fixed_slice_mut::<U3, U3>(0, 0);
@ -52,11 +52,11 @@ pub fn reflect<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4,
} }
/// Builds a scale-bias matrix. /// Builds a scale-bias matrix.
pub fn scale_bias_matrix<N: Number>(scale: N, bias: N) -> Mat<N, U4, U4> { pub fn scale_bias_matrix<N: Number>(scale: N, bias: N) -> TMat4<N> {
let _0 = N::zero(); let _0 = N::zero();
let _1 = N::one(); let _1 = N::one();
Matrix4::new( TMat4::new(
scale, _0, _0, bias, scale, _0, _0, bias,
_0, scale, _0, bias, _0, scale, _0, bias,
_0, _0, scale, bias, _0, _0, scale, bias,
@ -65,16 +65,16 @@ pub fn scale_bias_matrix<N: Number>(scale: N, bias: N) -> Mat<N, U4, U4> {
} }
/// Builds a scale-bias matrix, and right-multiply it to `m`. /// Builds a scale-bias matrix, and right-multiply it to `m`.
pub fn scale_bias<N: Number>(m: &Mat<N, U4, U4>, scale: N, bias: N) -> Mat<N, U4, U4> { pub fn scale_bias<N: Number>(m: &TMat4<N>, scale: N, bias: N) -> TMat4<N> {
m * scale_bias_matrix(scale, bias) m * scale_bias_matrix(scale, bias)
} }
/// Transforms a matrix with a shearing on X axis. /// Transforms a matrix with a shearing on X axis.
pub fn shear2d_x<N: Number>(m: &Mat<N, U3, U3>, y: N) -> Mat<N, U3, U3> { pub fn shear2d_x<N: Number>(m: &TMat3<N>, y: N) -> TMat3<N> {
let _0 = N::zero(); let _0 = N::zero();
let _1 = N::one(); let _1 = N::one();
let shear = Matrix3::new( let shear = TMat3::new(
_1, y, _0, _1, y, _0,
_0, _1, _0, _0, _1, _0,
_0, _0, _1 _0, _0, _1
@ -83,10 +83,10 @@ pub fn shear2d_x<N: Number>(m: &Mat<N, U3, U3>, y: N) -> Mat<N, U3, U3> {
} }
/// Transforms a matrix with a shearing on Y axis. /// Transforms a matrix with a shearing on Y axis.
pub fn shear_x<N: Number>(m: &Mat<N, U4, U4>, y: N, z: N) -> Mat<N, U4, U4> { pub fn shear_x<N: Number>(m: &TMat4<N>, y: N, z: N) -> TMat4<N> {
let _0 = N::zero(); let _0 = N::zero();
let _1 = N::one(); let _1 = N::one();
let shear = Matrix4::new( let shear = TMat4::new(
_1, _0, _0, _0, _1, _0, _0, _0,
y, _1, _0, _0, y, _1, _0, _0,
z, _0, _1, _0, z, _0, _1, _0,
@ -97,11 +97,11 @@ pub fn shear_x<N: Number>(m: &Mat<N, U4, U4>, y: N, z: N) -> Mat<N, U4, U4> {
} }
/// Transforms a matrix with a shearing on Y axis. /// Transforms a matrix with a shearing on Y axis.
pub fn shear2d_y<N: Number>(m: &Mat<N, U3, U3>, x: N) -> Mat<N, U3, U3> { pub fn shear2d_y<N: Number>(m: &TMat3<N>, x: N) -> TMat3<N> {
let _0 = N::zero(); let _0 = N::zero();
let _1 = N::one(); let _1 = N::one();
let shear = Matrix3::new( let shear = TMat3::new(
_1, _0, _0, _1, _0, _0,
x, _1, _0, x, _1, _0,
_0, _0, _1 _0, _0, _1
@ -110,10 +110,10 @@ pub fn shear2d_y<N: Number>(m: &Mat<N, U3, U3>, x: N) -> Mat<N, U3, U3> {
} }
/// Transforms a matrix with a shearing on Y axis. /// Transforms a matrix with a shearing on Y axis.
pub fn shear_y<N: Number>(m: &Mat<N, U4, U4>, x: N, z: N) -> Mat<N, U4, U4> { pub fn shear_y<N: Number>(m: &TMat4<N>, x: N, z: N) -> TMat4<N> {
let _0 = N::zero(); let _0 = N::zero();
let _1 = N::one(); let _1 = N::one();
let shear = Matrix4::new( let shear = TMat4::new(
_1, x, _0, _0, _1, x, _0, _0,
_0, _1, _0, _0, _0, _1, _0, _0,
_0, z, _1, _0, _0, z, _1, _0,
@ -124,10 +124,10 @@ pub fn shear_y<N: Number>(m: &Mat<N, U4, U4>, x: N, z: N) -> Mat<N, U4, U4> {
} }
/// Transforms a matrix with a shearing on Z axis. /// Transforms a matrix with a shearing on Z axis.
pub fn shear_z<N: Number>(m: &Mat<N, U4, U4>, x: N, y: N) -> Mat<N, U4, U4> { pub fn shear_z<N: Number>(m: &TMat4<N>, x: N, y: N) -> TMat4<N> {
let _0 = N::zero(); let _0 = N::zero();
let _1 = N::one(); let _1 = N::one();
let shear = Matrix4::new( let shear = TMat4::new(
_1, _0, x, _0, _1, _0, x, _0,
_0, _1, y, _0, _0, _1, y, _0,
_0, _0, _1, _0, _0, _0, _1, _0,

View File

@ -1,19 +1,19 @@
use na::{Real, U2, U3, UnitComplex}; use na::{Real, UnitComplex};
use traits::Number; use traits::Number;
use aliases::{Mat, Vec}; use aliases::{TMat3, TVec2};
/// Builds a 2D rotation matrix from an angle and right-multiply it to `m`. /// Builds a 2D rotation matrix from an angle and right-multiply it to `m`.
pub fn rotate2d<N: Real>(m: &Mat<N, U3, U3>, angle: N) -> Mat<N, U3, U3> { pub fn rotate2d<N: Real>(m: &TMat3<N>, angle: N) -> TMat3<N> {
m * UnitComplex::new(angle).to_homogeneous() m * UnitComplex::new(angle).to_homogeneous()
} }
/// Builds a 2D scaling matrix and right-multiply it to `m`. /// Builds a 2D scaling matrix and right-multiply it to `m`.
pub fn scale2d<N: Number>(m: &Mat<N, U3, U3>, v: &Vec<N, U2>) -> Mat<N, U3, U3> { pub fn scale2d<N: Number>(m: &TMat3<N>, v: &TVec2<N>) -> TMat3<N> {
m.prepend_nonuniform_scaling(v) m.prepend_nonuniform_scaling(v)
} }
/// Builds a translation matrix and right-multiply it to `m`. /// Builds a translation matrix and right-multiply it to `m`.
pub fn translate2d<N: Number>(m: &Mat<N, U3, U3>, v: &Vec<N, U2>) -> Mat<N, U3, U3> { pub fn translate2d<N: Number>(m: &TMat3<N>, v: &TVec2<N>) -> TMat3<N> {
m.prepend_translation(v) m.prepend_translation(v)
} }

View File

@ -10,10 +10,10 @@ pub fn angle<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
x.angle(y) x.angle(y)
} }
//pub fn oriented_angle<N: Real>(x: &Vec<N, U2>, y: &Vec<N, U2>) -> N { //pub fn oriented_angle<N: Real>(x: &TVec2<N>, y: &TVec2<N>) -> N {
// unimplemented!() // unimplemented!()
//} //}
// //
//pub fn oriented_angle_ref<N: Real>(x: &Vec<N, U3>, y: &Vec<N, U3>, refv: &Vec<N, U3>) -> N { //pub fn oriented_angle_ref<N: Real>(x: &TVec3<N>, y: &TVec3<N>, refv: &TVec3<N>) -> N {
// unimplemented!() // unimplemented!()
//} //}

View File

@ -1,15 +1,15 @@
use na::{Real, DefaultAllocator, U2, U3}; use na::{Real, DefaultAllocator};
use traits::{Number, Dimension, Alloc}; use traits::{Number, Dimension, Alloc};
use aliases::Vec; use aliases::{Vec, TVec2, TVec3};
/// Returns `true` if two vectors are collinear (up to an epsilon). /// Returns `true` if two vectors are collinear (up to an epsilon).
pub fn are_collinear<N: Number>(v0: &Vec<N, U3>, v1: &Vec<N, U3>, epsilon: N) -> bool { pub fn are_collinear<N: Number>(v0: &TVec3<N>, v1: &TVec3<N>, epsilon: N) -> bool {
is_null(&v0.cross(v1), epsilon) is_null(&v0.cross(v1), epsilon)
} }
/// Returns `true` if two 2D vectors are collinear (up to an epsilon). /// Returns `true` if two 2D vectors are collinear (up to an epsilon).
pub fn are_collinear2d<N: Number>(v0: &Vec<N, U2>, v1: &Vec<N, U2>, epsilon: N) -> bool { pub fn are_collinear2d<N: Number>(v0: &TVec2<N>, v1: &TVec2<N>, epsilon: N) -> bool {
abs_diff_eq!(v0.perp(v1), N::zero(), epsilon = epsilon) abs_diff_eq!(v0.perp(v1), N::zero(), epsilon = epsilon)
} }