From 129dccd0104a53d81515f2ff2e46e8953b8dfaba Mon Sep 17 00:00:00 2001 From: polymonster Date: Sun, 7 May 2023 12:36:52 +0100 Subject: [PATCH] - fix incorrect m44 * m34 mul function, there was a typo in the 4th row causing incorrect results --- src/mat.rs | 8 ++++---- tests/tests.rs | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/mat.rs b/src/mat.rs index d4e30fb..a261a28 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -1049,10 +1049,10 @@ fn mul4x4_3x4(lhs: Mat4, rhs: Mat34) -> Mat4 { lhs.m[8] * rhs.m[2] + lhs.m[9] * rhs.m[6] + lhs.m[10] * rhs.m[10], lhs.m[8] * rhs.m[3] + lhs.m[9] * rhs.m[7] + lhs.m[10] * rhs.m[11] + lhs.m[11], - lhs.m[12] * rhs.m[0] + lhs.m[10] * rhs.m[4] + lhs.m[14] * rhs.m[8], - lhs.m[12] * rhs.m[1] + lhs.m[10] * rhs.m[5] + lhs.m[14] * rhs.m[9], - lhs.m[12] * rhs.m[2] + lhs.m[10] * rhs.m[6] + lhs.m[14] * rhs.m[10], - lhs.m[12] * rhs.m[3] + lhs.m[10] * rhs.m[7] + lhs.m[14] * rhs.m[11] + lhs.m[15], + lhs.m[12] * rhs.m[0] + lhs.m[13] * rhs.m[4] + lhs.m[14] * rhs.m[8], + lhs.m[12] * rhs.m[1] + lhs.m[13] * rhs.m[5] + lhs.m[14] * rhs.m[9], + lhs.m[12] * rhs.m[2] + lhs.m[13] * rhs.m[6] + lhs.m[14] * rhs.m[10], + lhs.m[12] * rhs.m[3] + lhs.m[13] * rhs.m[7] + lhs.m[14] * rhs.m[11] + lhs.m[15], ] } } diff --git a/tests/tests.rs b/tests/tests.rs index afa33c3..e2209fa 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1712,6 +1712,30 @@ fn matrix_mul() { assert_eq!(Mat4f::approx(m4ref * mi, expected, 0.001), true); assert_eq!(Mat4f::approx(m4 * miref, expected, 0.001), true); assert_eq!(Mat4f::approx(m4ref * miref, expected, 0.001), true); + + // 3x4 * 4x4 parity with 4x4 * 4x4 + + let m34 = Mat34f::new( + -0.00078125, 0.0, 0.00078125, 0.0, + 0.00072463776, 0.0014492755, 0.00072463776, 0.0, + 0.00037593985, -0.00037593985, 0.00037593985, 0.5 + ); + + let m44 = Mat4f::new( + -0.00078125, 0.0, 0.00078125, 0.0, + 0.00072463776, 0.0014492755, 0.00072463776, 0.0, + 0.00037593985, -0.00037593985, 0.00037593985, 0.5, + 0.0, 0.0, 0.0, 1.0 + ); + + let proj = Mat4f::new( + 0.0013531648, 0.0, 0.0, -0.0, + 0.0, 0.0021739134, 0.0, -0.0, + 0.0, 0.0, -0.0006511469, 0.5, + 0.0, 0.0, 0.0, 1.0 + ); + + assert_eq!(proj * m34, proj * m44); } #[test]