ncollide3d/query/ray/
ray_bounding_sphere.rs
1use crate::bounding_volume::BoundingSphere;
2use crate::math::Isometry;
3use crate::query::{Ray, RayCast, RayIntersection};
4use crate::shape::Ball;
5use na::RealField;
6
7impl<N: RealField + Copy> RayCast<N> for BoundingSphere<N> {
8 #[inline]
9 fn toi_with_ray(&self, m: &Isometry<N>, ray: &Ray<N>, max_toi: N, solid: bool) -> Option<N> {
10 let centered_ray = ray.translate_by(-(m * self.center()).coords);
11
12 Ball::new(self.radius()).toi_with_ray(m, ¢ered_ray, max_toi, solid)
13 }
14
15 #[inline]
16 fn toi_and_normal_with_ray(
17 &self,
18 m: &Isometry<N>,
19 ray: &Ray<N>,
20 max_toi: N,
21 solid: bool,
22 ) -> Option<RayIntersection<N>> {
23 let centered_ray = ray.translate_by(-(m * self.center()).coords);
24
25 Ball::new(self.radius()).toi_and_normal_with_ray(
26 &Isometry::identity(),
27 ¢ered_ray,
28 max_toi,
29 solid,
30 )
31 }
32
33 #[cfg(feature = "dim3")]
34 #[inline]
35 fn toi_and_normal_and_uv_with_ray(
36 &self,
37 m: &Isometry<N>,
38 ray: &Ray<N>,
39 max_toi: N,
40 solid: bool,
41 ) -> Option<RayIntersection<N>> {
42 let centered_ray = ray.translate_by(-(m * self.center()).coords);
43
44 Ball::new(self.radius()).toi_and_normal_and_uv_with_ray(
45 &Isometry::identity(),
46 ¢ered_ray,
47 max_toi,
48 solid,
49 )
50 }
51
52 #[inline]
53 fn intersects_ray(&self, m: &Isometry<N>, ray: &Ray<N>, max_toi: N) -> bool {
54 let centered_ray = ray.translate_by(-(m * self.center()).coords);
55
56 Ball::new(self.radius()).intersects_ray(&Isometry::identity(), ¢ered_ray, max_toi)
57 }
58}