From f53d0438ed63417684c961ece307f8dc57ac7a5c Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Thu, 25 Feb 2021 15:40:54 +0100 Subject: Contact modification: make the contact normal modifiable too. --- src/geometry/narrow_phase.rs | 3 +++ src/pipeline/physics_hooks.rs | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs index 28c53f1..9c635dc 100644 --- a/src/geometry/narrow_phase.rs +++ b/src/geometry/narrow_phase.rs @@ -594,6 +594,7 @@ impl NarrowPhase { let mut modifiable_solver_contacts = std::mem::replace(&mut manifold.data.solver_contacts, Vec::new()); let mut modifiable_user_data = manifold.data.user_data; + let mut modifiable_normal = manifold.data.normal; let mut context = ContactModificationContext { rigid_body1: rb1, @@ -604,12 +605,14 @@ impl NarrowPhase { collider2: co2, manifold, solver_contacts: &mut modifiable_solver_contacts, + normal: &mut modifiable_normal, user_data: &mut modifiable_user_data, }; hooks.modify_solver_contacts(&mut context); manifold.data.solver_contacts = modifiable_solver_contacts; + manifold.data.normal = modifiable_normal; manifold.data.user_data = modifiable_user_data; } } diff --git a/src/pipeline/physics_hooks.rs b/src/pipeline/physics_hooks.rs index 11ca485..c3621ea 100644 --- a/src/pipeline/physics_hooks.rs +++ b/src/pipeline/physics_hooks.rs @@ -19,7 +19,7 @@ pub struct PairFilterContext<'a> { pub collider2: &'a Collider, } -/// Context given to custom contact modifiers to modify the contacts seen by the constrainst solver. +/// Context given to custom contact modifiers to modify the contacts seen by the constraints solver. pub struct ContactModificationContext<'a> { /// The first collider involved in the potential collision. pub rigid_body1: &'a RigidBody, @@ -37,6 +37,8 @@ pub struct ContactModificationContext<'a> { pub manifold: &'a ContactManifold, /// The solver contacts that can be modified. pub solver_contacts: &'a mut Vec, + /// The contact normal that can be modified. + pub normal: &'a mut Vector, /// User-defined data attached to the manifold. // NOTE: we keep this a &'a mut u32 to emphasize the // fact that this can be modified. @@ -195,6 +197,8 @@ pub trait PhysicsHooks: Send + Sync { /// Each contact manifold is given a `u32` user-defined data that is persistent between /// timesteps (as long as the contact manifold exists). This user-defined data is initialized /// as 0 and can be modified in `context.user_data`. + /// + /// The world-space contact normal can be modified in `context.normal`. fn modify_solver_contacts(&self, _context: &mut ContactModificationContext) {} } -- cgit