From 73788a21ab02b27c12f6ab30901b85e928b25067 Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Thu, 7 Jul 2022 10:58:10 +0200 Subject: Add ActiveEvents::CONTACT_FORCE_EVENTS for consistency with ActiveEvents::COLLISION_EVENTS --- src/geometry/collider.rs | 12 ++++++++++-- src/pipeline/event_handler.rs | 7 +++++-- src/pipeline/physics_pipeline.rs | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index 7b0cc4c..bbea8b0 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -26,7 +26,7 @@ pub struct Collider { pub(crate) material: ColliderMaterial, pub(crate) flags: ColliderFlags, pub(crate) bf_data: ColliderBroadPhaseData, - pub(crate) contact_force_event_threshold: Real, + contact_force_event_threshold: Real, /// User-defined data associated to this collider. pub user_data: u128, } @@ -37,6 +37,14 @@ impl Collider { self.changes = ColliderChanges::all(); } + pub(crate) fn effective_contact_force_event_threshold(&self) -> Real { + if self.flags.active_events.contains(ActiveEvents::CONTACT_FORCE_EVENTS) { + self.contact_force_event_threshold + } else { + Real::MAX + } + } + /// The rigid body this collider is attached to. pub fn parent(&self) -> Option { self.parent.map(|parent| parent.handle) @@ -412,7 +420,7 @@ impl ColliderBuilder { active_collision_types: ActiveCollisionTypes::default(), active_hooks: ActiveHooks::empty(), active_events: ActiveEvents::empty(), - contact_force_event_threshold: Real::MAX, + contact_force_event_threshold: 0.0, } } diff --git a/src/pipeline/event_handler.rs b/src/pipeline/event_handler.rs index e0f76a9..e5270ad 100644 --- a/src/pipeline/event_handler.rs +++ b/src/pipeline/event_handler.rs @@ -7,9 +7,12 @@ bitflags::bitflags! { #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] /// Flags affecting the events generated for this collider. pub struct ActiveEvents: u32 { - /// If set, Rapier will call `EventHandler::handle_contact_event` + /// If set, Rapier will call `EventHandler::handle_collision_event` /// whenever relevant for this collider. const COLLISION_EVENTS = 0b0001; + /// If set, Rapier will call `EventHandler::handle_contact_force_event` + /// whenever relevant for this collider. + const CONTACT_FORCE_EVENTS = 0b0010; } } @@ -48,7 +51,7 @@ pub trait EventHandler: Send + Sync { /// /// A force event is generated whenever the total force magnitude applied between two /// colliders is `> Collider::contact_force_event_threshold` value of any of these - /// colliders. + /// colliders with the `ActiveEvents::CONTACT_FORCE_EVENTS` flag set. /// /// The "total force magnitude" here means "the sum of the magnitudes of the forces applied at /// all the contact points in a contact pair". Therefore, if the contact pair involves two diff --git a/src/pipeline/physics_pipeline.rs b/src/pipeline/physics_pipeline.rs index 71ab578..391b39a 100644 --- a/src/pipeline/physics_pipeline.rs +++ b/src/pipeline/physics_pipeline.rs @@ -291,8 +291,8 @@ impl PhysicsPipeline { let co1 = &colliders[pair.collider1]; let co2 = &colliders[pair.collider2]; let threshold = co1 - .contact_force_event_threshold - .min(co2.contact_force_event_threshold); + .effective_contact_force_event_threshold() + .min(co2.effective_contact_force_event_threshold()); if threshold < Real::MAX { let total_magnitude = pair.total_impulse_magnitude() * inv_dt; -- cgit From e20f4a9952fb83ba99cfbb22da62cf88b336011b Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Thu, 7 Jul 2022 11:06:25 +0200 Subject: cargo fmt --- src/geometry/collider.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index bbea8b0..a9af8d1 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -38,7 +38,11 @@ impl Collider { } pub(crate) fn effective_contact_force_event_threshold(&self) -> Real { - if self.flags.active_events.contains(ActiveEvents::CONTACT_FORCE_EVENTS) { + if self + .flags + .active_events + .contains(ActiveEvents::CONTACT_FORCE_EVENTS) + { self.contact_force_event_threshold } else { Real::MAX -- cgit