Skip to content

Commit

Permalink
- fix incorrect m44 * m34 mul function, there was a typo in the 4th r…
Browse files Browse the repository at this point in the history
…ow causing incorrect results
  • Loading branch information
polymonster committed May 7, 2023
1 parent 95c0d48 commit 129dccd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/mat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,10 +1049,10 @@ fn mul4x4_3x4<T: Number>(lhs: Mat4<T>, rhs: Mat34<T>) -> Mat4<T> {
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],
]
}
}
Expand Down
24 changes: 24 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 129dccd

Please sign in to comment.