solid_ray_cast3d/
solid_ray_cast3d.rs

1use parry3d::math::{Pose, Vector};
2use parry3d::query::{Ray, RayCast};
3use parry3d::shape::Cuboid;
4
5fn main() {
6    let cuboid = Cuboid::new(Vector::new(1.0, 2.0, 1.0));
7    let ray_inside = Ray::new(Vector::ZERO, Vector::Y);
8    let ray_miss = Ray::new(Vector::new(2.0, 2.0, 2.0), Vector::new(1.0, 1.0, 1.0));
9
10    // Solid cast.
11    assert_eq!(
12        cuboid
13            .cast_ray(&Pose::identity(), &ray_inside, f32::MAX, true)
14            .unwrap(),
15        0.0
16    );
17
18    // Non-solid cast.
19    assert_eq!(
20        cuboid
21            .cast_ray(&Pose::identity(), &ray_inside, f32::MAX, false)
22            .unwrap(),
23        2.0
24    );
25
26    // The other ray does not intersect this shape.
27    assert!(cuboid
28        .cast_ray(&Pose::identity(), &ray_miss, f32::MAX, false)
29        .is_none());
30    assert!(cuboid
31        .cast_ray(&Pose::identity(), &ray_miss, f32::MAX, true)
32        .is_none());
33}