From 46ad2203057fbe4418120ab6dc1cb830e3d53958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 9 Oct 2015 09:29:31 +0200 Subject: [PATCH] BGE Fix T41943: Zeroing out angular velocity not possible This patch makes it possible to zero out angular velocity. tiny angular velocities may cause instabilities, according to the discussion in T41943, so they are mapped to (0, 0, 0) instead. It also applies the same reasoning to the linear velocity, unifying the different approaches. Differential revision: D952 --- .../Physics/Bullet/CcdPhysicsController.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index dbaa925db08..ab7097b19ca 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -1283,7 +1283,13 @@ void CcdPhysicsController::ApplyForce(const MT_Vector3& forcein,bool local) void CcdPhysicsController::SetAngularVelocity(const MT_Vector3& ang_vel,bool local) { btVector3 angvel(ang_vel.x(),ang_vel.y(),ang_vel.z()); - if (m_object && angvel.length2() > (SIMD_EPSILON*SIMD_EPSILON)) + + /* Refuse tiny tiny velocities, as they might cause instabilities. */ + float vel_squared = angvel.length2(); + if (vel_squared > 0 && vel_squared <= (SIMD_EPSILON*SIMD_EPSILON)) + angvel = btVector3(0, 0, 0); + + if (m_object) { m_object->activate(true); if (m_object->isStaticObject()) @@ -1305,9 +1311,14 @@ void CcdPhysicsController::SetAngularVelocity(const MT_Vector3& ang_vel,bool lo } void CcdPhysicsController::SetLinearVelocity(const MT_Vector3& lin_vel,bool local) { - btVector3 linVel(lin_vel.x(),lin_vel.y(),lin_vel.z()); - if (m_object/* && linVel.length2() > (SIMD_EPSILON*SIMD_EPSILON)*/) + + /* Refuse tiny tiny velocities, as they might cause instabilities. */ + float vel_squared = linVel.length2(); + if (vel_squared > 0 && vel_squared <= (SIMD_EPSILON*SIMD_EPSILON)) + linVel = btVector3(0, 0, 0); + + if (m_object) { m_object->activate(true); if (m_object->isStaticObject())