use na::{U2, U3}; use crate::aliases::{TMat3, TMat4, TVec2, TVec3}; use crate::traits::Number; /// Build planar projection matrix along normal axis and right-multiply it to `m`. pub fn proj2d(m: &TMat3, normal: &TVec2) -> TMat3 { let mut res = TMat3::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: &TMat4, normal: &TVec3) -> TMat4 { let mut res = TMat4::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: &TMat3, normal: &TVec2) -> TMat3 { let mut res = TMat3::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: &TMat4, normal: &TVec3) -> TMat4 { let mut res = TMat4::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) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); TMat4::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: &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: &TMat3, y: N) -> TMat3 { let _0 = N::zero(); let _1 = N::one(); let shear = TMat3::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: &TMat4, y: N, z: N) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); let shear = TMat4::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: &TMat3, x: N) -> TMat3 { let _0 = N::zero(); let _1 = N::one(); let shear = TMat3::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: &TMat4, x: N, z: N) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); let shear = TMat4::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: &TMat4, x: N, y: N) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); let shear = TMat4::new(_1, _0, x, _0, _0, _1, y, _0, _0, _0, _1, _0, _0, _0, _0, _1); m * shear }