angular-only hinge updated
[blender.git] / extern / bullet2 / src / BulletDynamics / ConstraintSolver / btHingeConstraint.cpp
index b507e4c7bb8d8da6f74acc01121b5ee887cbbb1e..7b2a9ba624447b6e9432ca0dd973d5868ae43df1 100644 (file)
@@ -200,6 +200,7 @@ void        btHingeConstraint::solveConstraint(btScalar     timeStep)
        btScalar damping = 1.f;
 
 //linear part
+       if (!m_angularOnly)
        {
                for (int i=0;i<3;i++)
                {               
@@ -226,44 +227,46 @@ void      btHingeConstraint::solveConstraint(btScalar     timeStep)
                }
        }
 
-       ///solve angular part
-
-       // get axes in world space
-       btVector3 axisA = getRigidBodyA().getCenterOfMassTransform().getBasis() * m_axisInA;
-       btVector3 axisB = getRigidBodyB().getCenterOfMassTransform().getBasis() * m_axisInB;
-
-       const btVector3& angVelA = getRigidBodyA().getAngularVelocity();
-       const btVector3& angVelB = getRigidBodyB().getAngularVelocity();
-       btVector3 angA = angVelA - axisA * axisA.dot(angVelA);
-       btVector3 angB = angVelB - axisB * axisB.dot(angVelB);
-       btVector3 velrel = angA-angB;
-
-       //solve angular velocity correction
-       float relaxation = 1.f;
-       float len = velrel.length();
-       if (len > 0.00001f)
-       {
-               btVector3 normal = velrel.normalized();
-               float denom = getRigidBodyA().computeAngularImpulseDenominator(normal) +
-                       getRigidBodyB().computeAngularImpulseDenominator(normal);
-               // scale for mass and relaxation
-               velrel *= (1.f/denom) * 0.9;
-       }
-
-       //solve angular positional correction
-       btVector3 angularError = -axisA.cross(axisB) *(1.f/timeStep);
-       float len2 = angularError.length();
-       if (len2>0.00001f)
+       
        {
-               btVector3 normal2 = angularError.normalized();
-               float denom2 = getRigidBodyA().computeAngularImpulseDenominator(normal2) +
-                               getRigidBodyB().computeAngularImpulseDenominator(normal2);
-               angularError *= (1.f/denom2) * relaxation;
-       }
+               ///solve angular part
+
+               // get axes in world space
+               btVector3 axisA = getRigidBodyA().getCenterOfMassTransform().getBasis() * m_axisInA;
+               btVector3 axisB = getRigidBodyB().getCenterOfMassTransform().getBasis() * m_axisInB;
+
+               const btVector3& angVelA = getRigidBodyA().getAngularVelocity();
+               const btVector3& angVelB = getRigidBodyB().getAngularVelocity();
+               btVector3 angA = angVelA - axisA * axisA.dot(angVelA);
+               btVector3 angB = angVelB - axisB * axisB.dot(angVelB);
+               btVector3 velrel = angA-angB;
+
+               //solve angular velocity correction
+               float relaxation = 1.f;
+               float len = velrel.length();
+               if (len > 0.00001f)
+               {
+                       btVector3 normal = velrel.normalized();
+                       float denom = getRigidBodyA().computeAngularImpulseDenominator(normal) +
+                               getRigidBodyB().computeAngularImpulseDenominator(normal);
+                       // scale for mass and relaxation
+                       velrel *= (1.f/denom) * 0.9;
+               }
 
-       m_rbA.applyTorqueImpulse(-velrel+angularError);
-       m_rbB.applyTorqueImpulse(velrel-angularError);
+               //solve angular positional correction
+               btVector3 angularError = -axisA.cross(axisB) *(1.f/timeStep);
+               float len2 = angularError.length();
+               if (len2>0.00001f)
+               {
+                       btVector3 normal2 = angularError.normalized();
+                       float denom2 = getRigidBodyA().computeAngularImpulseDenominator(normal2) +
+                                       getRigidBodyB().computeAngularImpulseDenominator(normal2);
+                       angularError *= (1.f/denom2) * relaxation;
+               }
 
+               m_rbA.applyTorqueImpulse(-velrel+angularError);
+               m_rbB.applyTorqueImpulse(velrel-angularError);
+       }
 #endif
 
 }