diff options
| author | Sébastien Crozet <developer@crozet.re> | 2022-07-04 15:04:06 +0200 |
|---|---|---|
| committer | Sébastien Crozet <developer@crozet.re> | 2022-07-04 15:04:06 +0200 |
| commit | 158308ad715d00f2c0f259b185bf0410395b1aac (patch) | |
| tree | 243ea954686a15b125c453c357d58c3eb562c94a /src/pipeline | |
| parent | 1121b07d523ea9441025f2b40574e2b6c2477a88 (diff) | |
| download | rapier-158308ad715d00f2c0f259b185bf0410395b1aac.tar.gz rapier-158308ad715d00f2c0f259b185bf0410395b1aac.tar.bz2 rapier-158308ad715d00f2c0f259b185bf0410395b1aac.zip | |
Add hepler function for building a contact force event from a contact pair
Diffstat (limited to 'src/pipeline')
| -rw-r--r-- | src/pipeline/event_handler.rs | 31 | ||||
| -rw-r--r-- | src/pipeline/query_pipeline.rs | 8 |
2 files changed, 5 insertions, 34 deletions
diff --git a/src/pipeline/event_handler.rs b/src/pipeline/event_handler.rs index e491fdf..e0f76a9 100644 --- a/src/pipeline/event_handler.rs +++ b/src/pipeline/event_handler.rs @@ -124,36 +124,7 @@ impl EventHandler for ChannelEventCollector { contact_pair: &ContactPair, total_force_magnitude: Real, ) { - let mut result = ContactForceEvent { - collider1: contact_pair.collider1, - collider2: contact_pair.collider2, - total_force_magnitude, - ..ContactForceEvent::default() - }; - - for m in &contact_pair.manifolds { - let mut total_manifold_impulse = 0.0; - for pt in m.contacts() { - total_manifold_impulse += pt.data.impulse; - - if pt.data.impulse > result.max_force_magnitude { - result.max_force_magnitude = pt.data.impulse; - result.max_force_direction = m.data.normal; - } - } - - result.total_force += m.data.normal * total_manifold_impulse; - } - - let inv_dt = crate::utils::inv(dt); - // NOTE: convert impulses to forces. Note that we - // don’t need to convert the `total_force_magnitude` - // because it’s an input of this function already - // assumed to be a force instead of an impulse. - result.total_force *= inv_dt; - result.max_force_direction *= inv_dt; - result.max_force_magnitude *= inv_dt; - + let result = ContactForceEvent::from_contact_pair(dt, contact_pair, total_force_magnitude); let _ = self.contact_force_event_sender.send(result); } } diff --git a/src/pipeline/query_pipeline.rs b/src/pipeline/query_pipeline.rs index 586212c..86fa7b6 100644 --- a/src/pipeline/query_pipeline.rs +++ b/src/pipeline/query_pipeline.rs @@ -103,16 +103,16 @@ impl QueryFilterFlags { /// A filter tha describes what collider should be included or excluded from a scene query. #[derive(Copy, Clone, Default)] pub struct QueryFilter<'a> { - /// Flags indicating what particular type of colliders should be exclude. + /// Flags indicating what particular type of colliders should be excluded from the scene query. pub flags: QueryFilterFlags, /// If set, only colliders with collision groups compatible with this one will /// be included in the scene query. pub groups: Option<InteractionGroups>, - /// If set, this collider will be excluded by the query. + /// If set, this collider will be excluded from the scene query. pub exclude_collider: Option<ColliderHandle>, - /// If set, any collider attached to this rigid-body will be exclude by the query. + /// If set, any collider attached to this rigid-body will be excluded from the scene query. pub exclude_rigid_body: Option<RigidBodyHandle>, - /// If set, any collider for which this closure returns false + /// If set, any collider for which this closure returns false will be excluded from the scene query. pub predicate: Option<&'a dyn Fn(ColliderHandle, &Collider) -> bool>, } |
