|
@@ -4,8 +4,8 @@ Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
-Permission is granted to anyone to use this software for any purpose,
|
|
|
|
|
-including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
|
|
|
+Permission is granted to anyone to use this software for any purpose,
|
|
|
|
|
+including commercial applications, and to alter it and redistribute it freely,
|
|
|
subject to the following restrictions:
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
@@ -24,6 +24,8 @@ subject to the following restrictions:
|
|
|
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
|
|
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
|
|
|
|
|
|
|
|
#include "LinearMath/btIDebugDraw.h"
|
|
#include "LinearMath/btIDebugDraw.h"
|
|
|
|
|
+#include "LinearMath/btCpuFeatureUtility.h"
|
|
|
|
|
+
|
|
|
//#include "btJacobianEntry.h"
|
|
//#include "btJacobianEntry.h"
|
|
|
#include "LinearMath/btMinMax.h"
|
|
#include "LinearMath/btMinMax.h"
|
|
|
#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
|
|
#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
|
|
@@ -39,142 +41,262 @@ int gNumSplitImpulseRecoveries = 0;
|
|
|
|
|
|
|
|
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
|
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
|
|
|
|
|
|
|
-btSequentialImpulseConstraintSolver::btSequentialImpulseConstraintSolver()
|
|
|
|
|
-:m_btSeed2(0)
|
|
|
|
|
|
|
+
|
|
|
|
|
+///This is the scalar reference implementation of solving a single constraint row, the innerloop of the Projected Gauss Seidel/Sequential Impulse constraint solver
|
|
|
|
|
+///Below are optional SSE2 and SSE4/FMA3 versions. We assume most hardware has SSE2. For SSE4/FMA3 we perform a CPU feature check.
|
|
|
|
|
+static btSimdScalar gResolveSingleConstraintRowGeneric_scalar_reference(btSolverBody& body1, btSolverBody& body2, const btSolverConstraint& c)
|
|
|
{
|
|
{
|
|
|
|
|
+ btScalar deltaImpulse = c.m_rhs - btScalar(c.m_appliedImpulse)*c.m_cfm;
|
|
|
|
|
+ const btScalar deltaVel1Dotn = c.m_contactNormal1.dot(body1.internalGetDeltaLinearVelocity()) + c.m_relpos1CrossNormal.dot(body1.internalGetDeltaAngularVelocity());
|
|
|
|
|
+ const btScalar deltaVel2Dotn = c.m_contactNormal2.dot(body2.internalGetDeltaLinearVelocity()) + c.m_relpos2CrossNormal.dot(body2.internalGetDeltaAngularVelocity());
|
|
|
|
|
|
|
|
|
|
+ // const btScalar delta_rel_vel = deltaVel1Dotn-deltaVel2Dotn;
|
|
|
|
|
+ deltaImpulse -= deltaVel1Dotn*c.m_jacDiagABInv;
|
|
|
|
|
+ deltaImpulse -= deltaVel2Dotn*c.m_jacDiagABInv;
|
|
|
|
|
+
|
|
|
|
|
+ const btScalar sum = btScalar(c.m_appliedImpulse) + deltaImpulse;
|
|
|
|
|
+ if (sum < c.m_lowerLimit)
|
|
|
|
|
+ {
|
|
|
|
|
+ deltaImpulse = c.m_lowerLimit - c.m_appliedImpulse;
|
|
|
|
|
+ c.m_appliedImpulse = c.m_lowerLimit;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (sum > c.m_upperLimit)
|
|
|
|
|
+ {
|
|
|
|
|
+ deltaImpulse = c.m_upperLimit - c.m_appliedImpulse;
|
|
|
|
|
+ c.m_appliedImpulse = c.m_upperLimit;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ c.m_appliedImpulse = sum;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ body1.internalApplyImpulse(c.m_contactNormal1*body1.internalGetInvMass(), c.m_angularComponentA, deltaImpulse);
|
|
|
|
|
+ body2.internalApplyImpulse(c.m_contactNormal2*body2.internalGetInvMass(), c.m_angularComponentB, deltaImpulse);
|
|
|
|
|
+
|
|
|
|
|
+ return deltaImpulse;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-btSequentialImpulseConstraintSolver::~btSequentialImpulseConstraintSolver()
|
|
|
|
|
|
|
+
|
|
|
|
|
+static btSimdScalar gResolveSingleConstraintRowLowerLimit_scalar_reference(btSolverBody& body1, btSolverBody& body2, const btSolverConstraint& c)
|
|
|
{
|
|
{
|
|
|
|
|
+ btScalar deltaImpulse = c.m_rhs - btScalar(c.m_appliedImpulse)*c.m_cfm;
|
|
|
|
|
+ const btScalar deltaVel1Dotn = c.m_contactNormal1.dot(body1.internalGetDeltaLinearVelocity()) + c.m_relpos1CrossNormal.dot(body1.internalGetDeltaAngularVelocity());
|
|
|
|
|
+ const btScalar deltaVel2Dotn = c.m_contactNormal2.dot(body2.internalGetDeltaLinearVelocity()) + c.m_relpos2CrossNormal.dot(body2.internalGetDeltaAngularVelocity());
|
|
|
|
|
+
|
|
|
|
|
+ deltaImpulse -= deltaVel1Dotn*c.m_jacDiagABInv;
|
|
|
|
|
+ deltaImpulse -= deltaVel2Dotn*c.m_jacDiagABInv;
|
|
|
|
|
+ const btScalar sum = btScalar(c.m_appliedImpulse) + deltaImpulse;
|
|
|
|
|
+ if (sum < c.m_lowerLimit)
|
|
|
|
|
+ {
|
|
|
|
|
+ deltaImpulse = c.m_lowerLimit - c.m_appliedImpulse;
|
|
|
|
|
+ c.m_appliedImpulse = c.m_lowerLimit;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ c.m_appliedImpulse = sum;
|
|
|
|
|
+ }
|
|
|
|
|
+ body1.internalApplyImpulse(c.m_contactNormal1*body1.internalGetInvMass(), c.m_angularComponentA, deltaImpulse);
|
|
|
|
|
+ body2.internalApplyImpulse(c.m_contactNormal2*body2.internalGetInvMass(), c.m_angularComponentB, deltaImpulse);
|
|
|
|
|
+
|
|
|
|
|
+ return deltaImpulse;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
#ifdef USE_SIMD
|
|
#ifdef USE_SIMD
|
|
|
#include <emmintrin.h>
|
|
#include <emmintrin.h>
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
#define btVecSplat(x, e) _mm_shuffle_ps(x, x, _MM_SHUFFLE(e,e,e,e))
|
|
#define btVecSplat(x, e) _mm_shuffle_ps(x, x, _MM_SHUFFLE(e,e,e,e))
|
|
|
static inline __m128 btSimdDot3( __m128 vec0, __m128 vec1 )
|
|
static inline __m128 btSimdDot3( __m128 vec0, __m128 vec1 )
|
|
|
{
|
|
{
|
|
|
__m128 result = _mm_mul_ps( vec0, vec1);
|
|
__m128 result = _mm_mul_ps( vec0, vec1);
|
|
|
return _mm_add_ps( btVecSplat( result, 0 ), _mm_add_ps( btVecSplat( result, 1 ), btVecSplat( result, 2 ) ) );
|
|
return _mm_add_ps( btVecSplat( result, 0 ), _mm_add_ps( btVecSplat( result, 1 ), btVecSplat( result, 2 ) ) );
|
|
|
}
|
|
}
|
|
|
-#endif//USE_SIMD
|
|
|
|
|
|
|
+
|
|
|
|
|
+#if defined (BT_ALLOW_SSE4)
|
|
|
|
|
+#include <intrin.h>
|
|
|
|
|
+
|
|
|
|
|
+#define USE_FMA 1
|
|
|
|
|
+#define USE_FMA3_INSTEAD_FMA4 1
|
|
|
|
|
+#define USE_SSE4_DOT 1
|
|
|
|
|
+
|
|
|
|
|
+#define SSE4_DP(a, b) _mm_dp_ps(a, b, 0x7f)
|
|
|
|
|
+#define SSE4_DP_FP(a, b) _mm_cvtss_f32(_mm_dp_ps(a, b, 0x7f))
|
|
|
|
|
+
|
|
|
|
|
+#if USE_SSE4_DOT
|
|
|
|
|
+#define DOT_PRODUCT(a, b) SSE4_DP(a, b)
|
|
|
|
|
+#else
|
|
|
|
|
+#define DOT_PRODUCT(a, b) btSimdDot3(a, b)
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#if USE_FMA
|
|
|
|
|
+#if USE_FMA3_INSTEAD_FMA4
|
|
|
|
|
+// a*b + c
|
|
|
|
|
+#define FMADD(a, b, c) _mm_fmadd_ps(a, b, c)
|
|
|
|
|
+// -(a*b) + c
|
|
|
|
|
+#define FMNADD(a, b, c) _mm_fnmadd_ps(a, b, c)
|
|
|
|
|
+#else // USE_FMA3
|
|
|
|
|
+// a*b + c
|
|
|
|
|
+#define FMADD(a, b, c) _mm_macc_ps(a, b, c)
|
|
|
|
|
+// -(a*b) + c
|
|
|
|
|
+#define FMNADD(a, b, c) _mm_nmacc_ps(a, b, c)
|
|
|
|
|
+#endif
|
|
|
|
|
+#else // USE_FMA
|
|
|
|
|
+// c + a*b
|
|
|
|
|
+#define FMADD(a, b, c) _mm_add_ps(c, _mm_mul_ps(a, b))
|
|
|
|
|
+// c - a*b
|
|
|
|
|
+#define FMNADD(a, b, c) _mm_sub_ps(c, _mm_mul_ps(a, b))
|
|
|
|
|
+#endif
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
// Project Gauss Seidel or the equivalent Sequential Impulse
|
|
// Project Gauss Seidel or the equivalent Sequential Impulse
|
|
|
-void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowGenericSIMD(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& c)
|
|
|
|
|
|
|
+static btSimdScalar gResolveSingleConstraintRowGeneric_sse2(btSolverBody& body1, btSolverBody& body2, const btSolverConstraint& c)
|
|
|
{
|
|
{
|
|
|
-#ifdef USE_SIMD
|
|
|
|
|
__m128 cpAppliedImp = _mm_set1_ps(c.m_appliedImpulse);
|
|
__m128 cpAppliedImp = _mm_set1_ps(c.m_appliedImpulse);
|
|
|
__m128 lowerLimit1 = _mm_set1_ps(c.m_lowerLimit);
|
|
__m128 lowerLimit1 = _mm_set1_ps(c.m_lowerLimit);
|
|
|
__m128 upperLimit1 = _mm_set1_ps(c.m_upperLimit);
|
|
__m128 upperLimit1 = _mm_set1_ps(c.m_upperLimit);
|
|
|
- __m128 deltaImpulse = _mm_sub_ps(_mm_set1_ps(c.m_rhs), _mm_mul_ps(_mm_set1_ps(c.m_appliedImpulse),_mm_set1_ps(c.m_cfm)));
|
|
|
|
|
- __m128 deltaVel1Dotn = _mm_add_ps(btSimdDot3(c.m_contactNormal1.mVec128,body1.internalGetDeltaLinearVelocity().mVec128), btSimdDot3(c.m_relpos1CrossNormal.mVec128,body1.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
- __m128 deltaVel2Dotn = _mm_add_ps(btSimdDot3(c.m_contactNormal2.mVec128,body2.internalGetDeltaLinearVelocity().mVec128), btSimdDot3(c.m_relpos2CrossNormal.mVec128,body2.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
- deltaImpulse = _mm_sub_ps(deltaImpulse,_mm_mul_ps(deltaVel1Dotn,_mm_set1_ps(c.m_jacDiagABInv)));
|
|
|
|
|
- deltaImpulse = _mm_sub_ps(deltaImpulse,_mm_mul_ps(deltaVel2Dotn,_mm_set1_ps(c.m_jacDiagABInv)));
|
|
|
|
|
- btSimdScalar sum = _mm_add_ps(cpAppliedImp,deltaImpulse);
|
|
|
|
|
- btSimdScalar resultLowerLess,resultUpperLess;
|
|
|
|
|
- resultLowerLess = _mm_cmplt_ps(sum,lowerLimit1);
|
|
|
|
|
- resultUpperLess = _mm_cmplt_ps(sum,upperLimit1);
|
|
|
|
|
- __m128 lowMinApplied = _mm_sub_ps(lowerLimit1,cpAppliedImp);
|
|
|
|
|
- deltaImpulse = _mm_or_ps( _mm_and_ps(resultLowerLess, lowMinApplied), _mm_andnot_ps(resultLowerLess, deltaImpulse) );
|
|
|
|
|
- c.m_appliedImpulse = _mm_or_ps( _mm_and_ps(resultLowerLess, lowerLimit1), _mm_andnot_ps(resultLowerLess, sum) );
|
|
|
|
|
- __m128 upperMinApplied = _mm_sub_ps(upperLimit1,cpAppliedImp);
|
|
|
|
|
- deltaImpulse = _mm_or_ps( _mm_and_ps(resultUpperLess, deltaImpulse), _mm_andnot_ps(resultUpperLess, upperMinApplied) );
|
|
|
|
|
- c.m_appliedImpulse = _mm_or_ps( _mm_and_ps(resultUpperLess, c.m_appliedImpulse), _mm_andnot_ps(resultUpperLess, upperLimit1) );
|
|
|
|
|
- __m128 linearComponentA = _mm_mul_ps(c.m_contactNormal1.mVec128,body1.internalGetInvMass().mVec128);
|
|
|
|
|
- __m128 linearComponentB = _mm_mul_ps((c.m_contactNormal2).mVec128,body2.internalGetInvMass().mVec128);
|
|
|
|
|
|
|
+ btSimdScalar deltaImpulse = _mm_sub_ps(_mm_set1_ps(c.m_rhs), _mm_mul_ps(_mm_set1_ps(c.m_appliedImpulse), _mm_set1_ps(c.m_cfm)));
|
|
|
|
|
+ __m128 deltaVel1Dotn = _mm_add_ps(btSimdDot3(c.m_contactNormal1.mVec128, body1.internalGetDeltaLinearVelocity().mVec128), btSimdDot3(c.m_relpos1CrossNormal.mVec128, body1.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
+ __m128 deltaVel2Dotn = _mm_add_ps(btSimdDot3(c.m_contactNormal2.mVec128, body2.internalGetDeltaLinearVelocity().mVec128), btSimdDot3(c.m_relpos2CrossNormal.mVec128, body2.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
+ deltaImpulse = _mm_sub_ps(deltaImpulse, _mm_mul_ps(deltaVel1Dotn, _mm_set1_ps(c.m_jacDiagABInv)));
|
|
|
|
|
+ deltaImpulse = _mm_sub_ps(deltaImpulse, _mm_mul_ps(deltaVel2Dotn, _mm_set1_ps(c.m_jacDiagABInv)));
|
|
|
|
|
+ btSimdScalar sum = _mm_add_ps(cpAppliedImp, deltaImpulse);
|
|
|
|
|
+ btSimdScalar resultLowerLess, resultUpperLess;
|
|
|
|
|
+ resultLowerLess = _mm_cmplt_ps(sum, lowerLimit1);
|
|
|
|
|
+ resultUpperLess = _mm_cmplt_ps(sum, upperLimit1);
|
|
|
|
|
+ __m128 lowMinApplied = _mm_sub_ps(lowerLimit1, cpAppliedImp);
|
|
|
|
|
+ deltaImpulse = _mm_or_ps(_mm_and_ps(resultLowerLess, lowMinApplied), _mm_andnot_ps(resultLowerLess, deltaImpulse));
|
|
|
|
|
+ c.m_appliedImpulse = _mm_or_ps(_mm_and_ps(resultLowerLess, lowerLimit1), _mm_andnot_ps(resultLowerLess, sum));
|
|
|
|
|
+ __m128 upperMinApplied = _mm_sub_ps(upperLimit1, cpAppliedImp);
|
|
|
|
|
+ deltaImpulse = _mm_or_ps(_mm_and_ps(resultUpperLess, deltaImpulse), _mm_andnot_ps(resultUpperLess, upperMinApplied));
|
|
|
|
|
+ c.m_appliedImpulse = _mm_or_ps(_mm_and_ps(resultUpperLess, c.m_appliedImpulse), _mm_andnot_ps(resultUpperLess, upperLimit1));
|
|
|
|
|
+ __m128 linearComponentA = _mm_mul_ps(c.m_contactNormal1.mVec128, body1.internalGetInvMass().mVec128);
|
|
|
|
|
+ __m128 linearComponentB = _mm_mul_ps((c.m_contactNormal2).mVec128, body2.internalGetInvMass().mVec128);
|
|
|
__m128 impulseMagnitude = deltaImpulse;
|
|
__m128 impulseMagnitude = deltaImpulse;
|
|
|
- body1.internalGetDeltaLinearVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaLinearVelocity().mVec128,_mm_mul_ps(linearComponentA,impulseMagnitude));
|
|
|
|
|
- body1.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaAngularVelocity().mVec128 ,_mm_mul_ps(c.m_angularComponentA.mVec128,impulseMagnitude));
|
|
|
|
|
- body2.internalGetDeltaLinearVelocity().mVec128 = _mm_add_ps(body2.internalGetDeltaLinearVelocity().mVec128,_mm_mul_ps(linearComponentB,impulseMagnitude));
|
|
|
|
|
- body2.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body2.internalGetDeltaAngularVelocity().mVec128 ,_mm_mul_ps(c.m_angularComponentB.mVec128,impulseMagnitude));
|
|
|
|
|
-#else
|
|
|
|
|
- resolveSingleConstraintRowGeneric(body1,body2,c);
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
+ body1.internalGetDeltaLinearVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaLinearVelocity().mVec128, _mm_mul_ps(linearComponentA, impulseMagnitude));
|
|
|
|
|
+ body1.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaAngularVelocity().mVec128, _mm_mul_ps(c.m_angularComponentA.mVec128, impulseMagnitude));
|
|
|
|
|
+ body2.internalGetDeltaLinearVelocity().mVec128 = _mm_add_ps(body2.internalGetDeltaLinearVelocity().mVec128, _mm_mul_ps(linearComponentB, impulseMagnitude));
|
|
|
|
|
+ body2.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body2.internalGetDeltaAngularVelocity().mVec128, _mm_mul_ps(c.m_angularComponentB.mVec128, impulseMagnitude));
|
|
|
|
|
+ return deltaImpulse;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Project Gauss Seidel or the equivalent Sequential Impulse
|
|
|
|
|
- void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowGeneric(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& c)
|
|
|
|
|
|
|
+
|
|
|
|
|
+// Enhanced version of gResolveSingleConstraintRowGeneric_sse2 with SSE4.1 and FMA3
|
|
|
|
|
+static btSimdScalar gResolveSingleConstraintRowGeneric_sse4_1_fma3(btSolverBody& body1, btSolverBody& body2, const btSolverConstraint& c)
|
|
|
{
|
|
{
|
|
|
- btScalar deltaImpulse = c.m_rhs-btScalar(c.m_appliedImpulse)*c.m_cfm;
|
|
|
|
|
- const btScalar deltaVel1Dotn = c.m_contactNormal1.dot(body1.internalGetDeltaLinearVelocity()) + c.m_relpos1CrossNormal.dot(body1.internalGetDeltaAngularVelocity());
|
|
|
|
|
- const btScalar deltaVel2Dotn = c.m_contactNormal2.dot(body2.internalGetDeltaLinearVelocity()) + c.m_relpos2CrossNormal.dot(body2.internalGetDeltaAngularVelocity());
|
|
|
|
|
|
|
+#if defined (BT_ALLOW_SSE4)
|
|
|
|
|
+ __m128 tmp = _mm_set_ps1(c.m_jacDiagABInv);
|
|
|
|
|
+ __m128 deltaImpulse = _mm_set_ps1(c.m_rhs - btScalar(c.m_appliedImpulse)*c.m_cfm);
|
|
|
|
|
+ const __m128 lowerLimit = _mm_set_ps1(c.m_lowerLimit);
|
|
|
|
|
+ const __m128 upperLimit = _mm_set_ps1(c.m_upperLimit);
|
|
|
|
|
+ const __m128 deltaVel1Dotn = _mm_add_ps(DOT_PRODUCT(c.m_contactNormal1.mVec128, body1.internalGetDeltaLinearVelocity().mVec128), DOT_PRODUCT(c.m_relpos1CrossNormal.mVec128, body1.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
+ const __m128 deltaVel2Dotn = _mm_add_ps(DOT_PRODUCT(c.m_contactNormal2.mVec128, body2.internalGetDeltaLinearVelocity().mVec128), DOT_PRODUCT(c.m_relpos2CrossNormal.mVec128, body2.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
+ deltaImpulse = FMNADD(deltaVel1Dotn, tmp, deltaImpulse);
|
|
|
|
|
+ deltaImpulse = FMNADD(deltaVel2Dotn, tmp, deltaImpulse);
|
|
|
|
|
+ tmp = _mm_add_ps(c.m_appliedImpulse, deltaImpulse); // sum
|
|
|
|
|
+ const __m128 maskLower = _mm_cmpgt_ps(tmp, lowerLimit);
|
|
|
|
|
+ const __m128 maskUpper = _mm_cmpgt_ps(upperLimit, tmp);
|
|
|
|
|
+ deltaImpulse = _mm_blendv_ps(_mm_sub_ps(lowerLimit, c.m_appliedImpulse), _mm_blendv_ps(_mm_sub_ps(upperLimit, c.m_appliedImpulse), deltaImpulse, maskUpper), maskLower);
|
|
|
|
|
+ c.m_appliedImpulse = _mm_blendv_ps(lowerLimit, _mm_blendv_ps(upperLimit, tmp, maskUpper), maskLower);
|
|
|
|
|
+ body1.internalGetDeltaLinearVelocity().mVec128 = FMADD(_mm_mul_ps(c.m_contactNormal1.mVec128, body1.internalGetInvMass().mVec128), deltaImpulse, body1.internalGetDeltaLinearVelocity().mVec128);
|
|
|
|
|
+ body1.internalGetDeltaAngularVelocity().mVec128 = FMADD(c.m_angularComponentA.mVec128, deltaImpulse, body1.internalGetDeltaAngularVelocity().mVec128);
|
|
|
|
|
+ body2.internalGetDeltaLinearVelocity().mVec128 = FMADD(_mm_mul_ps(c.m_contactNormal2.mVec128, body2.internalGetInvMass().mVec128), deltaImpulse, body2.internalGetDeltaLinearVelocity().mVec128);
|
|
|
|
|
+ body2.internalGetDeltaAngularVelocity().mVec128 = FMADD(c.m_angularComponentB.mVec128, deltaImpulse, body2.internalGetDeltaAngularVelocity().mVec128);
|
|
|
|
|
+ return deltaImpulse;
|
|
|
|
|
+#else
|
|
|
|
|
+ return gResolveSingleConstraintRowGeneric_sse2(body1,body2,c);
|
|
|
|
|
+#endif
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-// const btScalar delta_rel_vel = deltaVel1Dotn-deltaVel2Dotn;
|
|
|
|
|
- deltaImpulse -= deltaVel1Dotn*c.m_jacDiagABInv;
|
|
|
|
|
- deltaImpulse -= deltaVel2Dotn*c.m_jacDiagABInv;
|
|
|
|
|
|
|
|
|
|
- const btScalar sum = btScalar(c.m_appliedImpulse) + deltaImpulse;
|
|
|
|
|
- if (sum < c.m_lowerLimit)
|
|
|
|
|
- {
|
|
|
|
|
- deltaImpulse = c.m_lowerLimit-c.m_appliedImpulse;
|
|
|
|
|
- c.m_appliedImpulse = c.m_lowerLimit;
|
|
|
|
|
- }
|
|
|
|
|
- else if (sum > c.m_upperLimit)
|
|
|
|
|
- {
|
|
|
|
|
- deltaImpulse = c.m_upperLimit-c.m_appliedImpulse;
|
|
|
|
|
- c.m_appliedImpulse = c.m_upperLimit;
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- c.m_appliedImpulse = sum;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- body1.internalApplyImpulse(c.m_contactNormal1*body1.internalGetInvMass(),c.m_angularComponentA,deltaImpulse);
|
|
|
|
|
- body2.internalApplyImpulse(c.m_contactNormal2*body2.internalGetInvMass(),c.m_angularComponentB,deltaImpulse);
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
- void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowLowerLimitSIMD(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& c)
|
|
|
|
|
|
|
+static btSimdScalar gResolveSingleConstraintRowLowerLimit_sse2(btSolverBody& body1, btSolverBody& body2, const btSolverConstraint& c)
|
|
|
{
|
|
{
|
|
|
-#ifdef USE_SIMD
|
|
|
|
|
__m128 cpAppliedImp = _mm_set1_ps(c.m_appliedImpulse);
|
|
__m128 cpAppliedImp = _mm_set1_ps(c.m_appliedImpulse);
|
|
|
__m128 lowerLimit1 = _mm_set1_ps(c.m_lowerLimit);
|
|
__m128 lowerLimit1 = _mm_set1_ps(c.m_lowerLimit);
|
|
|
__m128 upperLimit1 = _mm_set1_ps(c.m_upperLimit);
|
|
__m128 upperLimit1 = _mm_set1_ps(c.m_upperLimit);
|
|
|
- __m128 deltaImpulse = _mm_sub_ps(_mm_set1_ps(c.m_rhs), _mm_mul_ps(_mm_set1_ps(c.m_appliedImpulse),_mm_set1_ps(c.m_cfm)));
|
|
|
|
|
- __m128 deltaVel1Dotn = _mm_add_ps(btSimdDot3(c.m_contactNormal1.mVec128,body1.internalGetDeltaLinearVelocity().mVec128), btSimdDot3(c.m_relpos1CrossNormal.mVec128,body1.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
- __m128 deltaVel2Dotn = _mm_add_ps(btSimdDot3(c.m_contactNormal2.mVec128,body2.internalGetDeltaLinearVelocity().mVec128), btSimdDot3(c.m_relpos2CrossNormal.mVec128,body2.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
- deltaImpulse = _mm_sub_ps(deltaImpulse,_mm_mul_ps(deltaVel1Dotn,_mm_set1_ps(c.m_jacDiagABInv)));
|
|
|
|
|
- deltaImpulse = _mm_sub_ps(deltaImpulse,_mm_mul_ps(deltaVel2Dotn,_mm_set1_ps(c.m_jacDiagABInv)));
|
|
|
|
|
- btSimdScalar sum = _mm_add_ps(cpAppliedImp,deltaImpulse);
|
|
|
|
|
- btSimdScalar resultLowerLess,resultUpperLess;
|
|
|
|
|
- resultLowerLess = _mm_cmplt_ps(sum,lowerLimit1);
|
|
|
|
|
- resultUpperLess = _mm_cmplt_ps(sum,upperLimit1);
|
|
|
|
|
- __m128 lowMinApplied = _mm_sub_ps(lowerLimit1,cpAppliedImp);
|
|
|
|
|
- deltaImpulse = _mm_or_ps( _mm_and_ps(resultLowerLess, lowMinApplied), _mm_andnot_ps(resultLowerLess, deltaImpulse) );
|
|
|
|
|
- c.m_appliedImpulse = _mm_or_ps( _mm_and_ps(resultLowerLess, lowerLimit1), _mm_andnot_ps(resultLowerLess, sum) );
|
|
|
|
|
- __m128 linearComponentA = _mm_mul_ps(c.m_contactNormal1.mVec128,body1.internalGetInvMass().mVec128);
|
|
|
|
|
- __m128 linearComponentB = _mm_mul_ps(c.m_contactNormal2.mVec128,body2.internalGetInvMass().mVec128);
|
|
|
|
|
|
|
+ btSimdScalar deltaImpulse = _mm_sub_ps(_mm_set1_ps(c.m_rhs), _mm_mul_ps(_mm_set1_ps(c.m_appliedImpulse), _mm_set1_ps(c.m_cfm)));
|
|
|
|
|
+ __m128 deltaVel1Dotn = _mm_add_ps(btSimdDot3(c.m_contactNormal1.mVec128, body1.internalGetDeltaLinearVelocity().mVec128), btSimdDot3(c.m_relpos1CrossNormal.mVec128, body1.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
+ __m128 deltaVel2Dotn = _mm_add_ps(btSimdDot3(c.m_contactNormal2.mVec128, body2.internalGetDeltaLinearVelocity().mVec128), btSimdDot3(c.m_relpos2CrossNormal.mVec128, body2.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
+ deltaImpulse = _mm_sub_ps(deltaImpulse, _mm_mul_ps(deltaVel1Dotn, _mm_set1_ps(c.m_jacDiagABInv)));
|
|
|
|
|
+ deltaImpulse = _mm_sub_ps(deltaImpulse, _mm_mul_ps(deltaVel2Dotn, _mm_set1_ps(c.m_jacDiagABInv)));
|
|
|
|
|
+ btSimdScalar sum = _mm_add_ps(cpAppliedImp, deltaImpulse);
|
|
|
|
|
+ btSimdScalar resultLowerLess, resultUpperLess;
|
|
|
|
|
+ resultLowerLess = _mm_cmplt_ps(sum, lowerLimit1);
|
|
|
|
|
+ resultUpperLess = _mm_cmplt_ps(sum, upperLimit1);
|
|
|
|
|
+ __m128 lowMinApplied = _mm_sub_ps(lowerLimit1, cpAppliedImp);
|
|
|
|
|
+ deltaImpulse = _mm_or_ps(_mm_and_ps(resultLowerLess, lowMinApplied), _mm_andnot_ps(resultLowerLess, deltaImpulse));
|
|
|
|
|
+ c.m_appliedImpulse = _mm_or_ps(_mm_and_ps(resultLowerLess, lowerLimit1), _mm_andnot_ps(resultLowerLess, sum));
|
|
|
|
|
+ __m128 linearComponentA = _mm_mul_ps(c.m_contactNormal1.mVec128, body1.internalGetInvMass().mVec128);
|
|
|
|
|
+ __m128 linearComponentB = _mm_mul_ps(c.m_contactNormal2.mVec128, body2.internalGetInvMass().mVec128);
|
|
|
__m128 impulseMagnitude = deltaImpulse;
|
|
__m128 impulseMagnitude = deltaImpulse;
|
|
|
- body1.internalGetDeltaLinearVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaLinearVelocity().mVec128,_mm_mul_ps(linearComponentA,impulseMagnitude));
|
|
|
|
|
- body1.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaAngularVelocity().mVec128 ,_mm_mul_ps(c.m_angularComponentA.mVec128,impulseMagnitude));
|
|
|
|
|
- body2.internalGetDeltaLinearVelocity().mVec128 = _mm_add_ps(body2.internalGetDeltaLinearVelocity().mVec128,_mm_mul_ps(linearComponentB,impulseMagnitude));
|
|
|
|
|
- body2.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body2.internalGetDeltaAngularVelocity().mVec128 ,_mm_mul_ps(c.m_angularComponentB.mVec128,impulseMagnitude));
|
|
|
|
|
|
|
+ body1.internalGetDeltaLinearVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaLinearVelocity().mVec128, _mm_mul_ps(linearComponentA, impulseMagnitude));
|
|
|
|
|
+ body1.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaAngularVelocity().mVec128, _mm_mul_ps(c.m_angularComponentA.mVec128, impulseMagnitude));
|
|
|
|
|
+ body2.internalGetDeltaLinearVelocity().mVec128 = _mm_add_ps(body2.internalGetDeltaLinearVelocity().mVec128, _mm_mul_ps(linearComponentB, impulseMagnitude));
|
|
|
|
|
+ body2.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body2.internalGetDeltaAngularVelocity().mVec128, _mm_mul_ps(c.m_angularComponentB.mVec128, impulseMagnitude));
|
|
|
|
|
+ return deltaImpulse;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// Enhanced version of gResolveSingleConstraintRowGeneric_sse2 with SSE4.1 and FMA3
|
|
|
|
|
+static btSimdScalar gResolveSingleConstraintRowLowerLimit_sse4_1_fma3(btSolverBody& body1, btSolverBody& body2, const btSolverConstraint& c)
|
|
|
|
|
+{
|
|
|
|
|
+#ifdef BT_ALLOW_SSE4
|
|
|
|
|
+ __m128 tmp = _mm_set_ps1(c.m_jacDiagABInv);
|
|
|
|
|
+ __m128 deltaImpulse = _mm_set_ps1(c.m_rhs - btScalar(c.m_appliedImpulse)*c.m_cfm);
|
|
|
|
|
+ const __m128 lowerLimit = _mm_set_ps1(c.m_lowerLimit);
|
|
|
|
|
+ const __m128 deltaVel1Dotn = _mm_add_ps(DOT_PRODUCT(c.m_contactNormal1.mVec128, body1.internalGetDeltaLinearVelocity().mVec128), DOT_PRODUCT(c.m_relpos1CrossNormal.mVec128, body1.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
+ const __m128 deltaVel2Dotn = _mm_add_ps(DOT_PRODUCT(c.m_contactNormal2.mVec128, body2.internalGetDeltaLinearVelocity().mVec128), DOT_PRODUCT(c.m_relpos2CrossNormal.mVec128, body2.internalGetDeltaAngularVelocity().mVec128));
|
|
|
|
|
+ deltaImpulse = FMNADD(deltaVel1Dotn, tmp, deltaImpulse);
|
|
|
|
|
+ deltaImpulse = FMNADD(deltaVel2Dotn, tmp, deltaImpulse);
|
|
|
|
|
+ tmp = _mm_add_ps(c.m_appliedImpulse, deltaImpulse);
|
|
|
|
|
+ const __m128 mask = _mm_cmpgt_ps(tmp, lowerLimit);
|
|
|
|
|
+ deltaImpulse = _mm_blendv_ps(_mm_sub_ps(lowerLimit, c.m_appliedImpulse), deltaImpulse, mask);
|
|
|
|
|
+ c.m_appliedImpulse = _mm_blendv_ps(lowerLimit, tmp, mask);
|
|
|
|
|
+ body1.internalGetDeltaLinearVelocity().mVec128 = FMADD(_mm_mul_ps(c.m_contactNormal1.mVec128, body1.internalGetInvMass().mVec128), deltaImpulse, body1.internalGetDeltaLinearVelocity().mVec128);
|
|
|
|
|
+ body1.internalGetDeltaAngularVelocity().mVec128 = FMADD(c.m_angularComponentA.mVec128, deltaImpulse, body1.internalGetDeltaAngularVelocity().mVec128);
|
|
|
|
|
+ body2.internalGetDeltaLinearVelocity().mVec128 = FMADD(_mm_mul_ps(c.m_contactNormal2.mVec128, body2.internalGetInvMass().mVec128), deltaImpulse, body2.internalGetDeltaLinearVelocity().mVec128);
|
|
|
|
|
+ body2.internalGetDeltaAngularVelocity().mVec128 = FMADD(c.m_angularComponentB.mVec128, deltaImpulse, body2.internalGetDeltaAngularVelocity().mVec128);
|
|
|
|
|
+ return deltaImpulse;
|
|
|
|
|
+#else
|
|
|
|
|
+ return gResolveSingleConstraintRowLowerLimit_sse2(body1,body2,c);
|
|
|
|
|
+#endif //BT_ALLOW_SSE4
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+#endif //USE_SIMD
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+btSimdScalar btSequentialImpulseConstraintSolver::resolveSingleConstraintRowGenericSIMD(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& c)
|
|
|
|
|
+{
|
|
|
|
|
+#ifdef USE_SIMD
|
|
|
|
|
+ return m_resolveSingleConstraintRowGeneric(body1, body2, c);
|
|
|
#else
|
|
#else
|
|
|
- resolveSingleConstraintRowLowerLimit(body1,body2,c);
|
|
|
|
|
|
|
+ return resolveSingleConstraintRowGeneric(body1,body2,c);
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Projected Gauss Seidel or the equivalent Sequential Impulse
|
|
|
|
|
- void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowLowerLimit(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& c)
|
|
|
|
|
|
|
+// Project Gauss Seidel or the equivalent Sequential Impulse
|
|
|
|
|
+btSimdScalar btSequentialImpulseConstraintSolver::resolveSingleConstraintRowGeneric(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& c)
|
|
|
{
|
|
{
|
|
|
- btScalar deltaImpulse = c.m_rhs-btScalar(c.m_appliedImpulse)*c.m_cfm;
|
|
|
|
|
- const btScalar deltaVel1Dotn = c.m_contactNormal1.dot(body1.internalGetDeltaLinearVelocity()) + c.m_relpos1CrossNormal.dot(body1.internalGetDeltaAngularVelocity());
|
|
|
|
|
- const btScalar deltaVel2Dotn = c.m_contactNormal2.dot(body2.internalGetDeltaLinearVelocity()) + c.m_relpos2CrossNormal.dot(body2.internalGetDeltaAngularVelocity());
|
|
|
|
|
|
|
+ return gResolveSingleConstraintRowGeneric_scalar_reference(body1, body2, c);
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- deltaImpulse -= deltaVel1Dotn*c.m_jacDiagABInv;
|
|
|
|
|
- deltaImpulse -= deltaVel2Dotn*c.m_jacDiagABInv;
|
|
|
|
|
- const btScalar sum = btScalar(c.m_appliedImpulse) + deltaImpulse;
|
|
|
|
|
- if (sum < c.m_lowerLimit)
|
|
|
|
|
- {
|
|
|
|
|
- deltaImpulse = c.m_lowerLimit-c.m_appliedImpulse;
|
|
|
|
|
- c.m_appliedImpulse = c.m_lowerLimit;
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- c.m_appliedImpulse = sum;
|
|
|
|
|
- }
|
|
|
|
|
- body1.internalApplyImpulse(c.m_contactNormal1*body1.internalGetInvMass(),c.m_angularComponentA,deltaImpulse);
|
|
|
|
|
- body2.internalApplyImpulse(c.m_contactNormal2*body2.internalGetInvMass(),c.m_angularComponentB,deltaImpulse);
|
|
|
|
|
|
|
+btSimdScalar btSequentialImpulseConstraintSolver::resolveSingleConstraintRowLowerLimitSIMD(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& c)
|
|
|
|
|
+{
|
|
|
|
|
+#ifdef USE_SIMD
|
|
|
|
|
+ return m_resolveSingleConstraintRowLowerLimit(body1, body2, c);
|
|
|
|
|
+#else
|
|
|
|
|
+ return resolveSingleConstraintRowLowerLimit(body1,body2,c);
|
|
|
|
|
+#endif
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+btSimdScalar btSequentialImpulseConstraintSolver::resolveSingleConstraintRowLowerLimit(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& c)
|
|
|
|
|
+{
|
|
|
|
|
+ return gResolveSingleConstraintRowLowerLimit_scalar_reference(body1,body2,c);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -243,6 +365,63 @@ void btSequentialImpulseConstraintSolver::resolveSplitPenetrationImpulseCacheFri
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ btSequentialImpulseConstraintSolver::btSequentialImpulseConstraintSolver()
|
|
|
|
|
+ : m_resolveSingleConstraintRowGeneric(gResolveSingleConstraintRowGeneric_scalar_reference),
|
|
|
|
|
+ m_resolveSingleConstraintRowLowerLimit(gResolveSingleConstraintRowLowerLimit_scalar_reference),
|
|
|
|
|
+ m_btSeed2(0)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+#ifdef USE_SIMD
|
|
|
|
|
+ m_resolveSingleConstraintRowGeneric = gResolveSingleConstraintRowGeneric_sse2;
|
|
|
|
|
+ m_resolveSingleConstraintRowLowerLimit=gResolveSingleConstraintRowLowerLimit_sse2;
|
|
|
|
|
+#endif //USE_SIMD
|
|
|
|
|
+
|
|
|
|
|
+#ifdef BT_ALLOW_SSE4
|
|
|
|
|
+ int cpuFeatures = btCpuFeatureUtility::getCpuFeatures();
|
|
|
|
|
+ if ((cpuFeatures & btCpuFeatureUtility::CPU_FEATURE_FMA3) && (cpuFeatures & btCpuFeatureUtility::CPU_FEATURE_SSE4_1))
|
|
|
|
|
+ {
|
|
|
|
|
+ m_resolveSingleConstraintRowGeneric = gResolveSingleConstraintRowGeneric_sse4_1_fma3;
|
|
|
|
|
+ m_resolveSingleConstraintRowLowerLimit = gResolveSingleConstraintRowLowerLimit_sse4_1_fma3;
|
|
|
|
|
+ }
|
|
|
|
|
+#endif//BT_ALLOW_SSE4
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ btSequentialImpulseConstraintSolver::~btSequentialImpulseConstraintSolver()
|
|
|
|
|
+ {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ btSingleConstraintRowSolver btSequentialImpulseConstraintSolver::getScalarConstraintRowSolverGeneric()
|
|
|
|
|
+ {
|
|
|
|
|
+ return gResolveSingleConstraintRowGeneric_scalar_reference;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ btSingleConstraintRowSolver btSequentialImpulseConstraintSolver::getScalarConstraintRowSolverLowerLimit()
|
|
|
|
|
+ {
|
|
|
|
|
+ return gResolveSingleConstraintRowLowerLimit_scalar_reference;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+#ifdef USE_SIMD
|
|
|
|
|
+ btSingleConstraintRowSolver btSequentialImpulseConstraintSolver::getSSE2ConstraintRowSolverGeneric()
|
|
|
|
|
+ {
|
|
|
|
|
+ return gResolveSingleConstraintRowGeneric_sse2;
|
|
|
|
|
+ }
|
|
|
|
|
+ btSingleConstraintRowSolver btSequentialImpulseConstraintSolver::getSSE2ConstraintRowSolverLowerLimit()
|
|
|
|
|
+ {
|
|
|
|
|
+ return gResolveSingleConstraintRowLowerLimit_sse2;
|
|
|
|
|
+ }
|
|
|
|
|
+#ifdef BT_ALLOW_SSE4
|
|
|
|
|
+ btSingleConstraintRowSolver btSequentialImpulseConstraintSolver::getSSE4_1ConstraintRowSolverGeneric()
|
|
|
|
|
+ {
|
|
|
|
|
+ return gResolveSingleConstraintRowGeneric_sse4_1_fma3;
|
|
|
|
|
+ }
|
|
|
|
|
+ btSingleConstraintRowSolver btSequentialImpulseConstraintSolver::getSSE4_1ConstraintRowSolverLowerLimit()
|
|
|
|
|
+ {
|
|
|
|
|
+ return gResolveSingleConstraintRowLowerLimit_sse4_1_fma3;
|
|
|
|
|
+ }
|
|
|
|
|
+#endif //BT_ALLOW_SSE4
|
|
|
|
|
+#endif //USE_SIMD
|
|
|
|
|
|
|
|
unsigned long btSequentialImpulseConstraintSolver::btRand2()
|
|
unsigned long btSequentialImpulseConstraintSolver::btRand2()
|
|
|
{
|
|
{
|
|
@@ -303,7 +482,7 @@ void btSequentialImpulseConstraintSolver::initSolverBody(btSolverBody* solverBod
|
|
|
solverBody->m_angularVelocity = rb->getAngularVelocity();
|
|
solverBody->m_angularVelocity = rb->getAngularVelocity();
|
|
|
solverBody->m_externalForceImpulse = rb->getTotalForce()*rb->getInvMass()*timeStep;
|
|
solverBody->m_externalForceImpulse = rb->getTotalForce()*rb->getInvMass()*timeStep;
|
|
|
solverBody->m_externalTorqueImpulse = rb->getTotalTorque()*rb->getInvInertiaTensorWorld()*timeStep ;
|
|
solverBody->m_externalTorqueImpulse = rb->getTotalTorque()*rb->getInvInertiaTensorWorld()*timeStep ;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
} else
|
|
} else
|
|
|
{
|
|
{
|
|
|
solverBody->m_worldTransform.setIdentity();
|
|
solverBody->m_worldTransform.setIdentity();
|
|
@@ -335,7 +514,7 @@ btScalar btSequentialImpulseConstraintSolver::restitutionCurve(btScalar rel_vel,
|
|
|
|
|
|
|
|
void btSequentialImpulseConstraintSolver::applyAnisotropicFriction(btCollisionObject* colObj,btVector3& frictionDirection, int frictionMode)
|
|
void btSequentialImpulseConstraintSolver::applyAnisotropicFriction(btCollisionObject* colObj,btVector3& frictionDirection, int frictionMode)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
if (colObj && colObj->hasAnisotropicFriction(frictionMode))
|
|
if (colObj && colObj->hasAnisotropicFriction(frictionMode))
|
|
|
{
|
|
{
|
|
@@ -356,7 +535,7 @@ void btSequentialImpulseConstraintSolver::applyAnisotropicFriction(btCollisionOb
|
|
|
void btSequentialImpulseConstraintSolver::setupFrictionConstraint(btSolverConstraint& solverConstraint, const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation, btScalar desiredVelocity, btScalar cfmSlip)
|
|
void btSequentialImpulseConstraintSolver::setupFrictionConstraint(btSolverConstraint& solverConstraint, const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation, btScalar desiredVelocity, btScalar cfmSlip)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
btSolverBody& solverBodyA = m_tmpSolverBodyPool[solverBodyIdA];
|
|
btSolverBody& solverBodyA = m_tmpSolverBodyPool[solverBodyIdA];
|
|
|
btSolverBody& solverBodyB = m_tmpSolverBodyPool[solverBodyIdB];
|
|
btSolverBody& solverBodyB = m_tmpSolverBodyPool[solverBodyIdB];
|
|
|
|
|
|
|
@@ -417,12 +596,12 @@ void btSequentialImpulseConstraintSolver::setupFrictionConstraint(btSolverConstr
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
btScalar rel_vel;
|
|
btScalar rel_vel;
|
|
|
- btScalar vel1Dotn = solverConstraint.m_contactNormal1.dot(body0?solverBodyA.m_linearVelocity+solverBodyA.m_externalForceImpulse:btVector3(0,0,0))
|
|
|
|
|
|
|
+ btScalar vel1Dotn = solverConstraint.m_contactNormal1.dot(body0?solverBodyA.m_linearVelocity+solverBodyA.m_externalForceImpulse:btVector3(0,0,0))
|
|
|
+ solverConstraint.m_relpos1CrossNormal.dot(body0?solverBodyA.m_angularVelocity:btVector3(0,0,0));
|
|
+ solverConstraint.m_relpos1CrossNormal.dot(body0?solverBodyA.m_angularVelocity:btVector3(0,0,0));
|
|
|
- btScalar vel2Dotn = solverConstraint.m_contactNormal2.dot(body1?solverBodyB.m_linearVelocity+solverBodyB.m_externalForceImpulse:btVector3(0,0,0))
|
|
|
|
|
|
|
+ btScalar vel2Dotn = solverConstraint.m_contactNormal2.dot(body1?solverBodyB.m_linearVelocity+solverBodyB.m_externalForceImpulse:btVector3(0,0,0))
|
|
|
+ solverConstraint.m_relpos2CrossNormal.dot(body1?solverBodyB.m_angularVelocity:btVector3(0,0,0));
|
|
+ solverConstraint.m_relpos2CrossNormal.dot(body1?solverBodyB.m_angularVelocity:btVector3(0,0,0));
|
|
|
|
|
|
|
|
rel_vel = vel1Dotn+vel2Dotn;
|
|
rel_vel = vel1Dotn+vel2Dotn;
|
|
@@ -431,12 +610,13 @@ void btSequentialImpulseConstraintSolver::setupFrictionConstraint(btSolverConstr
|
|
|
|
|
|
|
|
// Urho3D: possible friction fix from https://github.com/bulletphysics/bullet3/commit/907ac49892ede3f4a3295f7cbd96759107e5fc0e
|
|
// Urho3D: possible friction fix from https://github.com/bulletphysics/bullet3/commit/907ac49892ede3f4a3295f7cbd96759107e5fc0e
|
|
|
btScalar velocityError = desiredVelocity - rel_vel;
|
|
btScalar velocityError = desiredVelocity - rel_vel;
|
|
|
- btScalar velocityImpulse = velocityError * btScalar(solverConstraint.m_jacDiagABInv);
|
|
|
|
|
|
|
+ btScalar velocityImpulse = velocityError * btScalar(solverConstraint.m_jacDiagABInv);
|
|
|
solverConstraint.m_rhs = velocityImpulse;
|
|
solverConstraint.m_rhs = velocityImpulse;
|
|
|
|
|
+ solverConstraint.m_rhsPenetration = 0.f;
|
|
|
solverConstraint.m_cfm = cfmSlip;
|
|
solverConstraint.m_cfm = cfmSlip;
|
|
|
solverConstraint.m_lowerLimit = -solverConstraint.m_friction;
|
|
solverConstraint.m_lowerLimit = -solverConstraint.m_friction;
|
|
|
solverConstraint.m_upperLimit = solverConstraint.m_friction;
|
|
solverConstraint.m_upperLimit = solverConstraint.m_friction;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -444,7 +624,7 @@ btSolverConstraint& btSequentialImpulseConstraintSolver::addFrictionConstraint(c
|
|
|
{
|
|
{
|
|
|
btSolverConstraint& solverConstraint = m_tmpSolverContactFrictionConstraintPool.expandNonInitializing();
|
|
btSolverConstraint& solverConstraint = m_tmpSolverContactFrictionConstraintPool.expandNonInitializing();
|
|
|
solverConstraint.m_frictionIndex = frictionIndex;
|
|
solverConstraint.m_frictionIndex = frictionIndex;
|
|
|
- setupFrictionConstraint(solverConstraint, normalAxis, solverBodyIdA, solverBodyIdB, cp, rel_pos1, rel_pos2,
|
|
|
|
|
|
|
+ setupFrictionConstraint(solverConstraint, normalAxis, solverBodyIdA, solverBodyIdB, cp, rel_pos1, rel_pos2,
|
|
|
colObj0, colObj1, relaxation, desiredVelocity, cfmSlip);
|
|
colObj0, colObj1, relaxation, desiredVelocity, cfmSlip);
|
|
|
return solverConstraint;
|
|
return solverConstraint;
|
|
|
}
|
|
}
|
|
@@ -452,7 +632,7 @@ btSolverConstraint& btSequentialImpulseConstraintSolver::addFrictionConstraint(c
|
|
|
|
|
|
|
|
void btSequentialImpulseConstraintSolver::setupRollingFrictionConstraint( btSolverConstraint& solverConstraint, const btVector3& normalAxis1,int solverBodyIdA,int solverBodyIdB,
|
|
void btSequentialImpulseConstraintSolver::setupRollingFrictionConstraint( btSolverConstraint& solverConstraint, const btVector3& normalAxis1,int solverBodyIdA,int solverBodyIdB,
|
|
|
btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,
|
|
btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,
|
|
|
- btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation,
|
|
|
|
|
|
|
+ btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation,
|
|
|
btScalar desiredVelocity, btScalar cfmSlip)
|
|
btScalar desiredVelocity, btScalar cfmSlip)
|
|
|
|
|
|
|
|
{
|
|
{
|
|
@@ -498,12 +678,12 @@ void btSequentialImpulseConstraintSolver::setupRollingFrictionConstraint( btSolv
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
btScalar rel_vel;
|
|
btScalar rel_vel;
|
|
|
- btScalar vel1Dotn = solverConstraint.m_contactNormal1.dot(body0?solverBodyA.m_linearVelocity+solverBodyA.m_externalForceImpulse:btVector3(0,0,0))
|
|
|
|
|
|
|
+ btScalar vel1Dotn = solverConstraint.m_contactNormal1.dot(body0?solverBodyA.m_linearVelocity+solverBodyA.m_externalForceImpulse:btVector3(0,0,0))
|
|
|
+ solverConstraint.m_relpos1CrossNormal.dot(body0?solverBodyA.m_angularVelocity:btVector3(0,0,0));
|
|
+ solverConstraint.m_relpos1CrossNormal.dot(body0?solverBodyA.m_angularVelocity:btVector3(0,0,0));
|
|
|
- btScalar vel2Dotn = solverConstraint.m_contactNormal2.dot(body1?solverBodyB.m_linearVelocity+solverBodyB.m_externalForceImpulse:btVector3(0,0,0))
|
|
|
|
|
|
|
+ btScalar vel2Dotn = solverConstraint.m_contactNormal2.dot(body1?solverBodyB.m_linearVelocity+solverBodyB.m_externalForceImpulse:btVector3(0,0,0))
|
|
|
+ solverConstraint.m_relpos2CrossNormal.dot(body1?solverBodyB.m_angularVelocity:btVector3(0,0,0));
|
|
+ solverConstraint.m_relpos2CrossNormal.dot(body1?solverBodyB.m_angularVelocity:btVector3(0,0,0));
|
|
|
|
|
|
|
|
rel_vel = vel1Dotn+vel2Dotn;
|
|
rel_vel = vel1Dotn+vel2Dotn;
|
|
@@ -512,12 +692,12 @@ void btSequentialImpulseConstraintSolver::setupRollingFrictionConstraint( btSolv
|
|
|
|
|
|
|
|
// Urho3D: possible friction fix from https://github.com/bulletphysics/bullet3/commit/907ac49892ede3f4a3295f7cbd96759107e5fc0e
|
|
// Urho3D: possible friction fix from https://github.com/bulletphysics/bullet3/commit/907ac49892ede3f4a3295f7cbd96759107e5fc0e
|
|
|
btScalar velocityError = desiredVelocity - rel_vel;
|
|
btScalar velocityError = desiredVelocity - rel_vel;
|
|
|
- btScalar velocityImpulse = velocityError * btScalar(solverConstraint.m_jacDiagABInv);
|
|
|
|
|
|
|
+ btScalar velocityImpulse = velocityError * btScalar(solverConstraint.m_jacDiagABInv);
|
|
|
solverConstraint.m_rhs = velocityImpulse;
|
|
solverConstraint.m_rhs = velocityImpulse;
|
|
|
solverConstraint.m_cfm = cfmSlip;
|
|
solverConstraint.m_cfm = cfmSlip;
|
|
|
solverConstraint.m_lowerLimit = -solverConstraint.m_friction;
|
|
solverConstraint.m_lowerLimit = -solverConstraint.m_friction;
|
|
|
solverConstraint.m_upperLimit = solverConstraint.m_friction;
|
|
solverConstraint.m_upperLimit = solverConstraint.m_friction;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -532,7 +712,7 @@ btSolverConstraint& btSequentialImpulseConstraintSolver::addRollingFrictionConst
|
|
|
{
|
|
{
|
|
|
btSolverConstraint& solverConstraint = m_tmpSolverContactRollingFrictionConstraintPool.expandNonInitializing();
|
|
btSolverConstraint& solverConstraint = m_tmpSolverContactRollingFrictionConstraintPool.expandNonInitializing();
|
|
|
solverConstraint.m_frictionIndex = frictionIndex;
|
|
solverConstraint.m_frictionIndex = frictionIndex;
|
|
|
- setupRollingFrictionConstraint(solverConstraint, normalAxis, solverBodyIdA, solverBodyIdB, cp, rel_pos1, rel_pos2,
|
|
|
|
|
|
|
+ setupRollingFrictionConstraint(solverConstraint, normalAxis, solverBodyIdA, solverBodyIdB, cp, rel_pos1, rel_pos2,
|
|
|
colObj0, colObj1, relaxation, desiredVelocity, cfmSlip);
|
|
colObj0, colObj1, relaxation, desiredVelocity, cfmSlip);
|
|
|
return solverConstraint;
|
|
return solverConstraint;
|
|
|
}
|
|
}
|
|
@@ -560,7 +740,7 @@ int btSequentialImpulseConstraintSolver::getOrInitSolverBody(btCollisionObject&
|
|
|
body.setCompanionId(solverBodyIdA);
|
|
body.setCompanionId(solverBodyIdA);
|
|
|
} else
|
|
} else
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (m_fixedBodyId<0)
|
|
if (m_fixedBodyId<0)
|
|
|
{
|
|
{
|
|
|
m_fixedBodyId = m_tmpSolverBodyPool.size();
|
|
m_fixedBodyId = m_tmpSolverBodyPool.size();
|
|
@@ -578,15 +758,15 @@ int btSequentialImpulseConstraintSolver::getOrInitSolverBody(btCollisionObject&
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
-void btSequentialImpulseConstraintSolver::setupContactConstraint(btSolverConstraint& solverConstraint,
|
|
|
|
|
|
|
+void btSequentialImpulseConstraintSolver::setupContactConstraint(btSolverConstraint& solverConstraint,
|
|
|
int solverBodyIdA, int solverBodyIdB,
|
|
int solverBodyIdA, int solverBodyIdB,
|
|
|
btManifoldPoint& cp, const btContactSolverInfo& infoGlobal,
|
|
btManifoldPoint& cp, const btContactSolverInfo& infoGlobal,
|
|
|
btScalar& relaxation,
|
|
btScalar& relaxation,
|
|
|
const btVector3& rel_pos1, const btVector3& rel_pos2)
|
|
const btVector3& rel_pos1, const btVector3& rel_pos2)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
- const btVector3& pos1 = cp.getPositionWorldOnA();
|
|
|
|
|
- const btVector3& pos2 = cp.getPositionWorldOnB();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // const btVector3& pos1 = cp.getPositionWorldOnA();
|
|
|
|
|
+ // const btVector3& pos2 = cp.getPositionWorldOnB();
|
|
|
|
|
|
|
|
btSolverBody* bodyA = &m_tmpSolverBodyPool[solverBodyIdA];
|
|
btSolverBody* bodyA = &m_tmpSolverBodyPool[solverBodyIdA];
|
|
|
btSolverBody* bodyB = &m_tmpSolverBodyPool[solverBodyIdB];
|
|
btSolverBody* bodyB = &m_tmpSolverBodyPool[solverBodyIdB];
|
|
@@ -594,23 +774,23 @@ void btSequentialImpulseConstraintSolver::setupContactConstraint(btSolverConstra
|
|
|
btRigidBody* rb0 = bodyA->m_originalBody;
|
|
btRigidBody* rb0 = bodyA->m_originalBody;
|
|
|
btRigidBody* rb1 = bodyB->m_originalBody;
|
|
btRigidBody* rb1 = bodyB->m_originalBody;
|
|
|
|
|
|
|
|
-// btVector3 rel_pos1 = pos1 - colObj0->getWorldTransform().getOrigin();
|
|
|
|
|
|
|
+// btVector3 rel_pos1 = pos1 - colObj0->getWorldTransform().getOrigin();
|
|
|
// btVector3 rel_pos2 = pos2 - colObj1->getWorldTransform().getOrigin();
|
|
// btVector3 rel_pos2 = pos2 - colObj1->getWorldTransform().getOrigin();
|
|
|
- //rel_pos1 = pos1 - bodyA->getWorldTransform().getOrigin();
|
|
|
|
|
|
|
+ //rel_pos1 = pos1 - bodyA->getWorldTransform().getOrigin();
|
|
|
//rel_pos2 = pos2 - bodyB->getWorldTransform().getOrigin();
|
|
//rel_pos2 = pos2 - bodyB->getWorldTransform().getOrigin();
|
|
|
|
|
|
|
|
relaxation = 1.f;
|
|
relaxation = 1.f;
|
|
|
|
|
|
|
|
btVector3 torqueAxis0 = rel_pos1.cross(cp.m_normalWorldOnB);
|
|
btVector3 torqueAxis0 = rel_pos1.cross(cp.m_normalWorldOnB);
|
|
|
solverConstraint.m_angularComponentA = rb0 ? rb0->getInvInertiaTensorWorld()*torqueAxis0*rb0->getAngularFactor() : btVector3(0,0,0);
|
|
solverConstraint.m_angularComponentA = rb0 ? rb0->getInvInertiaTensorWorld()*torqueAxis0*rb0->getAngularFactor() : btVector3(0,0,0);
|
|
|
- btVector3 torqueAxis1 = rel_pos2.cross(cp.m_normalWorldOnB);
|
|
|
|
|
|
|
+ btVector3 torqueAxis1 = rel_pos2.cross(cp.m_normalWorldOnB);
|
|
|
solverConstraint.m_angularComponentB = rb1 ? rb1->getInvInertiaTensorWorld()*-torqueAxis1*rb1->getAngularFactor() : btVector3(0,0,0);
|
|
solverConstraint.m_angularComponentB = rb1 ? rb1->getInvInertiaTensorWorld()*-torqueAxis1*rb1->getAngularFactor() : btVector3(0,0,0);
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
#ifdef COMPUTE_IMPULSE_DENOM
|
|
#ifdef COMPUTE_IMPULSE_DENOM
|
|
|
btScalar denom0 = rb0->computeImpulseDenominator(pos1,cp.m_normalWorldOnB);
|
|
btScalar denom0 = rb0->computeImpulseDenominator(pos1,cp.m_normalWorldOnB);
|
|
|
btScalar denom1 = rb1->computeImpulseDenominator(pos2,cp.m_normalWorldOnB);
|
|
btScalar denom1 = rb1->computeImpulseDenominator(pos2,cp.m_normalWorldOnB);
|
|
|
-#else
|
|
|
|
|
|
|
+#else
|
|
|
btVector3 vec;
|
|
btVector3 vec;
|
|
|
btScalar denom0 = 0.f;
|
|
btScalar denom0 = 0.f;
|
|
|
btScalar denom1 = 0.f;
|
|
btScalar denom1 = 0.f;
|
|
@@ -624,7 +804,7 @@ void btSequentialImpulseConstraintSolver::setupContactConstraint(btSolverConstra
|
|
|
vec = ( -solverConstraint.m_angularComponentB).cross(rel_pos2);
|
|
vec = ( -solverConstraint.m_angularComponentB).cross(rel_pos2);
|
|
|
denom1 = rb1->getInvMass() + cp.m_normalWorldOnB.dot(vec);
|
|
denom1 = rb1->getInvMass() + cp.m_normalWorldOnB.dot(vec);
|
|
|
}
|
|
}
|
|
|
-#endif //COMPUTE_IMPULSE_DENOM
|
|
|
|
|
|
|
+#endif //COMPUTE_IMPULSE_DENOM
|
|
|
|
|
|
|
|
btScalar denom = relaxation/(denom0+denom1);
|
|
btScalar denom = relaxation/(denom0+denom1);
|
|
|
solverConstraint.m_jacDiagABInv = denom;
|
|
solverConstraint.m_jacDiagABInv = denom;
|
|
@@ -662,11 +842,11 @@ void btSequentialImpulseConstraintSolver::setupContactConstraint(btSolverConstra
|
|
|
btVector3 vel = vel1 - vel2;
|
|
btVector3 vel = vel1 - vel2;
|
|
|
btScalar rel_vel = cp.m_normalWorldOnB.dot(vel);
|
|
btScalar rel_vel = cp.m_normalWorldOnB.dot(vel);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
solverConstraint.m_friction = cp.m_combinedFriction;
|
|
solverConstraint.m_friction = cp.m_combinedFriction;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
restitution = restitutionCurve(rel_vel, cp.m_combinedRestitution);
|
|
restitution = restitutionCurve(rel_vel, cp.m_combinedRestitution);
|
|
|
if (restitution <= btScalar(0.))
|
|
if (restitution <= btScalar(0.))
|
|
|
{
|
|
{
|
|
@@ -696,17 +876,17 @@ void btSequentialImpulseConstraintSolver::setupContactConstraint(btSolverConstra
|
|
|
btVector3 externalTorqueImpulseA = bodyA->m_originalBody ? bodyA->m_externalTorqueImpulse: btVector3(0,0,0);
|
|
btVector3 externalTorqueImpulseA = bodyA->m_originalBody ? bodyA->m_externalTorqueImpulse: btVector3(0,0,0);
|
|
|
btVector3 externalForceImpulseB = bodyB->m_originalBody ? bodyB->m_externalForceImpulse: btVector3(0,0,0);
|
|
btVector3 externalForceImpulseB = bodyB->m_originalBody ? bodyB->m_externalForceImpulse: btVector3(0,0,0);
|
|
|
btVector3 externalTorqueImpulseB = bodyB->m_originalBody ?bodyB->m_externalTorqueImpulse : btVector3(0,0,0);
|
|
btVector3 externalTorqueImpulseB = bodyB->m_originalBody ?bodyB->m_externalTorqueImpulse : btVector3(0,0,0);
|
|
|
-
|
|
|
|
|
|
|
|
|
|
- btScalar vel1Dotn = solverConstraint.m_contactNormal1.dot(bodyA->m_linearVelocity+externalForceImpulseA)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ btScalar vel1Dotn = solverConstraint.m_contactNormal1.dot(bodyA->m_linearVelocity+externalForceImpulseA)
|
|
|
+ solverConstraint.m_relpos1CrossNormal.dot(bodyA->m_angularVelocity+externalTorqueImpulseA);
|
|
+ solverConstraint.m_relpos1CrossNormal.dot(bodyA->m_angularVelocity+externalTorqueImpulseA);
|
|
|
- btScalar vel2Dotn = solverConstraint.m_contactNormal2.dot(bodyB->m_linearVelocity+externalForceImpulseB)
|
|
|
|
|
|
|
+ btScalar vel2Dotn = solverConstraint.m_contactNormal2.dot(bodyB->m_linearVelocity+externalForceImpulseB)
|
|
|
+ solverConstraint.m_relpos2CrossNormal.dot(bodyB->m_angularVelocity+externalTorqueImpulseB);
|
|
+ solverConstraint.m_relpos2CrossNormal.dot(bodyB->m_angularVelocity+externalTorqueImpulseB);
|
|
|
btScalar rel_vel = vel1Dotn+vel2Dotn;
|
|
btScalar rel_vel = vel1Dotn+vel2Dotn;
|
|
|
|
|
|
|
|
btScalar positionalError = 0.f;
|
|
btScalar positionalError = 0.f;
|
|
|
btScalar velocityError = restitution - rel_vel;// * damping;
|
|
btScalar velocityError = restitution - rel_vel;// * damping;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
btScalar erp = infoGlobal.m_erp2;
|
|
btScalar erp = infoGlobal.m_erp2;
|
|
|
if (!infoGlobal.m_splitImpulse || (penetration > infoGlobal.m_splitImpulsePenetrationThreshold))
|
|
if (!infoGlobal.m_splitImpulse || (penetration > infoGlobal.m_splitImpulsePenetrationThreshold))
|
|
@@ -751,7 +931,7 @@ void btSequentialImpulseConstraintSolver::setupContactConstraint(btSolverConstra
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-void btSequentialImpulseConstraintSolver::setFrictionConstraintImpulse( btSolverConstraint& solverConstraint,
|
|
|
|
|
|
|
+void btSequentialImpulseConstraintSolver::setFrictionConstraintImpulse( btSolverConstraint& solverConstraint,
|
|
|
int solverBodyIdA, int solverBodyIdB,
|
|
int solverBodyIdA, int solverBodyIdB,
|
|
|
btManifoldPoint& cp, const btContactSolverInfo& infoGlobal)
|
|
btManifoldPoint& cp, const btContactSolverInfo& infoGlobal)
|
|
|
{
|
|
{
|
|
@@ -816,7 +996,7 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
|
|
|
|
|
|
|
|
|
|
|
|
|
///avoid collision response between two static objects
|
|
///avoid collision response between two static objects
|
|
|
- if (!solverBodyA || (solverBodyA->m_invMass.isZero() && (!solverBodyB || solverBodyB->m_invMass.isZero())))
|
|
|
|
|
|
|
+ if (!solverBodyA || (solverBodyA->m_invMass.fuzzyZero() && (!solverBodyB || solverBodyB->m_invMass.fuzzyZero())))
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
int rollingFriction=1;
|
|
int rollingFriction=1;
|
|
@@ -830,7 +1010,7 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
|
|
|
btVector3 rel_pos1;
|
|
btVector3 rel_pos1;
|
|
|
btVector3 rel_pos2;
|
|
btVector3 rel_pos2;
|
|
|
btScalar relaxation;
|
|
btScalar relaxation;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
int frictionIndex = m_tmpSolverContactConstraintPool.size();
|
|
int frictionIndex = m_tmpSolverContactConstraintPool.size();
|
|
|
btSolverConstraint& solverConstraint = m_tmpSolverContactConstraintPool.expandNonInitializing();
|
|
btSolverConstraint& solverConstraint = m_tmpSolverContactConstraintPool.expandNonInitializing();
|
|
@@ -844,7 +1024,7 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
|
|
|
const btVector3& pos1 = cp.getPositionWorldOnA();
|
|
const btVector3& pos1 = cp.getPositionWorldOnA();
|
|
|
const btVector3& pos2 = cp.getPositionWorldOnB();
|
|
const btVector3& pos2 = cp.getPositionWorldOnB();
|
|
|
|
|
|
|
|
- rel_pos1 = pos1 - colObj0->getWorldTransform().getOrigin();
|
|
|
|
|
|
|
+ rel_pos1 = pos1 - colObj0->getWorldTransform().getOrigin();
|
|
|
rel_pos2 = pos2 - colObj1->getWorldTransform().getOrigin();
|
|
rel_pos2 = pos2 - colObj1->getWorldTransform().getOrigin();
|
|
|
|
|
|
|
|
btVector3 vel1;// = rb0 ? rb0->getVelocityInLocalPoint(rel_pos1) : btVector3(0,0,0);
|
|
btVector3 vel1;// = rb0 ? rb0->getVelocityInLocalPoint(rel_pos1) : btVector3(0,0,0);
|
|
@@ -852,13 +1032,13 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
|
|
|
|
|
|
|
|
solverBodyA->getVelocityInLocalPointNoDelta(rel_pos1,vel1);
|
|
solverBodyA->getVelocityInLocalPointNoDelta(rel_pos1,vel1);
|
|
|
solverBodyB->getVelocityInLocalPointNoDelta(rel_pos2,vel2 );
|
|
solverBodyB->getVelocityInLocalPointNoDelta(rel_pos2,vel2 );
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
btVector3 vel = vel1 - vel2;
|
|
btVector3 vel = vel1 - vel2;
|
|
|
btScalar rel_vel = cp.m_normalWorldOnB.dot(vel);
|
|
btScalar rel_vel = cp.m_normalWorldOnB.dot(vel);
|
|
|
|
|
|
|
|
setupContactConstraint(solverConstraint, solverBodyIdA, solverBodyIdB, cp, infoGlobal, relaxation, rel_pos1, rel_pos2);
|
|
setupContactConstraint(solverConstraint, solverBodyIdA, solverBodyIdB, cp, infoGlobal, relaxation, rel_pos1, rel_pos2);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
// const btVector3& pos1 = cp.getPositionWorldOnA();
|
|
// const btVector3& pos1 = cp.getPositionWorldOnA();
|
|
|
// const btVector3& pos2 = cp.getPositionWorldOnB();
|
|
// const btVector3& pos2 = cp.getPositionWorldOnB();
|
|
@@ -899,21 +1079,21 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
|
|
|
addRollingFrictionConstraint(axis0,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
|
addRollingFrictionConstraint(axis0,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
|
|
if (axis1.length()>0.001)
|
|
if (axis1.length()>0.001)
|
|
|
addRollingFrictionConstraint(axis1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
|
addRollingFrictionConstraint(axis1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
///Bullet has several options to set the friction directions
|
|
///Bullet has several options to set the friction directions
|
|
|
- ///By default, each contact has only a single friction direction that is recomputed automatically very frame
|
|
|
|
|
|
|
+ ///By default, each contact has only a single friction direction that is recomputed automatically very frame
|
|
|
///based on the relative linear velocity.
|
|
///based on the relative linear velocity.
|
|
|
///If the relative velocity it zero, it will automatically compute a friction direction.
|
|
///If the relative velocity it zero, it will automatically compute a friction direction.
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
///You can also enable two friction directions, using the SOLVER_USE_2_FRICTION_DIRECTIONS.
|
|
///You can also enable two friction directions, using the SOLVER_USE_2_FRICTION_DIRECTIONS.
|
|
|
///In that case, the second friction direction will be orthogonal to both contact normal and first friction direction.
|
|
///In that case, the second friction direction will be orthogonal to both contact normal and first friction direction.
|
|
|
///
|
|
///
|
|
|
///If you choose SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION, then the friction will be independent from the relative projected velocity.
|
|
///If you choose SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION, then the friction will be independent from the relative projected velocity.
|
|
|
///
|
|
///
|
|
|
- ///The user can manually override the friction directions for certain contacts using a contact callback,
|
|
|
|
|
|
|
+ ///The user can manually override the friction directions for certain contacts using a contact callback,
|
|
|
///and set the cp.m_lateralFrictionInitialized to true
|
|
///and set the cp.m_lateralFrictionInitialized to true
|
|
|
///In that case, you can set the target relative motion in each friction direction (cp.m_contactMotion1 and cp.m_contactMotion2)
|
|
///In that case, you can set the target relative motion in each friction direction (cp.m_contactMotion1 and cp.m_contactMotion2)
|
|
|
///this will give a conveyor belt effect
|
|
///this will give a conveyor belt effect
|
|
@@ -969,9 +1149,9 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
setFrictionConstraintImpulse( solverConstraint, solverBodyIdA, solverBodyIdB, cp, infoGlobal);
|
|
setFrictionConstraintImpulse( solverConstraint, solverBodyIdA, solverBodyIdB, cp, infoGlobal);
|
|
|
-
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1011,7 +1191,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|
|
bool found=false;
|
|
bool found=false;
|
|
|
for (int b=0;b<numBodies;b++)
|
|
for (int b=0;b<numBodies;b++)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (&constraint->getRigidBodyA()==bodies[b])
|
|
if (&constraint->getRigidBodyA()==bodies[b])
|
|
|
{
|
|
{
|
|
|
found = true;
|
|
found = true;
|
|
@@ -1043,7 +1223,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|
|
bool found=false;
|
|
bool found=false;
|
|
|
for (int b=0;b<numBodies;b++)
|
|
for (int b=0;b<numBodies;b++)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (manifoldPtr[i]->getBody0()==bodies[b])
|
|
if (manifoldPtr[i]->getBody0()==bodies[b])
|
|
|
{
|
|
{
|
|
|
found = true;
|
|
found = true;
|
|
@@ -1067,8 +1247,8 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
#endif //BT_ADDITIONAL_DEBUG
|
|
#endif //BT_ADDITIONAL_DEBUG
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
for (int i = 0; i < numBodies; i++)
|
|
for (int i = 0; i < numBodies; i++)
|
|
|
{
|
|
{
|
|
|
bodies[i]->setCompanionId(-1);
|
|
bodies[i]->setCompanionId(-1);
|
|
@@ -1083,6 +1263,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|
|
|
|
|
|
|
//convert all bodies
|
|
//convert all bodies
|
|
|
|
|
|
|
|
|
|
+
|
|
|
for (int i=0;i<numBodies;i++)
|
|
for (int i=0;i<numBodies;i++)
|
|
|
{
|
|
{
|
|
|
int bodyId = getOrInitSolverBody(*bodies[i],infoGlobal.m_timeStep);
|
|
int bodyId = getOrInitSolverBody(*bodies[i],infoGlobal.m_timeStep);
|
|
@@ -1092,14 +1273,27 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|
|
{
|
|
{
|
|
|
btSolverBody& solverBody = m_tmpSolverBodyPool[bodyId];
|
|
btSolverBody& solverBody = m_tmpSolverBodyPool[bodyId];
|
|
|
btVector3 gyroForce (0,0,0);
|
|
btVector3 gyroForce (0,0,0);
|
|
|
- if (body->getFlags()&BT_ENABLE_GYROPSCOPIC_FORCE)
|
|
|
|
|
|
|
+ if (body->getFlags()&BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT)
|
|
|
{
|
|
{
|
|
|
- gyroForce = body->computeGyroscopicForce(infoGlobal.m_maxGyroscopicForce);
|
|
|
|
|
|
|
+ gyroForce = body->computeGyroscopicForceExplicit(infoGlobal.m_maxGyroscopicForce);
|
|
|
solverBody.m_externalTorqueImpulse -= gyroForce*body->getInvInertiaTensorWorld()*infoGlobal.m_timeStep;
|
|
solverBody.m_externalTorqueImpulse -= gyroForce*body->getInvInertiaTensorWorld()*infoGlobal.m_timeStep;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (body->getFlags()&BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_WORLD)
|
|
|
|
|
+ {
|
|
|
|
|
+ gyroForce = body->computeGyroscopicImpulseImplicit_World(infoGlobal.m_timeStep);
|
|
|
|
|
+ solverBody.m_externalTorqueImpulse += gyroForce;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (body->getFlags()&BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_BODY)
|
|
|
|
|
+ {
|
|
|
|
|
+ gyroForce = body->computeGyroscopicImpulseImplicit_Body(infoGlobal.m_timeStep);
|
|
|
|
|
+ solverBody.m_externalTorqueImpulse += gyroForce;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (1)
|
|
if (1)
|
|
|
{
|
|
{
|
|
|
int j;
|
|
int j;
|
|
@@ -1119,7 +1313,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|
|
|
|
|
|
|
int totalNumRows = 0;
|
|
int totalNumRows = 0;
|
|
|
int i;
|
|
int i;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
m_tmpConstraintSizesPool.resizeNoInitialize(numConstraints);
|
|
m_tmpConstraintSizesPool.resizeNoInitialize(numConstraints);
|
|
|
//calculate the total number of contraint rows
|
|
//calculate the total number of contraint rows
|
|
|
for (i=0;i<numConstraints;i++)
|
|
for (i=0;i<numConstraints;i++)
|
|
@@ -1149,14 +1343,14 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|
|
}
|
|
}
|
|
|
m_tmpSolverNonContactConstraintPool.resizeNoInitialize(totalNumRows);
|
|
m_tmpSolverNonContactConstraintPool.resizeNoInitialize(totalNumRows);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
///setup the btSolverConstraints
|
|
///setup the btSolverConstraints
|
|
|
int currentRow = 0;
|
|
int currentRow = 0;
|
|
|
|
|
|
|
|
for (i=0;i<numConstraints;i++)
|
|
for (i=0;i<numConstraints;i++)
|
|
|
{
|
|
{
|
|
|
const btTypedConstraint::btConstraintInfo1& info1 = m_tmpConstraintSizesPool[i];
|
|
const btTypedConstraint::btConstraintInfo1& info1 = m_tmpConstraintSizesPool[i];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (info1.m_numConstraintRows)
|
|
if (info1.m_numConstraintRows)
|
|
|
{
|
|
{
|
|
|
btAssert(currentRow<totalNumRows);
|
|
btAssert(currentRow<totalNumRows);
|
|
@@ -1264,7 +1458,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
{
|
|
{
|
|
|
btScalar rel_vel;
|
|
btScalar rel_vel;
|
|
|
btVector3 externalForceImpulseA = bodyAPtr->m_originalBody ? bodyAPtr->m_externalForceImpulse : btVector3(0,0,0);
|
|
btVector3 externalForceImpulseA = bodyAPtr->m_originalBody ? bodyAPtr->m_externalForceImpulse : btVector3(0,0,0);
|
|
@@ -1272,11 +1466,11 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|
|
|
|
|
|
|
btVector3 externalForceImpulseB = bodyBPtr->m_originalBody ? bodyBPtr->m_externalForceImpulse : btVector3(0,0,0);
|
|
btVector3 externalForceImpulseB = bodyBPtr->m_originalBody ? bodyBPtr->m_externalForceImpulse : btVector3(0,0,0);
|
|
|
btVector3 externalTorqueImpulseB = bodyBPtr->m_originalBody ?bodyBPtr->m_externalTorqueImpulse : btVector3(0,0,0);
|
|
btVector3 externalTorqueImpulseB = bodyBPtr->m_originalBody ?bodyBPtr->m_externalTorqueImpulse : btVector3(0,0,0);
|
|
|
-
|
|
|
|
|
- btScalar vel1Dotn = solverConstraint.m_contactNormal1.dot(rbA.getLinearVelocity()+externalForceImpulseA)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ btScalar vel1Dotn = solverConstraint.m_contactNormal1.dot(rbA.getLinearVelocity()+externalForceImpulseA)
|
|
|
+ solverConstraint.m_relpos1CrossNormal.dot(rbA.getAngularVelocity()+externalTorqueImpulseA);
|
|
+ solverConstraint.m_relpos1CrossNormal.dot(rbA.getAngularVelocity()+externalTorqueImpulseA);
|
|
|
-
|
|
|
|
|
- btScalar vel2Dotn = solverConstraint.m_contactNormal2.dot(rbB.getLinearVelocity()+externalForceImpulseB)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ btScalar vel2Dotn = solverConstraint.m_contactNormal2.dot(rbB.getLinearVelocity()+externalForceImpulseB)
|
|
|
+ solverConstraint.m_relpos2CrossNormal.dot(rbB.getAngularVelocity()+externalTorqueImpulseB);
|
|
+ solverConstraint.m_relpos2CrossNormal.dot(rbB.getAngularVelocity()+externalTorqueImpulseB);
|
|
|
|
|
|
|
|
rel_vel = vel1Dotn+vel2Dotn;
|
|
rel_vel = vel1Dotn+vel2Dotn;
|
|
@@ -1342,7 +1536,7 @@ btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration
|
|
|
int numNonContactPool = m_tmpSolverNonContactConstraintPool.size();
|
|
int numNonContactPool = m_tmpSolverNonContactConstraintPool.size();
|
|
|
int numConstraintPool = m_tmpSolverContactConstraintPool.size();
|
|
int numConstraintPool = m_tmpSolverContactConstraintPool.size();
|
|
|
int numFrictionPool = m_tmpSolverContactFrictionConstraintPool.size();
|
|
int numFrictionPool = m_tmpSolverContactFrictionConstraintPool.size();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (infoGlobal.m_solverMode & SOLVER_RANDMIZE_ORDER)
|
|
if (infoGlobal.m_solverMode & SOLVER_RANDMIZE_ORDER)
|
|
|
{
|
|
{
|
|
|
if (1) // uncomment this for a bit less random ((iteration & 7) == 0)
|
|
if (1) // uncomment this for a bit less random ((iteration & 7) == 0)
|
|
@@ -1355,7 +1549,7 @@ btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration
|
|
|
m_orderNonContactConstraintPool[swapi] = tmp;
|
|
m_orderNonContactConstraintPool[swapi] = tmp;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //contact/friction constraints are not solved more than
|
|
|
|
|
|
|
+ //contact/friction constraints are not solved more than
|
|
|
if (iteration< infoGlobal.m_numIterations)
|
|
if (iteration< infoGlobal.m_numIterations)
|
|
|
{
|
|
{
|
|
|
for (int j=0; j<numConstraintPool; ++j) {
|
|
for (int j=0; j<numConstraintPool; ++j) {
|
|
@@ -1434,7 +1628,7 @@ btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
btSolverConstraint& solveManifold = m_tmpSolverContactFrictionConstraintPool[m_orderFrictionConstraintPool[c*multiplier+1]];
|
|
btSolverConstraint& solveManifold = m_tmpSolverContactFrictionConstraintPool[m_orderFrictionConstraintPool[c*multiplier+1]];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (totalImpulse>btScalar(0))
|
|
if (totalImpulse>btScalar(0))
|
|
|
{
|
|
{
|
|
|
solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse);
|
|
solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse);
|
|
@@ -1456,12 +1650,11 @@ btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration
|
|
|
for (j=0;j<numPoolConstraints;j++)
|
|
for (j=0;j<numPoolConstraints;j++)
|
|
|
{
|
|
{
|
|
|
const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]];
|
|
const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]];
|
|
|
- //resolveSingleConstraintRowLowerLimitSIMD(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA],m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold);
|
|
|
|
|
- resolveSingleConstraintRowLowerLimit(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA],m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold);
|
|
|
|
|
|
|
+ resolveSingleConstraintRowLowerLimitSIMD(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA],m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
///solve all friction constraints, using SIMD, if available
|
|
///solve all friction constraints, using SIMD, if available
|
|
|
|
|
|
|
@@ -1476,12 +1669,11 @@ btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration
|
|
|
solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse);
|
|
solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse);
|
|
|
solveManifold.m_upperLimit = solveManifold.m_friction*totalImpulse;
|
|
solveManifold.m_upperLimit = solveManifold.m_friction*totalImpulse;
|
|
|
|
|
|
|
|
- //resolveSingleConstraintRowGenericSIMD(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA],m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold);
|
|
|
|
|
- resolveSingleConstraintRowGeneric(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA],m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold);
|
|
|
|
|
|
|
+ resolveSingleConstraintRowGenericSIMD(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA],m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
int numRollingFrictionPoolConstraints = m_tmpSolverContactRollingFrictionConstraintPool.size();
|
|
int numRollingFrictionPoolConstraints = m_tmpSolverContactRollingFrictionConstraintPool.size();
|
|
|
for (j=0;j<numRollingFrictionPoolConstraints;j++)
|
|
for (j=0;j<numRollingFrictionPoolConstraints;j++)
|
|
|
{
|
|
{
|
|
@@ -1500,9 +1692,9 @@ btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration
|
|
|
resolveSingleConstraintRowGenericSIMD(m_tmpSolverBodyPool[rollingFrictionConstraint.m_solverBodyIdA],m_tmpSolverBodyPool[rollingFrictionConstraint.m_solverBodyIdB],rollingFrictionConstraint);
|
|
resolveSingleConstraintRowGenericSIMD(m_tmpSolverBodyPool[rollingFrictionConstraint.m_solverBodyIdA],m_tmpSolverBodyPool[rollingFrictionConstraint.m_solverBodyIdB],rollingFrictionConstraint);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} else
|
|
} else
|
|
|
{
|
|
{
|
|
@@ -1626,10 +1818,10 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations(
|
|
|
|
|
|
|
|
for ( int iteration = 0 ; iteration< maxIterations ; iteration++)
|
|
for ( int iteration = 0 ; iteration< maxIterations ; iteration++)
|
|
|
//for ( int iteration = maxIterations-1 ; iteration >= 0;iteration--)
|
|
//for ( int iteration = maxIterations-1 ; iteration >= 0;iteration--)
|
|
|
- {
|
|
|
|
|
|
|
+ {
|
|
|
solveSingleIteration(iteration, bodies ,numBodies,manifoldPtr, numManifolds,constraints,numConstraints,infoGlobal,debugDrawer);
|
|
solveSingleIteration(iteration, bodies ,numBodies,manifoldPtr, numManifolds,constraints,numConstraints,infoGlobal,debugDrawer);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
return 0.f;
|
|
return 0.f;
|
|
|
}
|
|
}
|
|
@@ -1671,13 +1863,12 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyFinish(btCo
|
|
|
fb->m_appliedForceBodyB += solverConstr.m_contactNormal2*solverConstr.m_appliedImpulse*constr->getRigidBodyB().getLinearFactor()/infoGlobal.m_timeStep;
|
|
fb->m_appliedForceBodyB += solverConstr.m_contactNormal2*solverConstr.m_appliedImpulse*constr->getRigidBodyB().getLinearFactor()/infoGlobal.m_timeStep;
|
|
|
fb->m_appliedTorqueBodyA += solverConstr.m_relpos1CrossNormal* constr->getRigidBodyA().getAngularFactor()*solverConstr.m_appliedImpulse/infoGlobal.m_timeStep;
|
|
fb->m_appliedTorqueBodyA += solverConstr.m_relpos1CrossNormal* constr->getRigidBodyA().getAngularFactor()*solverConstr.m_appliedImpulse/infoGlobal.m_timeStep;
|
|
|
fb->m_appliedTorqueBodyB += solverConstr.m_relpos2CrossNormal* constr->getRigidBodyB().getAngularFactor()*solverConstr.m_appliedImpulse/infoGlobal.m_timeStep; /*RGM ???? */
|
|
fb->m_appliedTorqueBodyB += solverConstr.m_relpos2CrossNormal* constr->getRigidBodyB().getAngularFactor()*solverConstr.m_appliedImpulse/infoGlobal.m_timeStep; /*RGM ???? */
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
constr->internalSetAppliedImpulse(solverConstr.m_appliedImpulse);
|
|
constr->internalSetAppliedImpulse(solverConstr.m_appliedImpulse);
|
|
|
-
|
|
|
|
|
// Urho3D: if constraint has infinity breaking threshold, do not break no matter what
|
|
// Urho3D: if constraint has infinity breaking threshold, do not break no matter what
|
|
|
- btScalar breakingThreshold = constr->getBreakingImpulseThreshold();
|
|
|
|
|
|
|
+ btScalar breakingThreshold = constr->getBreakingImpulseThreshold();
|
|
|
if (breakingThreshold < SIMD_INFINITY && btFabs(solverConstr.m_appliedImpulse)>=breakingThreshold)
|
|
if (breakingThreshold < SIMD_INFINITY && btFabs(solverConstr.m_appliedImpulse)>=breakingThreshold)
|
|
|
{
|
|
{
|
|
|
constr->setEnabled(false);
|
|
constr->setEnabled(false);
|
|
@@ -1695,7 +1886,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyFinish(btCo
|
|
|
m_tmpSolverBodyPool[i].writebackVelocityAndTransform(infoGlobal.m_timeStep, infoGlobal.m_splitImpulseTurnErp);
|
|
m_tmpSolverBodyPool[i].writebackVelocityAndTransform(infoGlobal.m_timeStep, infoGlobal.m_splitImpulseTurnErp);
|
|
|
else
|
|
else
|
|
|
m_tmpSolverBodyPool[i].writebackVelocity();
|
|
m_tmpSolverBodyPool[i].writebackVelocity();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
m_tmpSolverBodyPool[i].m_originalBody->setLinearVelocity(
|
|
m_tmpSolverBodyPool[i].m_originalBody->setLinearVelocity(
|
|
|
m_tmpSolverBodyPool[i].m_linearVelocity+
|
|
m_tmpSolverBodyPool[i].m_linearVelocity+
|
|
|
m_tmpSolverBodyPool[i].m_externalForceImpulse);
|
|
m_tmpSolverBodyPool[i].m_externalForceImpulse);
|
|
@@ -1728,13 +1919,13 @@ btScalar btSequentialImpulseConstraintSolver::solveGroup(btCollisionObject** bod
|
|
|
|
|
|
|
|
BT_PROFILE("solveGroup");
|
|
BT_PROFILE("solveGroup");
|
|
|
//you need to provide at least some bodies
|
|
//you need to provide at least some bodies
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
solveGroupCacheFriendlySetup( bodies, numBodies, manifoldPtr, numManifolds,constraints, numConstraints,infoGlobal,debugDrawer);
|
|
solveGroupCacheFriendlySetup( bodies, numBodies, manifoldPtr, numManifolds,constraints, numConstraints,infoGlobal,debugDrawer);
|
|
|
|
|
|
|
|
solveGroupCacheFriendlyIterations(bodies, numBodies, manifoldPtr, numManifolds,constraints, numConstraints,infoGlobal,debugDrawer);
|
|
solveGroupCacheFriendlyIterations(bodies, numBodies, manifoldPtr, numManifolds,constraints, numConstraints,infoGlobal,debugDrawer);
|
|
|
|
|
|
|
|
solveGroupCacheFriendlyFinish(bodies, numBodies, infoGlobal);
|
|
solveGroupCacheFriendlyFinish(bodies, numBodies, infoGlobal);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return 0.f;
|
|
return 0.f;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1742,5 +1933,3 @@ void btSequentialImpulseConstraintSolver::reset()
|
|
|
{
|
|
{
|
|
|
m_btSeed2 = 0;
|
|
m_btSeed2 = 0;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|