pub use glam::{DMat3, DQuat, DVec3};
pub fn mat3_from_rows(r0: DVec3, r1: DVec3, r2: DVec3) -> DMat3 {
DMat3::from_cols(
DVec3::new(r0.x, r1.x, r2.x),
DVec3::new(r0.y, r1.y, r2.y),
DVec3::new(r0.z, r1.z, r2.z),
)
}
#[inline]
pub fn vector3_transform(tmat: &DMat3, vec: DVec3) -> DVec3 {
*tmat * vec
}
#[inline]
pub fn vector3_transform_transpose(tmat: &DMat3, vec: DVec3) -> DVec3 {
tmat.transpose() * vec
}
#[inline]
pub fn matrix3x3_transform_matrix(trans: &DMat3, mat: &DMat3) -> DMat3 {
*trans * *mat * trans.transpose()
}
#[inline]
pub fn matrix3x3_transpose_transform_matrix(trans: &DMat3, mat: &DMat3) -> DMat3 {
trans.transpose() * *mat * *trans
}
#[inline]
pub fn matrix3x3_product_transpose_transpose(mat_left: &DMat3, mat_right: &DMat3) -> DMat3 {
mat_left.transpose() * mat_right.transpose()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn mat3_from_rows_identity() {
let m = mat3_from_rows(
DVec3::new(1.0, 0.0, 0.0),
DVec3::new(0.0, 1.0, 0.0),
DVec3::new(0.0, 0.0, 1.0),
);
assert_eq!(m, DMat3::IDENTITY);
}
#[test]
fn mat3_from_rows_element_access() {
let m = mat3_from_rows(
DVec3::new(0.0, 1.0, 2.0),
DVec3::new(10.0, 11.0, 12.0),
DVec3::new(20.0, 21.0, 22.0),
);
assert_eq!(m.col(0)[0], 0.0);
assert_eq!(m.col(1)[0], 1.0);
assert_eq!(m.col(2)[0], 2.0);
assert_eq!(m.col(0)[1], 10.0);
assert_eq!(m.col(1)[1], 11.0);
assert_eq!(m.col(2)[1], 12.0);
assert_eq!(m.col(0)[2], 20.0);
assert_eq!(m.col(1)[2], 21.0);
assert_eq!(m.col(2)[2], 22.0);
}
}