ncollide3d/pipeline/narrow_phase/proximity_detector/
default_proximity_dispatcher.rs
1use crate::pipeline::narrow_phase::proximity_detector::{
2 BallBallProximityDetector, CompositeShapeShapeProximityDetector,
3 PlaneSupportMapProximityDetector, ProximityAlgorithm, ProximityDispatcher,
4 SupportMapPlaneProximityDetector, SupportMapSupportMapProximityDetector,
5};
6use crate::shape::{Ball, Plane, Shape};
7use na::RealField;
8
9pub struct DefaultProximityDispatcher {}
11
12impl DefaultProximityDispatcher {
13 pub fn new() -> DefaultProximityDispatcher {
15 DefaultProximityDispatcher {}
16 }
17}
18
19impl<N: RealField + Copy> ProximityDispatcher<N> for DefaultProximityDispatcher {
20 fn get_proximity_algorithm(
21 &self,
22 a: &dyn Shape<N>,
23 b: &dyn Shape<N>,
24 ) -> Option<ProximityAlgorithm<N>> {
25 let a_is_ball = a.is_shape::<Ball<N>>();
26 let b_is_ball = b.is_shape::<Ball<N>>();
27
28 if a_is_ball && b_is_ball {
29 Some(Box::new(BallBallProximityDetector::new()))
30 } else if a.is_shape::<Plane<N>>() && b.is_support_map() {
31 Some(Box::new(PlaneSupportMapProximityDetector::new()))
32 } else if b.is_shape::<Plane<N>>() && a.is_support_map() {
33 Some(Box::new(SupportMapPlaneProximityDetector::new()))
34 } else if a.is_support_map() && b.is_support_map() {
35 Some(Box::new(SupportMapSupportMapProximityDetector::new()))
36 } else if a.is_composite_shape() {
37 Some(Box::new(CompositeShapeShapeProximityDetector::<N>::new(
38 false,
39 )))
40 } else if b.is_composite_shape() {
41 Some(Box::new(CompositeShapeShapeProximityDetector::<N>::new(
42 true,
43 )))
44 } else {
45 None
46 }
47 }
48}