ncollide3d/pipeline/narrow_phase/contact_generator/
contact_manifold_generator.rs

1use crate::math::Isometry;
2use crate::query::ContactPreprocessor;
3use crate::query::{ContactManifold, ContactPrediction};
4use crate::shape::Shape;
5use na::RealField;
6use std::any::Any;
7
8/// An algorithm to compute contact points, normals and penetration depths between two specific
9/// objects.
10pub trait ContactManifoldGenerator<N: RealField + Copy>: Any + Send + Sync {
11    /// Runs the collision detection on two objects. It is assumed that the same
12    /// collision detector (the same structure) is always used with the same
13    /// pair of objects.
14    ///
15    /// Returns `false` if persisting this algorithm for re-use is unlikely to improve performance,
16    /// e.g. due to the objects being distant. Note that if the `ContactManifoldGenerator` would
17    /// likely be immediately reconstructed in the next time-step, dropping it is sub-optimal
18    /// regardless.
19    fn generate_contacts(
20        &mut self,
21        dispatcher: &dyn ContactDispatcher<N>,
22        ma: &Isometry<N>,
23        a: &dyn Shape<N>,
24        proc1: Option<&dyn ContactPreprocessor<N>>,
25        mb: &Isometry<N>,
26        b: &dyn Shape<N>,
27        proc2: Option<&dyn ContactPreprocessor<N>>,
28        prediction: &ContactPrediction<N>,
29        manifold: &mut ContactManifold<N>,
30    ) -> bool;
31
32    /// Generate an empty contact manifold configured as required by this contact manifold generator.
33    fn init_manifold(&self) -> ContactManifold<N> {
34        ContactManifold::new()
35    }
36}
37
38pub type ContactAlgorithm<N> = Box<dyn ContactManifoldGenerator<N>>;
39
40pub trait ContactDispatcher<N>: Any + Send + Sync {
41    /// Allocate a collision algorithm corresponding to a pair of objects with the given shapes.
42    fn get_contact_algorithm(
43        &self,
44        a: &dyn Shape<N>,
45        b: &dyn Shape<N>,
46    ) -> Option<ContactAlgorithm<N>>;
47}