From a42b7d93f1ba0fd28a1538369f9310ac68fb0340 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Thu, 9 Oct 2008 16:24:00 +0000 Subject: [PATCH] Stop resitution for resting contact, after n frames (can be controlled by btContactSolverInfo.m_restingContactRestitutionThreshold Thanks Jan Bender for bringing this up --- .../ConstraintSolver/btContactSolverInfo.h | 2 ++ .../btSequentialImpulseConstraintSolver.cpp | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h b/src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h index 916d4581f..6e382b2dd 100644 --- a/src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h +++ b/src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h @@ -44,6 +44,7 @@ struct btContactSolverInfoData btScalar m_warmstartingFactor; int m_solverMode; + int m_restingContactRestitutionThreshold; }; @@ -69,6 +70,7 @@ struct btContactSolverInfo : public btContactSolverInfoData m_linearSlop = btScalar(0.0); m_warmstartingFactor=btScalar(0.85); m_solverMode = SOLVER_RANDMIZE_ORDER | SOLVER_CACHE_FRIENDLY | SOLVER_USE_WARMSTARTING; + m_restingContactRestitutionThreshold = 2;//resting contact lifetime threshold to disable restitution } }; diff --git a/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp b/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp index b8afbd6aa..712ef1f00 100644 --- a/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp +++ b/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp @@ -718,11 +718,19 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol //solverConstraint.m_penetration = cp.getDistance(); solverConstraint.m_friction = cp.m_combinedFriction; - solverConstraint.m_restitution = restitutionCurve(rel_vel, cp.m_combinedRestitution); - if (solverConstraint.m_restitution <= btScalar(0.)) + + + if (cp.m_lifeTime>infoGlobal.m_restingContactRestitutionThreshold) { solverConstraint.m_restitution = 0.f; - }; + } else + { + solverConstraint.m_restitution = restitutionCurve(rel_vel, cp.m_combinedRestitution); + if (solverConstraint.m_restitution <= btScalar(0.)) + { + solverConstraint.m_restitution = 0.f; + }; + } btScalar penVel = -solverConstraint.m_penetration/infoGlobal.m_timeStep; @@ -1220,12 +1228,17 @@ void btSequentialImpulseConstraintSolver::prepareConstraints(btPersistentManifol cpd->m_penetration = cp.getDistance();///btScalar(info.m_numIterations); cpd->m_friction = cp.m_combinedFriction; - cpd->m_restitution = restitutionCurve(rel_vel, combinedRestitution); - if (cpd->m_restitution <= btScalar(0.)) + if (cp.m_lifeTime>info.m_restingContactRestitutionThreshold) { - cpd->m_restitution = btScalar(0.0); - - }; + cpd->m_restitution = 0.f; + } else + { + cpd->m_restitution = restitutionCurve(rel_vel, combinedRestitution); + if (cpd->m_restitution <= btScalar(0.)) + { + cpd->m_restitution = btScalar(0.0); + }; + } //restitution and penetration work in same direction so //rel_vel