mod camera {
use crate::screen::{Camera, WORLD_HALF_EXTENTS};
#[test]
fn camera_is_to_scale_and_transforms_properly() {
// The camera is a projection from [-WHE, +WHE] to [0, 1]
let mut camera = Camera {
width: WORLD_HALF_EXTENTS.x as f32,
height: WORLD_HALF_EXTENTS.y as f32,
..Default::default()
};
let vpjm = camera.build_view_projection_matrix();
assert_eq!(
vpjm.project_point3(glam::Vec3::new(0.0, 0.0, 0.0)),
glam::Vec3::new(0.5, 0.5, 0.0)
);
assert_eq!(
vpjm.project_point3(glam::Vec3::new(1.0, 1.0, 0.0)),
glam::Vec3::new(1.0, 1.0, 0.0)
);
camera.transform.translation.x = -0.25;
camera.transform.translation.y = -0.25;
let vpjm = camera.build_view_projection_matrix();
assert_eq!(
vpjm.project_point3(glam::Vec3::new(0.0, 0.0, 0.0)),
glam::Vec3::new(0.25, 0.25, 0.0)
);
assert_eq!(
vpjm.project_point3(glam::Vec3::new(1.0, 1.0, 0.0)),
glam::Vec3::new(0.75, 0.75, 0.0)
);
}
}