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 | |
| 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')
| -rw-r--r-- | src/dynamics/joint/generic_joint.rs | 22 | ||||
| -rw-r--r-- | src/geometry/mod.rs | 36 | ||||
| -rw-r--r-- | src/pipeline/event_handler.rs | 31 | ||||
| -rw-r--r-- | src/pipeline/query_pipeline.rs | 8 |
4 files changed, 52 insertions, 45 deletions
diff --git a/src/dynamics/joint/generic_joint.rs b/src/dynamics/joint/generic_joint.rs index 1cf96cb..bb1598d 100644 --- a/src/dynamics/joint/generic_joint.rs +++ b/src/dynamics/joint/generic_joint.rs @@ -278,17 +278,6 @@ impl GenericJoint { self } - /// Are contacts between the attached rigid-bodies enabled? - pub fn contacts_enabled(&self) -> bool { - self.contacts_enabled - } - - /// Sets whether contacts between the attached rigid-bodies are enabled. - pub fn set_contacts_enabled(&mut self, enabled: bool) -> &mut Self { - self.contacts_enabled = enabled; - self - } - /// The principal (local X) axis of this joint, expressed in the first rigid-body’s local-space. #[must_use] pub fn local_axis1(&self) -> UnitVector<Real> { @@ -337,6 +326,17 @@ impl GenericJoint { self } + /// Are contacts between the attached rigid-bodies enabled? + pub fn contacts_enabled(&self) -> bool { + self.contacts_enabled + } + + /// Sets whether contacts between the attached rigid-bodies are enabled. + pub fn set_contacts_enabled(&mut self, enabled: bool) -> &mut Self { + self.contacts_enabled = enabled; + self + } + /// The joint limits along the specified axis. #[must_use] pub fn limits(&self, axis: JointAxis) -> Option<&JointLimits<Real>> { diff --git a/src/geometry/mod.rs b/src/geometry/mod.rs index df9a785..ddb161e 100644 --- a/src/geometry/mod.rs +++ b/src/geometry/mod.rs @@ -140,6 +140,42 @@ pub struct ContactForceEvent { pub max_force_magnitude: Real, } +impl ContactForceEvent { + /// Init a contact force event from a contact pair. + pub fn from_contact_pair(dt: Real, pair: &ContactPair, total_force_magnitude: Real) -> Self { + let mut result = ContactForceEvent { + collider1: pair.collider1, + collider2: pair.collider2, + total_force_magnitude, + ..ContactForceEvent::default() + }; + + for m in &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; + result + } +} + pub(crate) use self::broad_phase_multi_sap::SAPProxyIndex; pub(crate) use self::narrow_phase::ContactManifoldIndex; pub(crate) use parry::partitioning::QBVH; 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>, } |
