summaryrefslogtreecommitdiff
path: root/src/tests/test_3d.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_3d.cc')
-rw-r--r--src/tests/test_3d.cc31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/tests/test_3d.cc b/src/tests/test_3d.cc
index 90869bf..e0fb2e0 100644
--- a/src/tests/test_3d.cc
+++ b/src/tests/test_3d.cc
@@ -23,14 +23,14 @@ void test_camera() {
assert(near(view.m[14], -10.0f));
// Test Camera::set_look_at
- cam.set_look_at({5, 0, 0}, {0, 0, 0}, {0, 1, 0}); // Look at origin from (5,0,0)
+ cam.set_look_at({5, 0, 0}, {0, 0, 0},
+ {0, 1, 0}); // Look at origin from (5,0,0)
mat4 view_shifted = cam.get_view_matrix();
- // The camera's forward vector (0,0,-1) should now point towards (-1,0,0) in world space.
- // The translation part of the view matrix should be based on -dot(s, eye), -dot(u, eye), dot(f, eye)
- // s = (0,0,-1), u = (0,1,0), f = (-1,0,0)
- // m[12] = -dot({0,0,-1}, {5,0,0}) = 0
- // m[13] = -dot({0,1,0}, {5,0,0}) = 0
- // m[14] = dot({-1,0,0}, {5,0,0}) = -5
+ // The camera's forward vector (0,0,-1) should now point towards (-1,0,0) in
+ // world space. The translation part of the view matrix should be based on
+ // -dot(s, eye), -dot(u, eye), dot(f, eye) s = (0,0,-1), u = (0,1,0), f =
+ // (-1,0,0) m[12] = -dot({0,0,-1}, {5,0,0}) = 0 m[13] = -dot({0,1,0}, {5,0,0})
+ // = 0 m[14] = dot({-1,0,0}, {5,0,0}) = -5
assert(near(view_shifted.m[12], 0.0f));
assert(near(view_shifted.m[13], 0.0f));
assert(near(view_shifted.m[14], -5.0f));
@@ -76,22 +76,27 @@ void test_object_transform() {
mat4 inv_model_t = model_t.inverse();
// Applying inv_model to a translated point should undo the translation.
// Point (5,0,0) should go to (0,0,0)
- vec4 translated_point(5,0,0,1);
- vec4 original_space_t = inv_model_t * vec4(translated_point.x, translated_point.y, translated_point.z, 1.0);
- assert(near(original_space_t.x, 0.0f) && near(original_space_t.y, 0.0f) && near(original_space_t.z, 0.0f));
+ vec4 translated_point(5, 0, 0, 1);
+ vec4 original_space_t =
+ inv_model_t *
+ vec4(translated_point.x, translated_point.y, translated_point.z, 1.0);
+ assert(near(original_space_t.x, 0.0f) && near(original_space_t.y, 0.0f) &&
+ near(original_space_t.z, 0.0f));
// Model matrix with rotation (90 deg Y) and translation (5,0,0)
obj.position = vec3(5, 0, 0);
obj.rotation = quat::from_axis({0, 1, 0}, 1.570796f);
mat4 model_trs = obj.get_model_matrix();
mat4 inv_model_trs = model_trs.inverse();
- // Transform point (1,0,0) (local right) via TRS: Rotates to (0,0,-1), Translates to (5,0,-1)
- vec4 p_trs(1,0,0,1);
+ // Transform point (1,0,0) (local right) via TRS: Rotates to (0,0,-1),
+ // Translates to (5,0,-1)
+ vec4 p_trs(1, 0, 0, 1);
vec4 transformed_p = model_trs * p_trs;
assert(near(transformed_p.x, 5.0f) && near(transformed_p.z, -1.0f));
// Apply inverse to transformed point to get back original point
vec4 original_space_trs = inv_model_trs * transformed_p;
- assert(near(original_space_trs.x, 1.0f) && near(original_space_trs.y, 0.0f) && near(original_space_trs.z, 0.0f));
+ assert(near(original_space_trs.x, 1.0f) && near(original_space_trs.y, 0.0f) &&
+ near(original_space_trs.z, 0.0f));
}
void test_scene() {