aboutsummaryrefslogtreecommitdiff
path: root/src/geometry/contact_pair.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-03-20 12:13:32 +0100
committerSébastien Crozet <sebastien@crozet.re>2022-03-20 21:49:16 +0100
commitd38740369c12ff10ffa6ceef438cb1c90c5d3508 (patch)
treee7f37c26c400b93bed96a8c7697c60e2a183ecfa /src/geometry/contact_pair.rs
parent063c638ec5906747e3ca85ee0c5f112c7775f797 (diff)
downloadrapier-d38740369c12ff10ffa6ceef438cb1c90c5d3508.tar.gz
rapier-d38740369c12ff10ffa6ceef438cb1c90c5d3508.tar.bz2
rapier-d38740369c12ff10ffa6ceef438cb1c90c5d3508.zip
Emit collision stopped events after a collider is removed.
Diffstat (limited to 'src/geometry/contact_pair.rs')
-rw-r--r--src/geometry/contact_pair.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/geometry/contact_pair.rs b/src/geometry/contact_pair.rs
index 5826c7a..a75d58d 100644
--- a/src/geometry/contact_pair.rs
+++ b/src/geometry/contact_pair.rs
@@ -1,8 +1,11 @@
use crate::dynamics::RigidBodyHandle;
use crate::geometry::{ColliderHandle, Contact, ContactManifold};
use crate::math::{Point, Real, Vector};
+use crate::pipeline::EventHandler;
use parry::query::ContactManifoldsWorkspace;
+use super::CollisionEvent;
+
bitflags::bitflags! {
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
/// Flags affecting the behavior of the constraints solver for a given contact manifold.
@@ -47,6 +50,45 @@ impl Default for ContactData {
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Copy, Clone, Debug)]
+/// The description of all the contacts between a pair of colliders.
+pub struct IntersectionPair {
+ /// Are the colliders intersecting?
+ pub intersecting: bool,
+ /// Was a `CollisionEvent::Started` emitted for this collider?
+ pub(crate) start_event_emited: bool,
+}
+
+impl IntersectionPair {
+ pub(crate) fn new() -> Self {
+ Self {
+ intersecting: false,
+ start_event_emited: false,
+ }
+ }
+
+ pub(crate) fn emit_start_event(
+ &mut self,
+ collider1: ColliderHandle,
+ collider2: ColliderHandle,
+ events: &dyn EventHandler,
+ ) {
+ self.start_event_emited = true;
+ events.handle_collision_event(CollisionEvent::new(collider1, collider2, true), None);
+ }
+
+ pub(crate) fn emit_stop_event(
+ &mut self,
+ collider1: ColliderHandle,
+ collider2: ColliderHandle,
+ events: &dyn EventHandler,
+ ) {
+ self.start_event_emited = false;
+ events.handle_collision_event(CollisionEvent::new(collider1, collider2, false), None);
+ }
+}
+
+#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Clone)]
/// The description of all the contacts between a pair of colliders.
pub struct ContactPair {
@@ -60,6 +102,8 @@ pub struct ContactPair {
pub manifolds: Vec<ContactManifold>,
/// Is there any active contact in this contact pair?
pub has_any_active_contact: bool,
+ /// Was a `CollisionEvent::Started` emitted for this collider?
+ pub(crate) start_event_emited: bool,
pub(crate) workspace: Option<ContactManifoldsWorkspace>,
}
@@ -70,6 +114,7 @@ impl ContactPair {
collider2,
has_any_active_contact: false,
manifolds: Vec::new(),
+ start_event_emited: false,
workspace: None,
}
}
@@ -109,6 +154,24 @@ impl ContactPair {
deepest
}
+
+ pub(crate) fn emit_start_event(&mut self, events: &dyn EventHandler) {
+ self.start_event_emited = true;
+
+ events.handle_collision_event(
+ CollisionEvent::new(self.collider1, self.collider2, true),
+ Some(self),
+ );
+ }
+
+ pub(crate) fn emit_stop_event(&mut self, events: &dyn EventHandler) {
+ self.start_event_emited = false;
+
+ events.handle_collision_event(
+ CollisionEvent::new(self.collider1, self.collider2, false),
+ Some(self),
+ );
+ }
}
#[derive(Clone, Debug)]