diff options
| author | Crozet Sébastien <developer@crozet.re> | 2021-03-28 11:26:53 +0200 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2021-03-28 11:27:07 +0200 |
| commit | 7306821c460ca3f77e697c89a79393e61c126624 (patch) | |
| tree | c8aa2a4d7d2c381706ee7edb60245bfd7bac7a07 /src/geometry | |
| parent | 710dd8d71ed53d2f52f15cdd19ee2f1248b62a96 (diff) | |
| download | rapier-7306821c460ca3f77e697c89a79393e61c126624.tar.gz rapier-7306821c460ca3f77e697c89a79393e61c126624.tar.bz2 rapier-7306821c460ca3f77e697c89a79393e61c126624.zip | |
Attenuate the warmstart impulse for CCD contacts.
CCD contacts result in very strong, instantaneous, impulses. So it is preferable to attenuate their contribution to subsequent timesteps to avoid overshooting.
Diffstat (limited to 'src/geometry')
| -rw-r--r-- | src/geometry/contact_pair.rs | 20 | ||||
| -rw-r--r-- | src/geometry/narrow_phase.rs | 4 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/geometry/contact_pair.rs b/src/geometry/contact_pair.rs index f156db5..ffd5d7f 100644 --- a/src/geometry/contact_pair.rs +++ b/src/geometry/contact_pair.rs @@ -38,6 +38,8 @@ pub struct ContactData { /// collider's rigid-body. #[cfg(feature = "dim3")] pub tangent_impulse: na::Vector2<Real>, + /// The target velocity correction at the contact point. + pub rhs: Real, } impl Default for ContactData { @@ -45,6 +47,7 @@ impl Default for ContactData { Self { impulse: 0.0, tangent_impulse: na::zero(), + rhs: 0.0, } } } @@ -143,16 +146,25 @@ pub struct SolverContact { /// This is set to zero by default. Set to a non-zero value to /// simulate, e.g., conveyor belts. pub tangent_velocity: Vector<Real>, - /// Associated contact data used to warm-start the constraints - /// solver. - pub data: ContactData, + /// The warmstart impulse, along the contact normal, applied by this contact to the first collider's rigid-body. + pub warmstart_impulse: Real, + /// The warmstart friction impulse along the vector orthonormal to the contact normal, applied to the first + /// collider's rigid-body. + #[cfg(feature = "dim2")] + pub warmstart_tangent_impulse: Real, + /// The warmstart friction impulses along the basis orthonormal to the contact normal, applied to the first + /// collider's rigid-body. + #[cfg(feature = "dim3")] + pub warmstart_tangent_impulse: na::Vector2<Real>, + /// The last velocity correction targeted by this contact. + pub prev_rhs: Real, } impl SolverContact { /// Should we treat this contact as a bouncy contact? /// If `true`, use [`Self::restitution`]. pub fn is_bouncy(&self) -> bool { - let is_new = self.data.impulse == 0.0; + let is_new = self.warmstart_impulse == 0.0; if is_new { // Treat new collisions as bouncing at first, unless we have zero restitution. self.restitution > 0.0 diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs index 92cf57d..372d056 100644 --- a/src/geometry/narrow_phase.rs +++ b/src/geometry/narrow_phase.rs @@ -584,7 +584,9 @@ impl NarrowPhase { friction, restitution, tangent_velocity: Vector::zeros(), - data: contact.data, + warmstart_impulse: contact.data.impulse, + warmstart_tangent_impulse: contact.data.tangent_impulse, + prev_rhs: contact.data.rhs, }; manifold.data.solver_contacts.push(solver_contact); |
