From f9e3d382d2ee097dce05997735982f5e120cca03 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 15 Feb 2021 21:18:26 +0100 Subject: New contacts are bouncy, old are resting If a contact is new (previous impluse = 0), then we treat it as bouncy (respecting restitution). If the contact is old we treat it as resting. Exceptions for restitutions <=0 and >= 1. --- src/geometry/contact_pair.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/geometry') diff --git a/src/geometry/contact_pair.rs b/src/geometry/contact_pair.rs index 47f6678..462d3ef 100644 --- a/src/geometry/contact_pair.rs +++ b/src/geometry/contact_pair.rs @@ -128,6 +128,22 @@ pub struct SolverContact { pub data: ContactData, } +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; + if is_new { + // Treat new collisions as bouncing at first, unless we have zero restitution. + self.restitution > 0.0 + } else { + // If the contact is still here one step later, it is now a resting contact. + // The exception is very high restitutions, which can never rest + self.restitution >= 1.0 + } + } +} + impl Default for ContactManifoldData { fn default() -> Self { Self::new( -- cgit