Commit: 46ad2203057fbe4418120ab6dc1cb830e3d53958
Author: Sybren A. Stüvel
Date:   Fri Oct 9 09:29:31 2015 +0200
Branches: master
https://developer.blender.org/rB46ad2203057fbe4418120ab6dc1cb830e3d53958

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

===================================================================

M       source/gameengine/Physics/Bullet/CcdPhysicsController.cpp

===================================================================

diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp 
b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
index dbaa925..ab7097b 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())

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to