Fixed obb-ray collision test

This commit is contained in:
Lillian Vixe 2024-03-08 02:38:00 -08:00
parent 0d1690d7b1
commit 5e81392448

View file

@ -612,6 +612,8 @@ pub fn ray_obb_intersection(
}
}
////.
///
pub fn distance_to_ray_bounds_intersection(
ray_origin: Vec3,
ray_direction_normalized: Vec3,
@ -931,25 +933,24 @@ pub fn test_obb_collisions() {
pub fn test_ray_x_bounding_collisions() {
let abounds: OBB = OBB::new(
Vec3::new(10., 0., 0.),
Quat::from_rotation_z(1.5708),
Quat::from_rotation_z(f32::to_radians(90.)),
Vec3::splat(5.),
); // rotated 90 degrees (approximate in radians), should match aabb_test at 5x 0yz
);
let aabb_test: Option<Vec3> =
ray_aabb_intersection(Vec3::ZERO, Vec3::X, abounds.position, abounds.half_size);
let obb_test: Option<Vec3> = ray_obb_intersection(Vec3::ZERO, Vec3::X, &abounds);
assert_eq!(aabb_test.unwrap(), Vec3::new(5., 0., 0.));
assert_eq!(obb_test.unwrap(), Vec3::new(5., 0., 0.));
assert_eq!(obb_test.unwrap().round(), Vec3::new(5., 0., 0.));
let rotated_bounds: OBB = OBB::new(
Vec3::new(10., 0., 0.),
Quat::from_rotation_z(0.785398), // 45 degrees rotation in radians (approximate)
Vec3::new(20., 0., 0.),
Quat::from_rotation_z(f32::to_radians(45.0)),
Vec3::splat(5.),
);
let rotated_obb_test = ray_obb_intersection(Vec3::ZERO, Vec3::X, &rotated_bounds).unwrap();
println!("{rotated_obb_test}");
panic!();
assert_eq!(rotated_obb_test.round().x, 13.);
}
/*
use rand::Rng;