From 78c8bc6cdef26d14c57d0eeb23188cba592961bf Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 23 Jan 2022 16:50:02 +0100 Subject: Improve cfm configuration using the critical damping factor --- .../solver/velocity_ground_constraint_element.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/dynamics/solver/velocity_ground_constraint_element.rs') diff --git a/src/dynamics/solver/velocity_ground_constraint_element.rs b/src/dynamics/solver/velocity_ground_constraint_element.rs index a843905..8057030 100644 --- a/src/dynamics/solver/velocity_ground_constraint_element.rs +++ b/src/dynamics/solver/velocity_ground_constraint_element.rs @@ -109,12 +109,17 @@ impl VelocityGroundConstraintNormalPart { } #[inline] - pub fn solve(&mut self, dir1: &Vector, im2: &Vector, mj_lambda2: &mut DeltaVel) - where + pub fn solve( + &mut self, + cfm_factor: N, + dir1: &Vector, + im2: &Vector, + mj_lambda2: &mut DeltaVel, + ) where AngVector: WDot, Result = N>, { let dvel = -dir1.dot(&mj_lambda2.linear) + self.gcross2.gdot(mj_lambda2.angular) + self.rhs; - let new_impulse = (self.impulse - self.r * dvel).simd_max(N::zero()); + let new_impulse = cfm_factor * (self.impulse - self.r * dvel).simd_max(N::zero()); let dlambda = new_impulse - self.impulse; self.impulse = new_impulse; @@ -139,6 +144,7 @@ impl VelocityGroundConstraintElement { #[inline] pub fn solve_group( + cfm_factor: N, elements: &mut [Self], dir1: &Vector, #[cfg(feature = "dim3")] tangent1: &Vector, @@ -155,7 +161,9 @@ impl VelocityGroundConstraintElement { // Solve penetration. if solve_normal { for element in elements.iter_mut() { - element.normal_part.solve(&dir1, im2, mj_lambda2); + element + .normal_part + .solve(cfm_factor, &dir1, im2, mj_lambda2); } } -- cgit