use std::marker::PhantomData; use na; use math::{Isometry, Point}; use geometry::shape::{Ball, Plane, Shape}; use geometry::query::algorithms::{JohnsonSimplex, VoronoiSimplex2, VoronoiSimplex3}; use narrow_phase::{BallBallContactGenerator, CompositeShapeShapeContactGenerator, ContactAlgorithm, ContactDispatcher, OneShotContactManifoldGenerator, PlaneSupportMapContactGenerator, ShapeCompositeShapeContactGenerator, SupportMapPlaneContactGenerator, SupportMapSupportMapContactGenerator}; /// Collision dispatcher for shapes defined by `ncollide_entities`. pub struct DefaultContactDispatcher { _point_type: PhantomData

, _matrix_type: PhantomData, } impl DefaultContactDispatcher { /// Creates a new basic collision dispatcher. pub fn new() -> DefaultContactDispatcher { DefaultContactDispatcher { _point_type: PhantomData, _matrix_type: PhantomData, } } } impl> ContactDispatcher for DefaultContactDispatcher { fn get_contact_algorithm( &self, a: &Shape, b: &Shape, ) -> Option> { let a_is_ball = a.is_shape::>(); let b_is_ball = b.is_shape::>(); if a_is_ball && b_is_ball { Some(Box::new(BallBallContactGenerator::::new())) } else if a.is_shape::>() && b.is_support_map() { let wo_manifold = PlaneSupportMapContactGenerator::::new(); if !b_is_ball { let manifold = OneShotContactManifoldGenerator::new(wo_manifold); Some(Box::new(manifold)) } else { Some(Box::new(wo_manifold)) } } else if b.is_shape::>() && a.is_support_map() { let wo_manifold = SupportMapPlaneContactGenerator::::new(); if !a_is_ball { let manifold = OneShotContactManifoldGenerator::new(wo_manifold); Some(Box::new(manifold)) } else { Some(Box::new(wo_manifold)) } } else if a.is_support_map() && b.is_support_map() { match na::dimension::() { 2 => { let simplex = VoronoiSimplex2::new(); let wo_manifold = SupportMapSupportMapContactGenerator::new(simplex); if !a_is_ball && !b_is_ball { let manifold = OneShotContactManifoldGenerator::new(wo_manifold); Some(Box::new(manifold)) } else { Some(Box::new(wo_manifold)) } } 3 => { let simplex = VoronoiSimplex3::new(); let wo_manifold = SupportMapSupportMapContactGenerator::new(simplex); if !a_is_ball && !b_is_ball { let manifold = OneShotContactManifoldGenerator::new(wo_manifold); Some(Box::new(manifold)) } else { Some(Box::new(wo_manifold)) } } _ => { let simplex = JohnsonSimplex::new_w_tls(); let wo_manifold = SupportMapSupportMapContactGenerator::new(simplex); if false { // !a_is_ball && !b_is_ball { let manifold = OneShotContactManifoldGenerator::new(wo_manifold); Some(Box::new(manifold)) } else { Some(Box::new(wo_manifold)) } } } } else if a.is_composite_shape() { Some(Box::new(CompositeShapeShapeContactGenerator::::new())) } else if b.is_composite_shape() { Some(Box::new(ShapeCompositeShapeContactGenerator::::new())) } else { None } } }