aboutsummaryrefslogtreecommitdiff
path: root/src/pipeline/event_handler.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-07-04 15:04:06 +0200
committerSébastien Crozet <developer@crozet.re>2022-07-04 15:04:06 +0200
commit158308ad715d00f2c0f259b185bf0410395b1aac (patch)
tree243ea954686a15b125c453c357d58c3eb562c94a /src/pipeline/event_handler.rs
parent1121b07d523ea9441025f2b40574e2b6c2477a88 (diff)
downloadrapier-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/event_handler.rs')
-rw-r--r--src/pipeline/event_handler.rs31
1 files changed, 1 insertions, 30 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);
}
}