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