diff options
| author | Crozet Sébastien <developer@crozet.re> | 2020-11-24 15:21:27 +0100 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2020-11-24 15:21:27 +0100 |
| commit | 437748096d96d4bde5540711580be26a2b146b65 (patch) | |
| tree | 2a2ec5f59598ca1e88a29e793ee7633ae1c10cc0 /src | |
| parent | 3379094f5af20187d7ee0d50717810956fa32254 (diff) | |
| download | rapier-437748096d96d4bde5540711580be26a2b146b65.tar.gz rapier-437748096d96d4bde5540711580be26a2b146b65.tar.bz2 rapier-437748096d96d4bde5540711580be26a2b146b65.zip | |
Allow retrieving one specific contact pair or proximity pair.
Diffstat (limited to 'src')
| -rw-r--r-- | src/geometry/narrow_phase.rs | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs index cf7b531..a3d0ea7 100644 --- a/src/geometry/narrow_phase.rs +++ b/src/geometry/narrow_phase.rs @@ -106,14 +106,39 @@ impl NarrowPhase { ) } - // #[cfg(feature = "parallel")] - // pub fn contact_pairs(&self) -> &[ContactPair] { - // &self.contact_graph.interactions - // } + /// The contact pair involving two specific colliders. + /// + /// If this returns `None`, there is no contact between the two colliders. + /// If this returns `Some`, then there may be a contact between the two colliders. Check the + /// result [`ContactPair::has_any_active_collider`] method to see if there is an actual contact. + pub fn contact_pair( + &self, + collider1: ColliderHandle, + collider2: ColliderHandle, + ) -> Option<&ContactPair> { + let id1 = self.graph_indices.get(collider1)?; + let id2 = self.graph_indices.get(collider2)?; + self.contact_graph + .interaction_pair(id1.contact_graph_index, id2.contact_graph_index) + .map(|c| c.2) + } - // pub fn contact_pairs_mut(&mut self) -> &mut [ContactPair] { - // &mut self.contact_graph.interactions - // } + /// The proximity pair involving two specific colliders. + /// + /// If this returns `None`, there is no intersection between the two colliders. + /// If this returns `Some`, then there may be an intersection between the two colliders. Check the + /// value of [`ProximityPair::proximity`] method to see if there is an actual intersection. + pub fn proximity_pair( + &self, + collider1: ColliderHandle, + collider2: ColliderHandle, + ) -> Option<&ProximityPair> { + let id1 = self.graph_indices.get(collider1)?; + let id2 = self.graph_indices.get(collider2)?; + self.proximity_graph + .interaction_pair(id1.proximity_graph_index, id2.proximity_graph_index) + .map(|c| c.2) + } // #[cfg(feature = "parallel")] // pub(crate) fn contact_pairs_vec_mut(&mut self) -> &mut Vec<ContactPair> { |
