summaryrefslogtreecommitdiff
path: root/src/tests/test_maths.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_maths.cc')
-rw-r--r--src/tests/test_maths.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/tests/test_maths.cc b/src/tests/test_maths.cc
index d9bc4d1..64bbb45 100644
--- a/src/tests/test_maths.cc
+++ b/src/tests/test_maths.cc
@@ -110,6 +110,25 @@ void test_matrices() {
mat4 view = mat4::look_at(eye, target, up);
// Point (0,0,0) in world should be at (0,0,-5) in view space
assert(near(view.m[14], -5.0f));
+
+ // Test matrix multiplication
+ mat4 t = mat4::translate({1, 2, 3});
+ mat4 s = mat4::scale({2, 2, 2});
+ mat4 ts = t * s; // Scale then Translate (if applied to vector on right: M*v)
+
+ // v = (1,1,1,1) -> scale(2,2,2) -> (2,2,2,1) -> translate(1,2,3) -> (3,4,5,1)
+ vec4 v(1, 1, 1, 1);
+ vec4 res = ts * v;
+ assert(near(res.x, 3.0f));
+ assert(near(res.y, 4.0f));
+ assert(near(res.z, 5.0f));
+
+ // Test Rotation
+ // Rotate 90 deg around Z. (1,0,0) -> (0,1,0)
+ mat4 r = mat4::rotate({0, 0, 1}, 1.570796f);
+ vec4 v_rot = r * vec4(1, 0, 0, 1);
+ assert(near(v_rot.x, 0.0f));
+ assert(near(v_rot.y, 1.0f));
}
// Tests easing curves