From 04595961cdd8efb9eb56236cd9933e021b9aa411 Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Mon, 19 Aug 2019 12:02:57 -0700 Subject: [PATCH] add velocity clamp to prevent deformable objects from going too fast --- .../btDeformableMultiBodyDynamicsWorld.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp b/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp index 354ce3304..60e3bbbbd 100644 --- a/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp +++ b/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp @@ -153,6 +153,19 @@ void btDeformableMultiBodyDynamicsWorld::integrateTransforms(btScalar timeStep) for (int j = 0; j < psb->m_nodes.size(); ++j) { btSoftBody::Node& node = psb->m_nodes[j]; + btScalar maxDisplacement = psb->getWorldInfo()->m_maxDisplacement; + btScalar clampDeltaV = maxDisplacement / timeStep; + for (int c = 0; c < 3; c++) + { + if (node.m_v[c] > clampDeltaV) + { + node.m_v[c] = clampDeltaV; + } + if (node.m_v[c] < -clampDeltaV) + { + node.m_v[c] = -clampDeltaV; + } + } node.m_x = node.m_q + timeStep * node.m_v; } }