From 22dc2ca6c33afed8cceb577e9220bb7eeeb63d08 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Sat, 18 Feb 2012 09:21:16 +0000 Subject: [PATCH] fix for btGeneric6DofConstraint, when the btRotationalLimitMotor goes over PI or under -PI. See http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=5046&p=27113#p27113 Thanks zlash for the fix/report and Flix for the reminder. --- .../ConstraintSolver/btGeneric6DofConstraint.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp b/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp index 7c5e4f6e7..8ff9940bb 100644 --- a/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp +++ b/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp @@ -130,12 +130,20 @@ int btRotationalLimitMotor::testLimitValue(btScalar test_value) { m_currentLimit = 1;//low limit violation m_currentLimitError = test_value - m_loLimit; + if(m_currentLimitError>SIMD_PI) + m_currentLimitError-=SIMD_2_PI; + else if(m_currentLimitError<-SIMD_PI) + m_currentLimitError+=SIMD_2_PI; return 1; } else if (test_value> m_hiLimit) { m_currentLimit = 2;//High limit violation m_currentLimitError = test_value - m_hiLimit; + if(m_currentLimitError>SIMD_PI) + m_currentLimitError-=SIMD_2_PI; + else if(m_currentLimitError<-SIMD_PI) + m_currentLimitError+=SIMD_2_PI; return 2; }; @@ -1067,4 +1075,4 @@ void btGeneric6DofConstraint::setAxis(const btVector3& axis1,const btVector3& ax m_frameInB = m_rbB.getCenterOfMassTransform().inverse() * frameInW; calculateTransforms(); -} \ No newline at end of file +}