Emit collision stopped events after a collider is removed.

This commit is contained in:
Sébastien Crozet
2022-03-20 12:13:32 +01:00
committed by Sébastien Crozet
parent 063c638ec5
commit d38740369c
6 changed files with 146 additions and 71 deletions

View File

@@ -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.
@@ -46,6 +49,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.
@@ -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)]