diff --git a/nalgebra-glm/src/aliases.rs b/nalgebra-glm/src/aliases.rs index e21c0e60..f64651b5 100644 --- a/nalgebra-glm/src/aliases.rs +++ b/nalgebra-glm/src/aliases.rs @@ -11,6 +11,14 @@ pub type Vec = VectorN; /// A quaternion with components of type `N`. pub type Qua = Quaternion; +/// A 1D vector with components of type `N`. +pub type TVec1 = Vector1; +/// A 2D vector with components of type `N`. +pub type TVec2 = Vector2; +/// A 3D vector with components of type `N`. +pub type TVec3 = Vector3; +/// A 4D vector with components of type `N`. +pub type TVec4 = Vector4; /// A 1D vector with boolean components. pub type BVec1 = Vector1; /// A 2D vector with boolean components. @@ -121,7 +129,31 @@ pub type I8Vec3 = Vector3; pub type I8Vec4 = Vector4; -/// A 2x2 matrix with `f64` components. +/// A 2x2 matrix with components of type `N`. +pub type TMat2 = Matrix2; +/// A 2x2 matrix with components of type `N`. +pub type TMat2x2 = Matrix2; +/// A 2x3 matrix with components of type `N`. +pub type TMat2x3 = Matrix2x3; +/// A 2x4 matrix with components of type `N`. +pub type TMat2x4 = Matrix2x4; +/// A 3x3 matrix with components of type `N`. +pub type TMat3 = Matrix3; +/// A 3x2 matrix with components of type `N`. +pub type TMat3x2 = Matrix3x2; +/// A 3x3 matrix with components of type `N`. +pub type TMat3x3 = Matrix3; +/// A 3x4 matrix with components of type `N`. +pub type TMat3x4 = Matrix3x4; +/// A 4x4 matrix with components of type `N`. +pub type TMat4 = Matrix4; +/// A 4x2 matrix with components of type `N`. +pub type TMat4x2 = Matrix4x2; +/// A 4x3 matrix with components of type `N`. +pub type TMat4x3 = Matrix4x3; +/// A 4x4 matrix with components of type `N`. +pub type TMat4x4 = Matrix4; +/// A 2x2 matrix with components of type `N`. pub type DMat2 = Matrix2; /// A 2x2 matrix with `f64` components. pub type DMat2x2 = Matrix2; diff --git a/nalgebra-glm/src/constructors.rs b/nalgebra-glm/src/constructors.rs index aa40eb9d..6af4a567 100644 --- a/nalgebra-glm/src/constructors.rs +++ b/nalgebra-glm/src/constructors.rs @@ -1,30 +1,31 @@ -use na::{Scalar, Real, U1, U2, U3, U4}; -use aliases::{Vec, Mat, Qua}; +use na::{Scalar, Real, U2, U3, U4}; +use aliases::{Mat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, + TMat4, TMat4x2, TMat4x3}; /// Creates a new 1D vector. -pub fn vec1(x: N) -> Vec { - Vec::::new(x) +pub fn vec1(x: N) -> TVec1 { + TVec1::new(x) } /// Creates a new 2D vector. -pub fn vec2(x: N, y: N) -> Vec { - Vec::::new(x, y) +pub fn vec2(x: N, y: N) -> TVec2 { + TVec2::new(x, y) } /// Creates a new 3D vector. -pub fn vec3(x: N, y: N, z: N) -> Vec { - Vec::::new(x, y, z) +pub fn vec3(x: N, y: N, z: N) -> TVec3 { + TVec3::new(x, y, z) } /// Creates a new 4D vector. -pub fn vec4(x: N, y: N, z: N, w: N) -> Vec { - Vec::::new(x, y, z, w) +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) -> Mat { +pub fn mat2(m11: N, m12: N, m21: N, m22: N) -> TMat2 { Mat::::new( m11, m12, m21, m22, @@ -32,7 +33,7 @@ pub fn mat2(m11: N, m12: N, m21: N, m22: N) -> Mat { } /// Create a new 2x2 matrix. -pub fn mat2x2(m11: N, m12: N, m21: N, m22: N) -> Mat { +pub fn mat2x2(m11: N, m12: N, m21: N, m22: N) -> TMat2 { Mat::::new( m11, m12, m21, m22, @@ -40,7 +41,7 @@ pub fn mat2x2(m11: N, m12: N, m21: N, m22: N) -> Mat { } /// Create a new 2x3 matrix. -pub fn mat2x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> Mat { +pub fn mat2x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat2x3 { Mat::::new( m11, m12, m13, m21, m22, m23, @@ -48,7 +49,7 @@ pub fn mat2x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> Mat< } /// Create a new 2x4 matrix. -pub fn mat2x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N) -> Mat { +pub fn mat2x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N) -> TMat2x4 { Mat::::new( m11, m12, m13, m14, m21, m22, m23, m24, @@ -56,7 +57,7 @@ pub fn mat2x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, } /// 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) -> Mat { +pub fn mat3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3 { Mat::::new( m11, m12, m13, m21, m22, m23, @@ -65,7 +66,7 @@ pub fn mat3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m } /// Create a new 3x2 matrix. -pub fn mat3x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> Mat { +pub fn mat3x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat3x2 { Mat::::new( m11, m12, m21, m22, @@ -74,7 +75,7 @@ pub fn mat3x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> Mat< } /// 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) -> Mat { +pub fn mat3x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3 { Mat::::new( m11, m12, m13, m31, m32, m33, @@ -83,7 +84,7 @@ pub fn mat3x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, } /// 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) -> Mat { +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 { Mat::::new( m11, m12, m13, m14, m21, m22, m23, m24, @@ -92,7 +93,7 @@ pub fn mat3x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, } /// Create a new 4x2 matrix. -pub fn mat4x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N, m42: N) -> Mat { +pub fn mat4x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N, m42: N) -> TMat4x2 { Mat::::new( m11, m12, m21, m22, @@ -102,7 +103,7 @@ pub fn mat4x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N, } /// 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) -> Mat { +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 { Mat::::new( m11, m12, m13, m21, m22, m23, @@ -112,7 +113,7 @@ pub fn mat4x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, } /// 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) -> Mat { +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 { Mat::::new( m11, m12, m13, m14, m21, m22, m23, m24, @@ -122,7 +123,7 @@ pub fn mat4x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, } /// 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) -> Mat { +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 { Mat::::new( m11, m12, m13, m14, m21, m22, m23, m24, diff --git a/nalgebra-glm/src/ext/matrix_clip_space.rs b/nalgebra-glm/src/ext/matrix_clip_space.rs index 87bea38b..0795a873 100644 --- a/nalgebra-glm/src/ext/matrix_clip_space.rs +++ b/nalgebra-glm/src/ext/matrix_clip_space.rs @@ -1,172 +1,172 @@ -use na::{Real, U4, Orthographic3, Perspective3}; -use aliases::Mat; +use na::{Real, Orthographic3, Perspective3}; +use aliases::TMat4; -//pub fn frustum(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat { +//pub fn frustum(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { // unimplemented!() //} -//pub fn frustum_lh(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat { +//pub fn frustum_lh(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_lr_no(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat { +//pub fn frustum_lr_no(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_lh_zo(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat { +//pub fn frustum_lh_zo(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_no(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat { +//pub fn frustum_no(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_rh(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat { +//pub fn frustum_rh(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_rh_no(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat { +//pub fn frustum_rh_no(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_rh_zo(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat { +//pub fn frustum_rh_zo(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_zo(left: N, right: N, bottom: N, top: N, near: N, far: N) -> Mat { +//pub fn frustum_zo(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { // unimplemented!() //} -//pub fn infinite_perspective(fovy: N, aspect: N, near: N) -> Mat { +//pub fn infinite_perspective(fovy: N, aspect: N, near: N) -> TMat4 { // unimplemented!() //} // -//pub fn infinite_perspective_lh(fovy: N, aspect: N, near: N) -> Mat { +//pub fn infinite_perspective_lh(fovy: N, aspect: N, near: N) -> TMat4 { // unimplemented!() //} // -//pub fn infinite_perspective_rh(fovy: N, aspect: N, near: N) -> Mat { +//pub fn infinite_perspective_rh(fovy: N, aspect: N, near: N) -> TMat4 { // unimplemented!() //} // -//pub fn infinite_ortho(left: N, right: N, bottom: N, top: N) -> Mat { +//pub fn infinite_ortho(left: N, right: N, bottom: N, top: N) -> TMat4 { // unimplemented!() //} /// Creates a matrix for an orthographic parallel viewing volume, using the right handedness and OpenGL near and far clip planes definition. -pub fn ortho(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Mat { +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() } -//pub fn ortho_lh(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//pub fn ortho_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { // unimplemented!() //} /// 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(fovy: N, aspect: N, near: N, far: N) -> Mat { +pub fn perspective(fovy: N, aspect: N, near: N, far: N) -> TMat4 { Perspective3::new(fovy, aspect, near, far).unwrap() } -//pub fn perspective_fov(fov: N, width: N, height: N, near: N, far: N) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//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) -> Mat { +//pub fn tweaked_infinite_perspective(fovy: N, aspect: N, near: N) -> TMat4 { // unimplemented!() //} // -//pub fn tweaked_infinite_perspective_ep(fovy: N, aspect: N, near: N, ep: N) -> Mat { +//pub fn tweaked_infinite_perspective_ep(fovy: N, aspect: N, near: N, ep: N) -> TMat4 { // unimplemented!() //} diff --git a/nalgebra-glm/src/ext/matrix_projection.rs b/nalgebra-glm/src/ext/matrix_projection.rs index c791e643..f07e0c45 100644 --- a/nalgebra-glm/src/ext/matrix_projection.rs +++ b/nalgebra-glm/src/ext/matrix_projection.rs @@ -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. /// @@ -8,15 +8,15 @@ use aliases::{Mat, Vec}; /// * `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. // * `viewport`: Rendering viewport -pub fn pick_matrix(center: &Vec, delta: &Vec, viewport: &Vec) -> Mat { - let shift = Vector3::new( +pub fn pick_matrix(center: &TVec2, delta: &TVec2, viewport: &TVec4) -> TMat4 { + let shift = TVec3::new( (viewport.z - (center.x - viewport.x) * na::convert(2.0)) / delta.x, (viewport.w - (center.y - viewport.y) * na::convert(2.0)) / delta.y, N::zero() ); - let result = Matrix4::new_translation(&shift); - result.prepend_nonuniform_scaling(&Vector3::new(viewport.z / delta.x, viewport.w / delta.y, N::one())) + let result = TMat4::new_translation(&shift); + 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. @@ -26,7 +26,7 @@ pub fn pick_matrix(center: &Vec, delta: &Vec, viewport: & /// * `model`: Specifies the current modelview matrix. /// * `proj`: Specifies the current projection matrix. /// * `viewport`: Specifies the current viewport. -pub fn project(obj: &Vec, model: &Mat, proj: &Mat, viewport: Vec) -> Vec { +pub fn project(obj: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { project_no(obj, model, proj, viewport) } @@ -39,9 +39,9 @@ pub fn project(obj: &Vec, model: &Mat, proj: &Mat(obj: &Vec, model: &Mat, proj: &Mat, viewport: Vec) -> Vec { +pub fn project_no(obj: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { 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. @@ -53,11 +53,11 @@ pub fn project_no(obj: &Vec, model: &Mat, proj: &Mat< /// * `model`: Specifies the current modelview matrix. /// * `proj`: Specifies the current projection matrix. /// * `viewport`: Specifies the current viewport. -pub fn project_zo(obj: &Vec, model: &Mat, proj: &Mat, viewport: Vec) -> Vec { - let normalized = proj * model * Vector4::new(obj.x, obj.y, obj.z, N::one()); +pub fn project_zo(obj: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { + let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, N::one()); let scale = N::one() / normalized.w; - Vector3::new( + TVec3::new( 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)), normalized.z * scale, @@ -71,7 +71,7 @@ pub fn project_zo(obj: &Vec, model: &Mat, proj: &Mat< /// * `model`: Specifies the current modelview matrix. /// * `proj`: Specifies the current projection matrix. /// * `viewport`: Specifies the current viewport. -pub fn unproject(win: &Vec, model: &Mat, proj: &Mat, viewport: Vec) -> Vec { +pub fn unproject(win: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { unproject_no(win, model, proj, viewport) } @@ -84,10 +84,10 @@ pub fn unproject(win: &Vec, model: &Mat, proj: &Mat(win: &Vec, model: &Mat, proj: &Mat, viewport: Vec) -> Vec { +pub fn unproject_no(win: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { let _2: N = na::convert(2.0); - let transform = (proj * model).try_inverse().unwrap_or(Matrix4::zeros()); - let pt = Vector4::new( + let transform = (proj * model).try_inverse().unwrap_or(TMat4::zeros()); + let pt = TVec4::new( _2 * (win.x - viewport.x) / viewport.z - N::one(), _2 * (win.y - viewport.y) / viewport.w - N::one(), _2 * win.z - N::one(), @@ -107,10 +107,10 @@ pub fn unproject_no(win: &Vec, model: &Mat, proj: &Ma /// * `model`: Specifies the current modelview matrix. /// * `proj`: Specifies the current projection matrix. /// * `viewport`: Specifies the current viewport. -pub fn unproject_zo(win: &Vec, model: &Mat, proj: &Mat, viewport: Vec) -> Vec { +pub fn unproject_zo(win: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { let _2: N = na::convert(2.0); - let transform = (proj * model).try_inverse().unwrap_or(Matrix4::zeros()); - let pt = Vector4::new( + let transform = (proj * model).try_inverse().unwrap_or(TMat4::zeros()); + let pt = TVec4::new( _2 * (win.x - viewport.x) / viewport.z - N::one(), _2 * (win.y - viewport.y) / viewport.w - N::one(), win.z, diff --git a/nalgebra-glm/src/ext/matrix_transform.rs b/nalgebra-glm/src/ext/matrix_transform.rs index 5a22b6e9..4fa1d83d 100644 --- a/nalgebra-glm/src/ext/matrix_transform.rs +++ b/nalgebra-glm/src/ext/matrix_transform.rs @@ -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 aliases::{Mat, Vec}; +use aliases::{Mat, Vec, TVec3, TMat4}; /// The identity matrix. pub fn identity() -> Mat @@ -15,7 +15,7 @@ pub fn identity() -> Mat /// * `eye` − Position of the camera /// * `center` − Position where the camera is looking at /// * `u` − Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)` -pub fn look_at(eye: &Vec, center: &Vec, up: &Vec) -> Mat { +pub fn look_at(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { look_at_rh(eye, center, up) } @@ -25,7 +25,7 @@ pub fn look_at(eye: &Vec, center: &Vec, up: &Vec) /// * `eye` − Position of the camera /// * `center` − Position where the camera is looking at /// * `u` − Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)` -pub fn look_at_lh(eye: &Vec, center: &Vec, up: &Vec) -> Mat { +pub fn look_at_lh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { Mat::look_at_lh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up) } @@ -35,7 +35,7 @@ pub fn look_at_lh(eye: &Vec, center: &Vec, up: &Vec(eye: &Vec, center: &Vec, up: &Vec) -> Mat { +pub fn look_at_rh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { Mat::look_at_rh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up) } @@ -45,7 +45,7 @@ pub fn look_at_rh(eye: &Vec, center: &Vec, up: &Vec(m: &Mat, angle: N, axis: &Vec) -> Mat { +pub fn rotate(m: &TMat4, angle: N, axis: &TVec3) -> TMat4 { m * Rotation3::from_axis_angle(&Unit::new_normalize(*axis), angle).to_homogeneous() } @@ -54,7 +54,7 @@ pub fn rotate(m: &Mat, angle: N, axis: &Vec) -> Mat(m: &Mat, angle: N) -> Mat { +pub fn rotate_x(m: &TMat4, angle: N) -> TMat4 { rotate(m, angle, &Vec::x()) } @@ -63,7 +63,7 @@ pub fn rotate_x(m: &Mat, angle: N) -> Mat { /// # Parameters /// * m − Input matrix multiplied by this rotation matrix. /// * angle − Rotation angle expressed in radians. -pub fn rotate_y(m: &Mat, angle: N) -> Mat { +pub fn rotate_y(m: &TMat4, angle: N) -> TMat4 { rotate(m, angle, &Vec::y()) } @@ -72,7 +72,7 @@ pub fn rotate_y(m: &Mat, angle: N) -> Mat { /// # Parameters /// * m − Input matrix multiplied by this rotation matrix. /// * angle − Rotation angle expressed in radians. -pub fn rotate_z(m: &Mat, angle: N) -> Mat { +pub fn rotate_z(m: &TMat4, angle: N) -> TMat4 { rotate(m, angle, &Vec::z()) } @@ -81,7 +81,7 @@ pub fn rotate_z(m: &Mat, angle: N) -> Mat { /// # Parameters /// * m − Input matrix multiplied by this scale matrix. /// * v − Ratio of scaling for each axis. -pub fn scale(m: &Mat, v: &Vec) -> Mat { +pub fn scale(m: &TMat4, v: &TVec3) -> TMat4 { m.prepend_nonuniform_scaling(v) } @@ -90,6 +90,6 @@ pub fn scale(m: &Mat, v: &Vec) -> Mat { /// # Parameters /// * m − Input matrix multiplied by this translation matrix. /// * v − Coordinates of a translation vector. -pub fn translate(m: &Mat, v: &Vec) -> Mat { +pub fn translate(m: &TMat4, v: &TVec3) -> TMat4 { m.prepend_translation(v) } diff --git a/nalgebra-glm/src/ext/quaternion_transform.rs b/nalgebra-glm/src/ext/quaternion_transform.rs index 06268fc9..c2fedf36 100644 --- a/nalgebra-glm/src/ext/quaternion_transform.rs +++ b/nalgebra-glm/src/ext/quaternion_transform.rs @@ -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. pub fn quat_exp(q: &Qua) -> Qua { @@ -18,7 +18,7 @@ pub fn quat_pow(q: &Qua, y: N) -> Qua { } /// Builds a quaternion from an axis and an angle, and right-multiply it to the quaternion `q`. -pub fn quat_rotate(q: &Qua, angle: N, axis: &Vec) -> Qua { +pub fn quat_rotate(q: &Qua, angle: N, axis: &TVec3) -> Qua { q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap() } diff --git a/nalgebra-glm/src/ext/quaternion_trigonometric.rs b/nalgebra-glm/src/ext/quaternion_trigonometric.rs index 13f7cf32..ae53eb72 100644 --- a/nalgebra-glm/src/ext/quaternion_trigonometric.rs +++ b/nalgebra-glm/src/ext/quaternion_trigonometric.rs @@ -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. pub fn quat_angle(x: &Qua) -> N { @@ -8,15 +8,15 @@ pub fn quat_angle(x: &Qua) -> N { } /// Creates a quaternion from an axis and an angle. -pub fn quat_angle_axis(angle: N, axis: &Vec) -> Qua { +pub fn quat_angle_axis(angle: N, axis: &TVec3) -> Qua { UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap() } /// The rotation axis of a quaternion assumed to be normalized. -pub fn quat_axis(x: &Qua) -> Vec { +pub fn quat_axis(x: &Qua) -> TVec3 { if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() { a.unwrap() } else { - Vector3::zeros() + TVec3::zeros() } } \ No newline at end of file diff --git a/nalgebra-glm/src/geometric.rs b/nalgebra-glm/src/geometric.rs index 757899ff..c3b7e9fe 100644 --- a/nalgebra-glm/src/geometric.rs +++ b/nalgebra-glm/src/geometric.rs @@ -1,10 +1,10 @@ -use na::{Real, U3, DefaultAllocator}; +use na::{Real, DefaultAllocator}; use traits::{Number, Alloc, Dimension}; -use aliases::Vec; +use aliases::{Vec, TVec3}; /// The cross product of two vectors. -pub fn cross(x: &Vec, y: &Vec) -> Vec { +pub fn cross(x: &TVec3, y: &TVec3) -> TVec3 { x.cross(y) } diff --git a/nalgebra-glm/src/gtc/packing.rs b/nalgebra-glm/src/gtc/packing.rs index e0ab84a0..ea8097e6 100644 --- a/nalgebra-glm/src/gtc/packing.rs +++ b/nalgebra-glm/src/gtc/packing.rs @@ -49,7 +49,7 @@ pub fn packInt4x8(v: &I8Vec4) -> i32 { unimplemented!() } -pub fn packRGBM(rgb: &Vec) -> Vec { +pub fn packRGBM(rgb: &TVec3) -> TVec4 { unimplemented!() } @@ -192,7 +192,7 @@ pub fn unpackInt4x8(p: i32) -> I8Vec4 { unimplemented!() } -pub fn unpackRGBM(rgbm: &Vec) -> Vec { +pub fn unpackRGBM(rgbm: &TVec4) -> TVec3 { unimplemented!() } diff --git a/nalgebra-glm/src/gtc/quaternion.rs b/nalgebra-glm/src/gtc/quaternion.rs index f0b3ec1b..0fe1f62c 100644 --- a/nalgebra-glm/src/gtc/quaternion.rs +++ b/nalgebra-glm/src/gtc/quaternion.rs @@ -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). -pub fn quat_euler_angles(x: &Qua) -> Vec { +pub fn quat_euler_angles(x: &Qua) -> TVec3 { let q = UnitQuaternion::new_unchecked(*x); 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. @@ -31,21 +31,21 @@ pub fn quat_less_than_equal(x: &Qua, y: &Qua) -> Vec { } /// Convert a quaternion to a rotation matrix in homogeneous coordinates. -pub fn quat_cast(x: &Qua) -> Mat { +pub fn quat_cast(x: &Qua) -> TMat4 { ::quat_to_mat4(x) } /// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix). -pub fn quat_look_at(direction: &Vec, up: &Vec) -> Qua { +pub fn quat_look_at(direction: &TVec3, up: &TVec3) -> Qua { quat_look_at_rh(direction, up) } /// Computes a left-handed look-at quaternion (equivalent to a left-handed look-at matrix). -pub fn quat_look_at_lh(direction: &Vec, up: &Vec) -> Qua { +pub fn quat_look_at_lh(direction: &TVec3, up: &TVec3) -> Qua { UnitQuaternion::look_at_lh(direction, up).unwrap() } /// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix). -pub fn quat_look_at_rh(direction: &Vec, up: &Vec) -> Qua { +pub fn quat_look_at_rh(direction: &TVec3, up: &TVec3) -> Qua { UnitQuaternion::look_at_rh(direction, up).unwrap() } diff --git a/nalgebra-glm/src/gtc/type_ptr.rs b/nalgebra-glm/src/gtc/type_ptr.rs index 4cf23f04..b8fe03e8 100644 --- a/nalgebra-glm/src/gtc/type_ptr.rs +++ b/nalgebra-glm/src/gtc/type_ptr.rs @@ -1,76 +1,75 @@ -use na::{Scalar, Real, U1, U2, U3, U4, DefaultAllocator, - Quaternion, Matrix2, Matrix3, Matrix4, Vector1, Vector2, Vector3, Vector4, - Matrix2x3, Matrix2x4, Matrix3x2, Matrix3x4, Matrix4x2, Matrix4x3}; +use na::{Scalar, Real, DefaultAllocator, Quaternion}; 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. -pub fn make_mat2(ptr: &[N]) -> Mat { - Matrix2::from_column_slice(ptr) +pub fn make_mat2(ptr: &[N]) -> TMat2 { + TMat2::from_column_slice(ptr) } /// Creates a 2x2 matrix from a slice arranged in column-major order. -pub fn make_mat2x2(ptr: &[N]) -> Mat { - Matrix2::from_column_slice(ptr) +pub fn make_mat2x2(ptr: &[N]) -> TMat2 { + TMat2::from_column_slice(ptr) } /// Creates a 2x3 matrix from a slice arranged in column-major order. -pub fn make_mat2x3(ptr: &[N]) -> Mat { - Matrix2x3::from_column_slice(ptr) +pub fn make_mat2x3(ptr: &[N]) -> TMat2x3 { + TMat2x3::from_column_slice(ptr) } /// Creates a 2x4 matrix from a slice arranged in column-major order. -pub fn make_mat2x4(ptr: &[N]) -> Mat { - Matrix2x4::from_column_slice(ptr) +pub fn make_mat2x4(ptr: &[N]) -> TMat2x4 { + TMat2x4::from_column_slice(ptr) } /// Creates a 3 matrix from a slice arranged in column-major order. -pub fn make_mat3(ptr: &[N]) -> Mat { - Matrix3::from_column_slice(ptr) +pub fn make_mat3(ptr: &[N]) -> TMat3 { + TMat3::from_column_slice(ptr) } /// Creates a 3x2 matrix from a slice arranged in column-major order. -pub fn make_mat3x2(ptr: &[N]) -> Mat { - Matrix3x2::from_column_slice(ptr) +pub fn make_mat3x2(ptr: &[N]) -> TMat3x2 { + TMat3x2::from_column_slice(ptr) } /// Creates a 3x3 matrix from a slice arranged in column-major order. -pub fn make_mat3x3(ptr: &[N]) -> Mat { - Matrix3::from_column_slice(ptr) +pub fn make_mat3x3(ptr: &[N]) -> TMat3 { + TMat3::from_column_slice(ptr) } /// Creates a 3x4 matrix from a slice arranged in column-major order. -pub fn make_mat3x4(ptr: &[N]) -> Mat { - Matrix3x4::from_column_slice(ptr) +pub fn make_mat3x4(ptr: &[N]) -> TMat3x4 { + TMat3x4::from_column_slice(ptr) } /// Creates a 4x4 matrix from a slice arranged in column-major order. -pub fn make_mat4(ptr: &[N]) -> Mat { - Matrix4::from_column_slice(ptr) +pub fn make_mat4(ptr: &[N]) -> TMat4 { + TMat4::from_column_slice(ptr) } /// Creates a 4x2 matrix from a slice arranged in column-major order. -pub fn make_mat4x2(ptr: &[N]) -> Mat { - Matrix4x2::from_column_slice(ptr) +pub fn make_mat4x2(ptr: &[N]) -> TMat4x2 { + TMat4x2::from_column_slice(ptr) } /// Creates a 4x3 matrix from a slice arranged in column-major order. -pub fn make_mat4x3(ptr: &[N]) -> Mat { - Matrix4x3::from_column_slice(ptr) +pub fn make_mat4x3(ptr: &[N]) -> TMat4x3 { + TMat4x3::from_column_slice(ptr) } /// Creates a 4x4 matrix from a slice arranged in column-major order. -pub fn make_mat4x4(ptr: &[N]) -> Mat { - Matrix4::from_column_slice(ptr) +pub fn make_mat4x4(ptr: &[N]) -> TMat4 { + TMat4::from_column_slice(ptr) } /// Converts a 2x2 matrix to a 3x3 matrix. -pub fn mat2_to_mat3(m: &Mat) -> Mat { +pub fn mat2_to_mat3(m: &TMat2) -> TMat3 { let _0 = N::zero(); let _1 = N::one(); - Matrix3::new( + TMat3::new( m.m11, m.m12, _0, m.m21, m.m22, _0, _0, _0, _1 @@ -78,19 +77,19 @@ pub fn mat2_to_mat3(m: &Mat) -> Mat { } /// Converts a 3x3 matrix to a 2x2 matrix. -pub fn mat3_to_mat2(m: &Mat) -> Mat { - Matrix2::new( +pub fn mat3_to_mat2(m: &TMat3) -> TMat2 { + TMat2::new( m.m11, m.m12, m.m21, m.m22 ) } /// Converts a 3x3 matrix to a 4x4 matrix. -pub fn mat3_to_mat4(m: &Mat) -> Mat { +pub fn mat3_to_mat4(m: &TMat3) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); - Matrix4::new( + TMat4::new( m.m11, m.m12, m.m13, _0, m.m21, m.m22, m.m23, _0, m.m31, m.m32, m.m33, _0, @@ -99,8 +98,8 @@ pub fn mat3_to_mat4(m: &Mat) -> Mat { } /// Converts a 4x4 matrix to a 3x3 matrix. -pub fn mat4_to_mat3(m: &Mat) -> Mat { - Matrix3::new( +pub fn mat4_to_mat3(m: &TMat4) -> TMat3 { + TMat3::new( m.m11, m.m12, m.m13, m.m21, m.m22, m.m23, m.m31, m.m32, m.m33, @@ -108,11 +107,11 @@ pub fn mat4_to_mat3(m: &Mat) -> Mat { } /// Converts a 2x2 matrix to a 4x4 matrix. -pub fn mat2_to_mat4(m: &Mat) -> Mat { +pub fn mat2_to_mat4(m: &TMat2) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); - Matrix4::new( + TMat4::new( m.m11, m.m12, _0, _0, m.m21, m.m22, _0, _0, _0, _0, _1, _0, @@ -121,8 +120,8 @@ pub fn mat2_to_mat4(m: &Mat) -> Mat { } /// Converts a 4x4 matrix to a 2x2 matrix. -pub fn mat4_to_mat2(m: &Mat) -> Mat { - Matrix2::new( +pub fn mat4_to_mat2(m: &TMat4) -> TMat2 { + TMat2::new( m.m11, m.m12, m.m21, m.m22, ) @@ -130,114 +129,114 @@ pub fn mat4_to_mat2(m: &Mat) -> Mat { /// Creates a quaternion from a slice arranged as `[x, y, z, w]`. pub fn make_quat(ptr: &[N]) -> Qua { - Quaternion::from_vector(Vector4::from_column_slice(ptr)) + Quaternion::from_vector(TVec4::from_column_slice(ptr)) } /// Creates a 1D vector from a slice. -pub fn make_vec1(v: &Vec) -> Vec { +pub fn make_vec1(v: &TVec1) -> TVec1 { *v } /// Creates a 1D vector from another vector. -pub fn vec2_to_vec1(v: &Vec) -> Vec { - Vector1::new(v.x) +pub fn vec2_to_vec1(v: &TVec2) -> TVec1 { + TVec1::new(v.x) } /// Creates a 1D vector from another vector. -pub fn vec3_to_vec1(v: &Vec) -> Vec { - Vector1::new(v.x) +pub fn vec3_to_vec1(v: &TVec3) -> TVec1 { + TVec1::new(v.x) } /// Creates a 1D vector from another vector. -pub fn vec4_to_vec1(v: &Vec) -> Vec { - Vector1::new(v.x) +pub fn vec4_to_vec1(v: &TVec4) -> TVec1 { + TVec1::new(v.x) } /// Creates a 2D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn vec1_to_vec2(v: &Vec) -> Vec { - Vector2::new(v.x, N::zero()) +pub fn vec1_to_vec2(v: &TVec1) -> TVec2 { + TVec2::new(v.x, N::zero()) } /// Creates a 2D vector from another vector. -pub fn vec2_to_vec2(v: &Vec) -> Vec { +pub fn vec2_to_vec2(v: &TVec2) -> TVec2 { *v } /// Creates a 2D vector from another vector. -pub fn vec3_to_vec2(v: &Vec) -> Vec { - Vector2::new(v.x, v.y) +pub fn vec3_to_vec2(v: &TVec3) -> TVec2 { + TVec2::new(v.x, v.y) } /// Creates a 2D vector from another vector. -pub fn vec4_to_vec2(v: &Vec) -> Vec { - Vector2::new(v.x, v.y) +pub fn vec4_to_vec2(v: &TVec4) -> TVec2 { + TVec2::new(v.x, v.y) } /// Creates a 2D vector from a slice. -pub fn make_vec2(ptr: &[N]) -> Vec { - Vector2::from_column_slice(ptr) +pub fn make_vec2(ptr: &[N]) -> TVec2 { + TVec2::from_column_slice(ptr) } /// Creates a 3D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn vec1_to_vec3(v: &Vec) -> Vec { - Vector3::new(v.x, N::zero(), N::zero()) +pub fn vec1_to_vec3(v: &TVec1) -> TVec3 { + TVec3::new(v.x, N::zero(), N::zero()) } /// Creates a 3D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn vec2_to_vec3(v: &Vec) -> Vec { - Vector3::new(v.x, v.y, N::zero()) +pub fn vec2_to_vec3(v: &TVec2) -> TVec3 { + TVec3::new(v.x, v.y, N::zero()) } /// Creates a 3D vector from another vector. -pub fn vec3_to_vec3(v: &Vec) -> Vec { +pub fn vec3_to_vec3(v: &TVec3) -> TVec3 { *v } /// Creates a 3D vector from another vector. -pub fn vec4_to_vec3(v: &Vec) -> Vec { - Vector3::new(v.x, v.y, v.z) +pub fn vec4_to_vec3(v: &TVec4) -> TVec3 { + TVec3::new(v.x, v.y, v.z) } /// Creates a 3D vector from another vector. -pub fn make_vec3(ptr: &[N]) -> Vec { - Vector3::from_column_slice(ptr) +pub fn make_vec3(ptr: &[N]) -> TVec3 { + TVec3::from_column_slice(ptr) } /// Creates a 4D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn vec1_to_vec4(v: &Vec) -> Vec { - Vector4::new(v.x, N::zero(), N::zero(), N::zero()) +pub fn vec1_to_vec4(v: &TVec1) -> TVec4 { + TVec4::new(v.x, N::zero(), N::zero(), N::zero()) } /// Creates a 4D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn vec2_to_vec4(v: &Vec) -> Vec { - Vector4::new(v.x, v.y, N::zero(), N::zero()) +pub fn vec2_to_vec4(v: &TVec2) -> TVec4 { + TVec4::new(v.x, v.y, N::zero(), N::zero()) } /// Creates a 4D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn vec3_to_vec4(v: &Vec) -> Vec { - Vector4::new(v.x, v.y, v.z, N::zero()) +pub fn vec3_to_vec4(v: &TVec3) -> TVec4 { + TVec4::new(v.x, v.y, v.z, N::zero()) } /// Creates a 4D vector from another vector. -pub fn vec4_to_vec4(v: &Vec) -> Vec { +pub fn vec4_to_vec4(v: &TVec4) -> TVec4 { *v } /// Creates a 4D vector from another vector. -pub fn make_vec4(ptr: &[N]) -> Vec { - Vector4::from_column_slice(ptr) +pub fn make_vec4(ptr: &[N]) -> TVec4 { + TVec4::from_column_slice(ptr) } /// Converts a matrix or vector to a slice arranged in column-major order. diff --git a/nalgebra-glm/src/gtc/ulp.rs b/nalgebra-glm/src/gtc/ulp.rs index 1b611951..179b5eb4 100644 --- a/nalgebra-glm/src/gtc/ulp.rs +++ b/nalgebra-glm/src/gtc/ulp.rs @@ -7,7 +7,7 @@ pub fn float_distance(x: T, y: T) -> u64 { unimplemented!() } -pub fn float_distance2(x: &Vec, y: &Vec) -> Vec { +pub fn float_distance2(x: &TVec2, y: &TVec2) -> Vec { unimplemented!() } diff --git a/nalgebra-glm/src/gtx/euler_angles.rs b/nalgebra-glm/src/gtx/euler_angles.rs index cd1e0a48..f2b779e3 100644 --- a/nalgebra-glm/src/gtx/euler_angles.rs +++ b/nalgebra-glm/src/gtx/euler_angles.rs @@ -2,162 +2,162 @@ use na::{Real, U3, U4}; use aliases::{Vec, Mat}; -pub fn derivedEulerAngleX(angleX: N, angularVelocityX: N) -> Mat { +pub fn derivedEulerAngleX(angleX: N, angularVelocityX: N) -> TMat4 { unimplemented!() } -pub fn derivedEulerAngleY(angleY: N, angularVelocityY: N) -> Mat { +pub fn derivedEulerAngleY(angleY: N, angularVelocityY: N) -> TMat4 { unimplemented!() } -pub fn derivedEulerAngleZ(angleZ: N, angularVelocityZ: N) -> Mat { +pub fn derivedEulerAngleZ(angleZ: N, angularVelocityZ: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleX(angleX: N) -> Mat { +pub fn eulerAngleX(angleX: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleXY(angleX: N, angleY: N) -> Mat { +pub fn eulerAngleXY(angleX: N, angleY: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleXYX(t1: N, t2: N, t3: N) -> Mat { +pub fn eulerAngleXYX(t1: N, t2: N, t3: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleXYZ(t1: N, t2: N, t3: N) -> Mat { +pub fn eulerAngleXYZ(t1: N, t2: N, t3: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleXZ(angleX: N, angleZ: N) -> Mat { +pub fn eulerAngleXZ(angleX: N, angleZ: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleXZX(t1: N, t2: N, t3: N) -> Mat { +pub fn eulerAngleXZX(t1: N, t2: N, t3: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleXZY(t1: N, t2: N, t3: N) -> Mat { +pub fn eulerAngleXZY(t1: N, t2: N, t3: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleY(angleY: N) -> Mat { +pub fn eulerAngleY(angleY: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleYX(angleY: N, angleX: N) -> Mat { +pub fn eulerAngleYX(angleY: N, angleX: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleYXY(t1: N, t2: N, t3: N) -> Mat { +pub fn eulerAngleYXY(t1: N, t2: N, t3: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleYXZ(yaw: N, pitch: N, roll: N) -> Mat { +pub fn eulerAngleYXZ(yaw: N, pitch: N, roll: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleYZ(angleY: N, angleZ: N) -> Mat { +pub fn eulerAngleYZ(angleY: N, angleZ: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleYZX(t1: N, t2: N, t3: N) -> Mat { +pub fn eulerAngleYZX(t1: N, t2: N, t3: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleYZY(t1: N, t2: N, t3: N) -> Mat { +pub fn eulerAngleYZY(t1: N, t2: N, t3: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleZ(angleZ: N) -> Mat { +pub fn eulerAngleZ(angleZ: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleZX(angle: N, angleX: N) -> Mat { +pub fn eulerAngleZX(angle: N, angleX: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleZXY(t1: N, t2: N, t3: N) -> Mat { +pub fn eulerAngleZXY(t1: N, t2: N, t3: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleZXZ(t1: N, t2: N, t3: N) -> Mat { +pub fn eulerAngleZXZ(t1: N, t2: N, t3: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleZY(angleZ: N, angleY: N) -> Mat { +pub fn eulerAngleZY(angleZ: N, angleY: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleZYX(t1: N, t2: N, t3: N) -> Mat { +pub fn eulerAngleZYX(t1: N, t2: N, t3: N) -> TMat4 { unimplemented!() } -pub fn eulerAngleZYZ(t1: N, t2: N, t3: N) -> Mat { +pub fn eulerAngleZYZ(t1: N, t2: N, t3: N) -> TMat4 { unimplemented!() } -pub fn extractEulerAngleXYX(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleXYX(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn extractEulerAngleXYZ(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleXYZ(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn extractEulerAngleXZX(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleXZX(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn extractEulerAngleXZY(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleXZY(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn extractEulerAngleYXY(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleYXY(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn extractEulerAngleYXZ(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleYXZ(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn extractEulerAngleYZX(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleYZX(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn extractEulerAngleYZY(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleYZY(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn extractEulerAngleZXY(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleZXY(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn extractEulerAngleZXZ(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleZXZ(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn extractEulerAngleZYX(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleZYX(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn extractEulerAngleZYZ(M: &Mat) -> (N, N, N) { +pub fn extractEulerAngleZYZ(M: &TMat4) -> (N, N, N) { unimplemented!() } -pub fn orientate2(angle: N) -> Mat { +pub fn orientate2(angle: N) -> TMat3x3 { unimplemented!() } -pub fn orientate3(angles: Vec) -> Mat { +pub fn orientate3(angles: TVec3) -> TMat3x3 { unimplemented!() } -pub fn orientate4(angles: Vec) -> Mat { +pub fn orientate4(angles: TVec3) -> TMat4 { unimplemented!() } -pub fn yawPitchRoll(yaw: N, pitch: N, roll: N) -> Mat { +pub fn yawPitchRoll(yaw: N, pitch: N, roll: N) -> TMat4 { unimplemented!() } diff --git a/nalgebra-glm/src/gtx/exterior_product.rs b/nalgebra-glm/src/gtx/exterior_product.rs index 07986d4e..228be61e 100644 --- a/nalgebra-glm/src/gtx/exterior_product.rs +++ b/nalgebra-glm/src/gtx/exterior_product.rs @@ -1,9 +1,7 @@ -use na::U2; - use traits::Number; -use aliases::Vec; +use aliases::TVec2; /// The 2D perpendicular product between two vectors. -pub fn cross2d(v: &Vec, u: &Vec) -> N { +pub fn cross2d(v: &TVec2, u: &TVec2) -> N { v.perp(u) } \ No newline at end of file diff --git a/nalgebra-glm/src/gtx/handed_coordinate_space.rs b/nalgebra-glm/src/gtx/handed_coordinate_space.rs index 1a68fcf3..9b0e1c9e 100644 --- a/nalgebra-glm/src/gtx/handed_coordinate_space.rs +++ b/nalgebra-glm/src/gtx/handed_coordinate_space.rs @@ -1,14 +1,12 @@ -use na::U3; - use traits::Number; -use aliases::Vec; +use aliases::TVec3; /// Returns `true` if `{a, b, c}` forms a left-handed trihedron. -pub fn left_handed(a: &Vec, b: &Vec, c: &Vec) -> bool { +pub fn left_handed(a: &TVec3, b: &TVec3, c: &TVec3) -> bool { a.cross(b).dot(c) < N::zero() } /// Returns `true` if `{a, b, c}` forms a right-handed trihedron. -pub fn right_handed(a: &Vec, b: &Vec, c: &Vec) -> bool { +pub fn right_handed(a: &TVec3, b: &TVec3, c: &TVec3) -> bool { a.cross(b).dot(c) > N::zero() } diff --git a/nalgebra-glm/src/gtx/matrix_cross_product.rs b/nalgebra-glm/src/gtx/matrix_cross_product.rs index 5a41fdd0..de01bcc9 100644 --- a/nalgebra-glm/src/gtx/matrix_cross_product.rs +++ b/nalgebra-glm/src/gtx/matrix_cross_product.rs @@ -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)`. -pub fn matrix_cross3(x: &Vec) -> Mat { +pub fn matrix_cross3(x: &TVec3) -> TMat3 { x.cross_matrix() } /// Builds a 4x4 matrix `m` such that for any `v`: `m * v == cross(x, v)`. -pub fn matrix_cross(x: &Vec) -> Mat { +pub fn matrix_cross(x: &TVec3) -> TMat4 { let m = x.cross_matrix(); // FIXME: use a dedicated constructor from Matrix3 to Matrix4. - Matrix4::new( + TMat4::new( m.m11, m.m12, m.m13, N::zero(), m.m21, m.m22, m.m23, N::zero(), m.m31, m.m32, m.m33, N::zero(), diff --git a/nalgebra-glm/src/gtx/matrix_operation.rs b/nalgebra-glm/src/gtx/matrix_operation.rs index b915808f..bf05cbb9 100644 --- a/nalgebra-glm/src/gtx/matrix_operation.rs +++ b/nalgebra-glm/src/gtx/matrix_operation.rs @@ -1,50 +1,47 @@ -use na::{Matrix2, Matrix2x3, Matrix2x4, Matrix3, Matrix3x2, Matrix3x4, Matrix4, Matrix4x2, Matrix4x3, - U2, U3, U4}; - 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. -pub fn diagonal2x2(v: &Vec) -> Mat { - Matrix2::from_diagonal(v) +pub fn diagonal2x2(v: &TVec2) -> TMat2 { + TMat2::from_diagonal(v) } /// Builds a 2x3 diagonal matrix. -pub fn diagonal2x3(v: &Vec) -> Mat { - Matrix2x3::from_partial_diagonal(v.as_slice()) +pub fn diagonal2x3(v: &TVec2) -> TMat2x3 { + TMat2x3::from_partial_diagonal(v.as_slice()) } /// Builds a 2x4 diagonal matrix. -pub fn diagonal2x4(v: &Vec) -> Mat { - Matrix2x4::from_partial_diagonal(v.as_slice()) +pub fn diagonal2x4(v: &TVec2) -> TMat2x4 { + TMat2x4::from_partial_diagonal(v.as_slice()) } /// Builds a 3x2 diagonal matrix. -pub fn diagonal3x2(v: &Vec) -> Mat { - Matrix3x2::from_partial_diagonal(v.as_slice()) +pub fn diagonal3x2(v: &TVec3) -> TMat3x2 { + TMat3x2::from_partial_diagonal(v.as_slice()) } /// Builds a 3x3 diagonal matrix. -pub fn diagonal3x3(v: &Vec) -> Mat { - Matrix3::from_diagonal(v) +pub fn diagonal3x3(v: &TVec3) -> TMat3 { + TMat3::from_diagonal(v) } /// Builds a 3x4 diagonal matrix. -pub fn diagonal3x4(v: &Vec) -> Mat { - Matrix3x4::from_partial_diagonal(v.as_slice()) +pub fn diagonal3x4(v: &TVec3) -> TMat3x4 { + TMat3x4::from_partial_diagonal(v.as_slice()) } /// Builds a 4x2 diagonal matrix. -pub fn diagonal4x2(v: &Vec) -> Mat { - Matrix4x2::from_partial_diagonal(v.as_slice()) +pub fn diagonal4x2(v: &TVec4) -> TMat4x2 { + TMat4x2::from_partial_diagonal(v.as_slice()) } /// Builds a 4x3 diagonal matrix. -pub fn diagonal4x3(v: &Vec) -> Mat { - Matrix4x3::from_partial_diagonal(v.as_slice()) +pub fn diagonal4x3(v: &TVec4) -> TMat4x3 { + TMat4x3::from_partial_diagonal(v.as_slice()) } /// Builds a 4x4 diagonal matrix. -pub fn diagonal4x4(v: &Vec) -> Mat { - Matrix4::from_diagonal(v) +pub fn diagonal4x4(v: &TVec4) -> TMat4 { + TMat4::from_diagonal(v) } diff --git a/nalgebra-glm/src/gtx/normal.rs b/nalgebra-glm/src/gtx/normal.rs index 01418490..6ae70ab7 100644 --- a/nalgebra-glm/src/gtx/normal.rs +++ b/nalgebra-glm/src/gtx/normal.rs @@ -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 is computed as the normalized vector `cross(p2 - p1, p3 - p1)`. -pub fn triangle_normal(p1: &Vec, p2: &Vec, p3: &Vec) -> Vec { +pub fn triangle_normal(p1: &TVec3, p2: &TVec3, p3: &TVec3) -> TVec3 { (p2 - p1).cross(&(p3 - p1)).normalize() } \ No newline at end of file diff --git a/nalgebra-glm/src/gtx/quaternion.rs b/nalgebra-glm/src/gtx/quaternion.rs index 696c218c..290c7150 100644 --- a/nalgebra-glm/src/gtx/quaternion.rs +++ b/nalgebra-glm/src/gtx/quaternion.rs @@ -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. -pub fn quat_cross_vec(q: &Qua, v: &Vec) -> Vec { +pub fn quat_cross_vec(q: &Qua, v: &TVec3) -> TVec3 { UnitQuaternion::new_unchecked(*q) * v } /// Rotate the vector `v` by the inverse of the quaternion `q` assumed to be normalized. -pub fn quat_inv_cross_vec(v: &Vec, q: &Qua) -> Vec { +pub fn quat_inv_cross_vec(v: &TVec3, q: &Qua) -> TVec3 { UnitQuaternion::new_unchecked(*q).inverse() * v } @@ -42,19 +42,19 @@ pub fn quat_identity() -> Qua { } /// Rotates a vector by a quaternion assumed to be normalized. -pub fn quat_rotate_vec3(q: &Qua, v: &Vec) -> Vec { +pub fn quat_rotate_vec3(q: &Qua, v: &TVec3) -> TVec3 { UnitQuaternion::new_unchecked(*q) * v } /// Rotates a vector in homogeneous coordinates by a quaternion assumed to be normalized. -pub fn quat_rotate_vec(q: &Qua, v: &Vec) -> Vec { +pub fn quat_rotate_vec(q: &Qua, v: &TVec4) -> TVec4 { // UnitQuaternion::new_unchecked(*q) * v let rotated = Unit::new_unchecked(*q) * v.fixed_rows::(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`. -pub fn quat_rotation(orig: &Vec, dest: &Vec) -> Qua { +pub fn quat_rotation(orig: &TVec3, dest: &TVec3) -> Qua { UnitQuaternion::rotation_between(orig, dest).unwrap_or(UnitQuaternion::identity()).unwrap() } @@ -68,23 +68,23 @@ pub fn quat_short_mix(x: &Qua, y: &Qua, a: N) -> Qua { //} /// Converts a quaternion to a rotation matrix. -pub fn quat_to_mat3(x: &Qua) -> Mat { +pub fn quat_to_mat3(x: &Qua) -> TMat3 { UnitQuaternion::new_unchecked(*x).to_rotation_matrix().unwrap() } /// Converts a quaternion to a rotation matrix in homogenous coordinates. -pub fn quat_to_mat4(x: &Qua) -> Mat { +pub fn quat_to_mat4(x: &Qua) -> TMat4 { UnitQuaternion::new_unchecked(*x).to_homogeneous() } /// Converts a rotation matrix to a quaternion. -pub fn mat3_to_quat(x: &Mat) -> Qua { +pub fn mat3_to_quat(x: &TMat3) -> Qua { let r = Rotation3::from_matrix_unchecked(*x); UnitQuaternion::from_rotation_matrix(&r).unwrap() } /// Converts a rotation matrix in homogeneous coordinates to a quaternion. -pub fn to_quat(x: &Mat) -> Qua { +pub fn to_quat(x: &TMat4) -> Qua { let rot = x.fixed_slice::(0, 0).into_owned(); mat3_to_quat(&rot) } diff --git a/nalgebra-glm/src/gtx/rotate_normalized_axis.rs b/nalgebra-glm/src/gtx/rotate_normalized_axis.rs index 8346c801..0a8d63fa 100644 --- a/nalgebra-glm/src/gtx/rotate_normalized_axis.rs +++ b/nalgebra-glm/src/gtx/rotate_normalized_axis.rs @@ -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. /// @@ -8,7 +8,7 @@ use aliases::{Vec, Mat, Qua}; /// * `m` - Input matrix multiplied by this rotation matrix. /// * `angle` - Rotation angle expressed in radians. /// * `axis` - Rotation axis, must be normalized. -pub fn rotate_normalized_axis(m: &Mat, angle: N, axis: &Vec) -> Mat { +pub fn rotate_normalized_axis(m: &TMat4, angle: N, axis: &TVec3) -> TMat4 { m * Rotation3::from_axis_angle(&Unit::new_unchecked(*axis), angle).to_homogeneous() } @@ -18,6 +18,6 @@ pub fn rotate_normalized_axis(m: &Mat, angle: N, axis: &Vec< /// * `q` - Source orientation /// * `angle` - Angle expressed in radians. /// * `axis` - Normalized axis of the rotation, must be normalized. -pub fn quat_rotate_normalized_axis(q: &Qua, angle: N, axis: &Vec) -> Qua { +pub fn quat_rotate_normalized_axis(q: &Qua, angle: N, axis: &TVec3) -> Qua { q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).unwrap() } \ No newline at end of file diff --git a/nalgebra-glm/src/gtx/rotate_vector.rs b/nalgebra-glm/src/gtx/rotate_vector.rs index 39c92abc..0e248fcf 100644 --- a/nalgebra-glm/src/gtx/rotate_vector.rs +++ b/nalgebra-glm/src/gtx/rotate_vector.rs @@ -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`. -pub fn orientation(normal: &Vec, up: &Vec) -> Mat { +pub fn orientation(normal: &TVec3, up: &TVec3) -> TMat4 { if let Some(r) = Rotation3::rotation_between(normal, up) { r.to_homogeneous() } else { - Mat::::identity() + TMat4::identity() } } /// Rotate a two dimensional vector. -pub fn rotate_vec2(v: &Vec, angle: N) -> Vec { +pub fn rotate_vec2(v: &TVec2, angle: N) -> TVec2 { UnitComplex::new(angle) * v } /// Rotate a three dimensional vector around an axis. -pub fn rotate_vec3(v: &Vec, angle: N, normal: &Vec) -> Vec { +pub fn rotate_vec3(v: &TVec3, angle: N, normal: &TVec3) -> TVec3 { Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle) * v } /// Rotate a thee dimensional vector in homogeneous coordinates around an axis. -pub fn rotate_vec4(v: &Vec, angle: N, normal: &Vec) -> Vec { +pub fn rotate_vec4(v: &TVec4, angle: N, normal: &TVec3) -> TVec4 { Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle).to_homogeneous() * v } /// Rotate a three dimensional vector around the `X` axis. -pub fn rotate_x_vec3(v: &Vec, angle: N) -> Vec { - Rotation3::from_axis_angle(&Vector3::x_axis(), angle) * v +pub fn rotate_x_vec3(v: &TVec3, angle: N) -> TVec3 { + Rotation3::from_axis_angle(&TVec3::x_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `X` axis. -pub fn rotate_x_vec4(v: &Vec, angle: N) -> Vec { - Rotation3::from_axis_angle(&Vector3::x_axis(), angle).to_homogeneous() * v +pub fn rotate_x_vec4(v: &TVec4, angle: N) -> TVec4 { + Rotation3::from_axis_angle(&TVec3::x_axis(), angle).to_homogeneous() * v } /// Rotate a three dimensional vector around the `Y` axis. -pub fn rotate_y_vec3(v: &Vec, angle: N) -> Vec { - Rotation3::from_axis_angle(&Vector3::y_axis(), angle) * v +pub fn rotate_y_vec3(v: &TVec3, angle: N) -> TVec3 { + Rotation3::from_axis_angle(&TVec3::y_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `Y` axis. -pub fn rotate_y_vec4(v: &Vec, angle: N) -> Vec { - Rotation3::from_axis_angle(&Vector3::y_axis(), angle).to_homogeneous() * v +pub fn rotate_y_vec4(v: &TVec4, angle: N) -> TVec4 { + Rotation3::from_axis_angle(&TVec3::y_axis(), angle).to_homogeneous() * v } /// Rotate a three dimensional vector around the `Z` axis. -pub fn rotate_z_vec3(v: &Vec, angle: N) -> Vec { - Rotation3::from_axis_angle(&Vector3::z_axis(), angle) * v +pub fn rotate_z_vec3(v: &TVec3, angle: N) -> TVec3 { + Rotation3::from_axis_angle(&TVec3::z_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `Z` axis. -pub fn rotate_z_vec4(v: &Vec, angle: N) -> Vec { - Rotation3::from_axis_angle(&Vector3::z_axis(), angle).to_homogeneous() * v +pub fn rotate_z_vec4(v: &TVec4, angle: N) -> TVec4 { + 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. -pub fn slerp(x: &Vec, y: &Vec, a: N) -> Vec { +pub fn slerp(x: &TVec3, y: &TVec3, a: N) -> TVec3 { Unit::new_unchecked(*x).slerp(&Unit::new_unchecked(*y), a).unwrap() } diff --git a/nalgebra-glm/src/gtx/transform.rs b/nalgebra-glm/src/gtx/transform.rs index 25af5f1d..0299dfe6 100644 --- a/nalgebra-glm/src/gtx/transform.rs +++ b/nalgebra-glm/src/gtx/transform.rs @@ -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 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. -pub fn rotation(angle: N, v: &Vec) -> Mat { +pub fn rotation(angle: N, v: &TVec3) -> TMat4 { Rotation3::from_axis_angle(&Unit::new_normalize(*v), angle).to_homogeneous() } /// A 4 * 4 scale matrix created from a vector of 3 components. -pub fn scaling(v: &Vec) -> Mat { - Matrix4::new_nonuniform_scaling(v) +pub fn scaling(v: &TVec3) -> TMat4 { + TMat4::new_nonuniform_scaling(v) } /// A 4 * 4 translation matrix created from the scaling factor on each axis. -pub fn translation(v: &Vec) -> Mat { - Matrix4::new_translation(v) +pub fn translation(v: &TVec3) -> TMat4 { + TMat4::new_translation(v) } /// A rotation 3 * 3 matrix created from an angle expressed in radians. -pub fn rotation2d(angle: N) -> Mat { +pub fn rotation2d(angle: N) -> TMat3 { Rotation2::new(angle).to_homogeneous() } /// A 3 * 3 scale matrix created from a vector of 2 components. -pub fn scaling2d(v: &Vec) -> Mat { - Matrix3::new_nonuniform_scaling(v) +pub fn scaling2d(v: &TVec2) -> TMat3 { + TMat3::new_nonuniform_scaling(v) } /// A 3 * 3 translation matrix created from the scaling factor on each axis. -pub fn translation2d(v: &Vec) -> Mat { - Matrix3::new_translation(v) +pub fn translation2d(v: &TVec2) -> TMat3 { + TMat3::new_translation(v) } diff --git a/nalgebra-glm/src/gtx/transform2.rs b/nalgebra-glm/src/gtx/transform2.rs index e4982030..0bb19e95 100644 --- a/nalgebra-glm/src/gtx/transform2.rs +++ b/nalgebra-glm/src/gtx/transform2.rs @@ -1,11 +1,11 @@ -use na::{U2, U3, U4, Matrix3, Matrix4}; +use na::{U2, U3}; 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`. -pub fn proj2d(m: &Mat, normal: &Vec) -> Mat { - let mut res = Matrix3::identity(); +pub fn proj2d(m: &TMat3, normal: &TVec2) -> TMat3 { + let mut res = TMat3::identity(); { let mut part = res.fixed_slice_mut::(0, 0); @@ -16,8 +16,8 @@ pub fn proj2d(m: &Mat, normal: &Vec) -> Mat(m: &Mat, normal: &Vec) -> Mat { - let mut res = Matrix4::identity(); +pub fn proj(m: &TMat4, normal: &TVec3) -> TMat4 { + let mut res = TMat4::identity(); { let mut part = res.fixed_slice_mut::(0, 0); @@ -28,8 +28,8 @@ pub fn proj(m: &Mat, normal: &Vec) -> Mat(m: &Mat, normal: &Vec) -> Mat { - let mut res = Matrix3::identity(); +pub fn reflect2d(m: &TMat3, normal: &TVec2) -> TMat3 { + let mut res = TMat3::identity(); { let mut part = res.fixed_slice_mut::(0, 0); @@ -40,8 +40,8 @@ pub fn reflect2d(m: &Mat, normal: &Vec) -> Mat(m: &Mat, normal: &Vec) -> Mat { - let mut res = Matrix4::identity(); +pub fn reflect(m: &TMat4, normal: &TVec3) -> TMat4 { + let mut res = TMat4::identity(); { let mut part = res.fixed_slice_mut::(0, 0); @@ -52,11 +52,11 @@ pub fn reflect(m: &Mat, normal: &Vec) -> Mat(scale: N, bias: N) -> Mat { +pub fn scale_bias_matrix(scale: N, bias: N) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); - Matrix4::new( + TMat4::new( scale, _0, _0, bias, _0, scale, _0, bias, _0, _0, scale, bias, @@ -65,16 +65,16 @@ pub fn scale_bias_matrix(scale: N, bias: N) -> Mat { } /// Builds a scale-bias matrix, and right-multiply it to `m`. -pub fn scale_bias(m: &Mat, scale: N, bias: N) -> Mat { +pub fn scale_bias(m: &TMat4, scale: N, bias: N) -> TMat4 { m * scale_bias_matrix(scale, bias) } /// Transforms a matrix with a shearing on X axis. -pub fn shear2d_x(m: &Mat, y: N) -> Mat { +pub fn shear2d_x(m: &TMat3, y: N) -> TMat3 { let _0 = N::zero(); let _1 = N::one(); - let shear = Matrix3::new( + let shear = TMat3::new( _1, y, _0, _0, _1, _0, _0, _0, _1 @@ -83,10 +83,10 @@ pub fn shear2d_x(m: &Mat, y: N) -> Mat { } /// Transforms a matrix with a shearing on Y axis. -pub fn shear_x(m: &Mat, y: N, z: N) -> Mat { +pub fn shear_x(m: &TMat4, y: N, z: N) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); - let shear = Matrix4::new( + let shear = TMat4::new( _1, _0, _0, _0, y, _1, _0, _0, z, _0, _1, _0, @@ -97,11 +97,11 @@ pub fn shear_x(m: &Mat, y: N, z: N) -> Mat { } /// Transforms a matrix with a shearing on Y axis. -pub fn shear2d_y(m: &Mat, x: N) -> Mat { +pub fn shear2d_y(m: &TMat3, x: N) -> TMat3 { let _0 = N::zero(); let _1 = N::one(); - let shear = Matrix3::new( + let shear = TMat3::new( _1, _0, _0, x, _1, _0, _0, _0, _1 @@ -110,10 +110,10 @@ pub fn shear2d_y(m: &Mat, x: N) -> Mat { } /// Transforms a matrix with a shearing on Y axis. -pub fn shear_y(m: &Mat, x: N, z: N) -> Mat { +pub fn shear_y(m: &TMat4, x: N, z: N) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); - let shear = Matrix4::new( + let shear = TMat4::new( _1, x, _0, _0, _0, _1, _0, _0, _0, z, _1, _0, @@ -124,10 +124,10 @@ pub fn shear_y(m: &Mat, x: N, z: N) -> Mat { } /// Transforms a matrix with a shearing on Z axis. -pub fn shear_z(m: &Mat, x: N, y: N) -> Mat { +pub fn shear_z(m: &TMat4, x: N, y: N) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); - let shear = Matrix4::new( + let shear = TMat4::new( _1, _0, x, _0, _0, _1, y, _0, _0, _0, _1, _0, diff --git a/nalgebra-glm/src/gtx/transform2d.rs b/nalgebra-glm/src/gtx/transform2d.rs index fbe1b086..b1e7e3e4 100644 --- a/nalgebra-glm/src/gtx/transform2d.rs +++ b/nalgebra-glm/src/gtx/transform2d.rs @@ -1,19 +1,19 @@ -use na::{Real, U2, U3, UnitComplex}; +use na::{Real, UnitComplex}; 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`. -pub fn rotate2d(m: &Mat, angle: N) -> Mat { +pub fn rotate2d(m: &TMat3, angle: N) -> TMat3 { m * UnitComplex::new(angle).to_homogeneous() } /// Builds a 2D scaling matrix and right-multiply it to `m`. -pub fn scale2d(m: &Mat, v: &Vec) -> Mat { +pub fn scale2d(m: &TMat3, v: &TVec2) -> TMat3 { m.prepend_nonuniform_scaling(v) } /// Builds a translation matrix and right-multiply it to `m`. -pub fn translate2d(m: &Mat, v: &Vec) -> Mat { +pub fn translate2d(m: &TMat3, v: &TVec2) -> TMat3 { m.prepend_translation(v) } \ No newline at end of file diff --git a/nalgebra-glm/src/gtx/vector_angle.rs b/nalgebra-glm/src/gtx/vector_angle.rs index a3231456..352c1707 100644 --- a/nalgebra-glm/src/gtx/vector_angle.rs +++ b/nalgebra-glm/src/gtx/vector_angle.rs @@ -10,10 +10,10 @@ pub fn angle(x: &Vec, y: &Vec) -> N x.angle(y) } -//pub fn oriented_angle(x: &Vec, y: &Vec) -> N { +//pub fn oriented_angle(x: &TVec2, y: &TVec2) -> N { // unimplemented!() //} // -//pub fn oriented_angle_ref(x: &Vec, y: &Vec, refv: &Vec) -> N { +//pub fn oriented_angle_ref(x: &TVec3, y: &TVec3, refv: &TVec3) -> N { // unimplemented!() //} diff --git a/nalgebra-glm/src/gtx/vector_query.rs b/nalgebra-glm/src/gtx/vector_query.rs index a6d97406..97acd49e 100644 --- a/nalgebra-glm/src/gtx/vector_query.rs +++ b/nalgebra-glm/src/gtx/vector_query.rs @@ -1,15 +1,15 @@ -use na::{Real, DefaultAllocator, U2, U3}; +use na::{Real, DefaultAllocator}; use traits::{Number, Dimension, Alloc}; -use aliases::Vec; +use aliases::{Vec, TVec2, TVec3}; /// Returns `true` if two vectors are collinear (up to an epsilon). -pub fn are_collinear(v0: &Vec, v1: &Vec, epsilon: N) -> bool { +pub fn are_collinear(v0: &TVec3, v1: &TVec3, epsilon: N) -> bool { is_null(&v0.cross(v1), epsilon) } /// Returns `true` if two 2D vectors are collinear (up to an epsilon). -pub fn are_collinear2d(v0: &Vec, v1: &Vec, epsilon: N) -> bool { +pub fn are_collinear2d(v0: &TVec2, v1: &TVec2, epsilon: N) -> bool { abs_diff_eq!(v0.perp(v1), N::zero(), epsilon = epsilon) }