use na::{U2, U3, U4, Matrix3, Matrix4}; use traits::Number; use aliases::{Mat, Vec}; /// 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(); { let mut part = res.fixed_slice_mut::(0, 0); part -= normal * normal.transpose(); } m * res } /// Build planar projection matrix along normal axis, and right-multiply it to `m`. pub fn proj(m: &Mat, normal: &Vec) -> Mat { let mut res = Matrix4::identity(); { let mut part = res.fixed_slice_mut::(0, 0); part -= normal * normal.transpose(); } m * res } /// Builds a reflection matrix and right-multiply it to `m`. pub fn reflect2d(m: &Mat, normal: &Vec) -> Mat { let mut res = Matrix3::identity(); { let mut part = res.fixed_slice_mut::(0, 0); part -= (normal * N::from_f64(2.0).unwrap()) * normal.transpose(); } m * res } /// Builds a reflection matrix, and right-multiply it to `m`. pub fn reflect(m: &Mat, normal: &Vec) -> Mat { let mut res = Matrix4::identity(); { let mut part = res.fixed_slice_mut::(0, 0); part -= (normal * N::from_f64(2.0).unwrap()) * normal.transpose(); } m * res } /// Builds a scale-bias matrix. pub fn scale_bias_matrix(scale: N, bias: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); Matrix4::new( scale, _0, _0, bias, _0, scale, _0, bias, _0, _0, scale, bias, _0, _0, _0, _1, ) } /// Builds a scale-bias matrix, and right-multiply it to `m`. pub fn scale_bias(m: &Mat, scale: N, bias: N) -> Mat { m * scale_bias_matrix(scale, bias) } /// Transforms a matrix with a shearing on X axis. pub fn shear2d_x(m: &Mat, y: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); let shear = Matrix3::new( _1, y, _0, _0, _1, _0, _0, _0, _1 ); m * shear } /// Transforms a matrix with a shearing on Y axis. pub fn shear_x(m: &Mat, y: N, z: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); let shear = Matrix4::new( _1, _0, _0, _0, y, _1, _0, _0, z, _0, _1, _0, _0, _0, _0, _1, ); m * shear } /// Transforms a matrix with a shearing on Y axis. pub fn shear2d_y(m: &Mat, x: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); let shear = Matrix3::new( _1, _0, _0, x, _1, _0, _0, _0, _1 ); m * shear } /// Transforms a matrix with a shearing on Y axis. pub fn shear_y(m: &Mat, x: N, z: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); let shear = Matrix4::new( _1, x, _0, _0, _0, _1, _0, _0, _0, z, _1, _0, _0, _0, _0, _1, ); m * shear } /// Transforms a matrix with a shearing on Z axis. pub fn shear_z(m: &Mat, x: N, y: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); let shear = Matrix4::new( _1, _0, x, _0, _0, _1, y, _0, _0, _0, _1, _0, _0, _0, _0, _1, ); m * shear }