aboutsummaryrefslogtreecommitdiff
path: root/stockton-render/src/draw/camera.rs
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:21 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:21 +0100
commit4163aaeff0542b1f6b00d31c3d3a61fdbc2dbea5 (patch)
treebf3a96395aaf5b9836ec96f530f1ab2fc33625fd /stockton-render/src/draw/camera.rs
parent3aaa48fef2f5b019660472429da21c726e6da007 (diff)
test(camera): test for MVP matrix generation
Diffstat (limited to 'stockton-render/src/draw/camera.rs')
-rw-r--r--stockton-render/src/draw/camera.rs39
1 files changed, 38 insertions, 1 deletions
diff --git a/stockton-render/src/draw/camera.rs b/stockton-render/src/draw/camera.rs
index 0e9011a..5737928 100644
--- a/stockton-render/src/draw/camera.rs
+++ b/stockton-render/src/draw/camera.rs
@@ -184,10 +184,47 @@ impl WorkingCamera {
self.settings.position.x += new.x;
self.settings.position.y += new.y;
self.settings.position.z += new.z;
+
self.is_dirty = true;
}
pub fn camera_pos(&self) -> Vector3 {
self.settings.position
}
-} \ No newline at end of file
+}
+
+#[cfg(test)]
+mod tests {
+ use stockton_types::Matrix4;
+use stockton_types::Vector3;
+ use draw::camera::WorkingCamera;
+
+ fn contains_nan(mat: &Matrix4) -> bool{
+ for x in mat.iter() {
+ if *x == std::f32::NAN {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ #[test]
+ fn camera_vp() {
+ let mut camera = WorkingCamera::defaults(16.0 / 9.0);
+
+ let old = camera.calc_vp_matrix();
+ println!("initial vp matrix: {:?}", old);
+
+ assert!(!contains_nan(&old), "No NaNs for initial matrix");
+
+ // Do a 180
+ camera.rotate(Vector3::new(0.0, 180.0, 0.0));
+
+ let new = camera.calc_vp_matrix();
+ assert!(!contains_nan(&new), "No NaNs after rotating");
+
+ println!("new vp matrix: {:?}", new);
+
+ assert!(old != new, "VP Matrix changes when camera rotates");
+ }
+}