diff options
| author | Sébastien Crozet <developer@crozet.re> | 2022-03-19 17:52:56 +0100 |
|---|---|---|
| committer | Sébastien Crozet <sebastien@crozet.re> | 2022-03-20 21:49:16 +0100 |
| commit | 063c638ec5906747e3ca85ee0c5f112c7775f797 (patch) | |
| tree | 498090f01c8cf8d69a35d03e123a1dfe006c54bf /src/geometry/mod.rs | |
| parent | a9e3441ecd64d50b478ab5370fabe187ec9a5c39 (diff) | |
| download | rapier-063c638ec5906747e3ca85ee0c5f112c7775f797.tar.gz rapier-063c638ec5906747e3ca85ee0c5f112c7775f797.tar.bz2 rapier-063c638ec5906747e3ca85ee0c5f112c7775f797.zip | |
Combine contact events and intersection events into a single event type and flags
Diffstat (limited to 'src/geometry/mod.rs')
| -rw-r--r-- | src/geometry/mod.rs | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/src/geometry/mod.rs b/src/geometry/mod.rs index 0462cbf..83c687b 100644 --- a/src/geometry/mod.rs +++ b/src/geometry/mod.rs @@ -52,38 +52,44 @@ pub type TOI = parry::query::TOI; pub use parry::shape::SharedShape; #[derive(Copy, Clone, Hash, Debug)] -/// Events occurring when two collision objects start or stop being in contact (or penetration). -pub enum ContactEvent { - /// Event occurring when two collision objects start being in contact. - /// - /// This event is generated whenever the narrow-phase finds a contact between two collision objects that did not have any contact at the last update. +/// Events occurring when two colliders start or stop being in contact (or intersecting) +pub enum CollisionEvent { + /// Event occurring when two colliders start being in contact (or intersecting) Started(ColliderHandle, ColliderHandle), - /// Event occurring when two collision objects stop being in contact. - /// - /// This event is generated whenever the narrow-phase fails to find any contact between two collision objects that did have at least one contact at the last update. + /// Event occurring when two colliders stop being in contact (or intersecting) Stopped(ColliderHandle, ColliderHandle), } -#[derive(Copy, Clone, Debug)] -/// Events occurring when two collision objects start or stop being in close proximity, contact, or disjoint. -pub struct IntersectionEvent { - /// The first collider to which the proximity event applies. - pub collider1: ColliderHandle, - /// The second collider to which the proximity event applies. - pub collider2: ColliderHandle, - /// Are the two colliders intersecting? - pub intersecting: bool, -} +impl CollisionEvent { + pub(crate) fn new(h1: ColliderHandle, h2: ColliderHandle, start: bool) -> Self { + if start { + Self::Started(h1, h2) + } else { + Self::Stopped(h1, h2) + } + } + + /// Is this a `Started` collision event? + pub fn started(self) -> bool { + matches!(self, CollisionEvent::Started(_, _)) + } + + /// Is this a `Stopped` collision event? + pub fn stopped(self) -> bool { + matches!(self, CollisionEvent::Stopped(_, _)) + } + + /// The handle of the first collider involved in this collision event. + pub fn collider1(self) -> ColliderHandle { + match self { + Self::Started(h, _) | Self::Stopped(h, _) => h, + } + } -impl IntersectionEvent { - /// Instantiates a new proximity event. - /// - /// Panics if `prev_status` is equal to `new_status`. - pub fn new(collider1: ColliderHandle, collider2: ColliderHandle, intersecting: bool) -> Self { - Self { - collider1, - collider2, - intersecting, + /// The handle of the second collider involved in this collision event. + pub fn collider2(self) -> ColliderHandle { + match self { + Self::Started(_, h) | Self::Stopped(_, h) => h, } } } |
