1pub mod aabb;
15pub mod fixed;
16pub mod frustum;
17pub mod ray;
18pub mod spatial;
19
20pub use glam::{EulerRot, Mat3, Mat4, Quat, Vec2, Vec3, Vec3A, Vec4};
23
24pub use aabb::Aabb;
25pub use fixed::{Fp32, FpVec3};
26pub use frustum::{Frustum, Intersection, Plane};
27pub use ray::Ray;
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn ray_intersects_aabb_inside_frustum() {
35 let view = Mat4::look_at_rh(Vec3::new(0.0, 0.0, 5.0), Vec3::ZERO, Vec3::Y);
37 let proj = Mat4::perspective_rh(std::f32::consts::FRAC_PI_4, 1.0, 0.1, 100.0);
38 let vp = proj * view;
39 let frustum = Frustum::from_matrix(&vp);
40
41 let aabb = Aabb::new(Vec3::splat(-1.0), Vec3::splat(1.0));
43
44 assert_eq!(frustum.test_aabb(aabb), Intersection::Inside);
46
47 let ray = Ray::new(Vec3::new(0.0, 0.0, 5.0), Vec3::new(0.0, 0.0, -1.0));
49
50 let t = ray.intersect_aabb(aabb);
52 assert!(t.is_some());
53
54 let intersection_distance = t.unwrap();
55 assert!((intersection_distance - 4.0).abs() < 1e-5);
57 }
58
59 #[test]
60 fn aabb_transform_then_frustum_cull() {
61 let view = Mat4::look_at_rh(Vec3::new(0.0, 0.0, 5.0), Vec3::ZERO, Vec3::Y);
63 let proj = Mat4::perspective_rh(std::f32::consts::FRAC_PI_4, 1.0, 0.1, 100.0);
64 let vp = proj * view;
65 let frustum = Frustum::from_matrix(&vp);
66
67 let local_aabb = Aabb::new(Vec3::splat(-0.5), Vec3::splat(0.5));
69
70 let inside_mat = Mat4::from_translation(Vec3::new(0.0, 0.0, -10.0));
72 let world_aabb_inside = local_aabb.transform(&inside_mat);
73 assert_eq!(frustum.test_aabb(world_aabb_inside), Intersection::Inside);
74
75 let outside_mat = Mat4::from_translation(Vec3::new(100.0, 0.0, 0.0));
77 let world_aabb_outside = local_aabb.transform(&outside_mat);
78 assert_eq!(frustum.test_aabb(world_aabb_outside), Intersection::Outside);
79 }
80}