more solver experiments, randomize the order of contact points, not just manifolds

use #defines for constants, rather then const btScalar
This commit is contained in:
ejcoumans
2006-11-04 05:22:36 +00:00
parent c4c4523a4e
commit 23c64fb0db
11 changed files with 71 additions and 51 deletions

View File

@@ -114,9 +114,12 @@ btCollisionShape* shapePtr[numShapes] =
GLDebugDrawer debugDrawer; GLDebugDrawer debugDrawer;
//experimental jitter damping (1 = no damping, 0 = total damping once motion below threshold)
extern float gJitterVelocityDampingFactor;
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
gJitterVelocityDampingFactor = 0.7;
CcdPhysicsDemo* ccdDemo = new CcdPhysicsDemo(); CcdPhysicsDemo* ccdDemo = new CcdPhysicsDemo();

View File

@@ -42,7 +42,8 @@ struct btDispatcherInfo
m_timeOfImpact(1.f), m_timeOfImpact(1.f),
m_useContinuous(false), m_useContinuous(false),
m_debugDraw(0), m_debugDraw(0),
m_enableSatConvex(false) m_enableSatConvex(false),
m_enableSPU(false)
{ {
} }
@@ -53,6 +54,7 @@ struct btDispatcherInfo
bool m_useContinuous; bool m_useContinuous;
class btIDebugDraw* m_debugDraw; class btIDebugDraw* m_debugDraw;
bool m_enableSatConvex; bool m_enableSatConvex;
bool m_enableSPU;
}; };

View File

@@ -14,6 +14,7 @@ subject to the following restrictions:
*/ */
#include "btCollisionDispatcher.h" #include "btCollisionDispatcher.h"
@@ -34,8 +35,8 @@ int gNumManifold = 0;
btCollisionDispatcher::btCollisionDispatcher(bool noDefaultAlgorithms) btCollisionDispatcher::btCollisionDispatcher(bool noDefaultAlgorithms)
:m_useIslands(true), :m_useIslands(true),
m_count(0),
m_convexConvexCreateFunc(0), m_convexConvexCreateFunc(0),
m_count(0),
m_convexConcaveCreateFunc(0), m_convexConcaveCreateFunc(0),
m_swappedConvexConcaveCreateFunc(0), m_swappedConvexConcaveCreateFunc(0),
m_compoundCreateFunc(0), m_compoundCreateFunc(0),
@@ -54,7 +55,7 @@ m_emptyCreateFunc(0)
} }
} }
btCollisionDispatcher::btCollisionDispatcher (): btCollisionDispatcher::btCollisionDispatcher ():
m_useIslands(true), m_useIslands(true),
m_count(0) m_count(0)

View File

@@ -40,6 +40,7 @@ m_ownsBroadphasePairCache(false)
{ {
} }
btCollisionWorld::btCollisionWorld() btCollisionWorld::btCollisionWorld()
: m_dispatcher1(new btCollisionDispatcher()), : m_dispatcher1(new btCollisionDispatcher()),
m_broadphasePairCache(new btSimpleBroadphase()), m_broadphasePairCache(new btSimpleBroadphase()),

View File

@@ -22,9 +22,9 @@ subject to the following restrictions:
#include <stdio.h> //for debug printf #include <stdio.h> //for debug printf
#endif #endif
static const btScalar rel_error = btScalar(1.0e-5);
btScalar rel_error2 = rel_error * rel_error; #define REL_ERROR2 1.0e-10f
float maxdist2 = 1.e30f;
#ifdef __SPU__ #ifdef __SPU__
#include <spu_printf.h> #include <spu_printf.h>
@@ -102,7 +102,7 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
break; break;
} }
// are we getting any closer ? // are we getting any closer ?
if (squaredDistance - delta <= squaredDistance * rel_error2) if (squaredDistance - delta <= squaredDistance * REL_ERROR2)
{ {
checkSimplex = true; checkSimplex = true;
break; break;
@@ -172,6 +172,7 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
float rlen = 1.f / btSqrt(lenSqr ); float rlen = 1.f / btSqrt(lenSqr );
normalInB *= rlen; //normalize normalInB *= rlen; //normalize
btScalar s = btSqrt(squaredDistance); btScalar s = btSqrt(squaredDistance);
ASSERT(s > btScalar(0.0)); ASSERT(s > btScalar(0.0));
pointOnA -= m_cachedSeparatingAxis * (marginA / s); pointOnA -= m_cachedSeparatingAxis * (marginA / s);
pointOnB += m_cachedSeparatingAxis * (marginB / s); pointOnB += m_cachedSeparatingAxis * (marginB / s);

View File

@@ -32,8 +32,14 @@ int totalCpd = 0;
int gTotalContactPoints = 0; int gTotalContactPoints = 0;
#define SEQUENTIAL_IMPULSE_MAX_SOLVER_BODIES 16384 struct btOrderIndex
static int gOrder[SEQUENTIAL_IMPULSE_MAX_SOLVER_BODIES]; {
short int m_manifoldIndex;
short int m_pointIndex;
};
#define SEQUENTIAL_IMPULSE_MAX_SOLVER_POINTS 16384
static btOrderIndex gOrder[SEQUENTIAL_IMPULSE_MAX_SOLVER_POINTS];
static unsigned long btSeed2 = 0; static unsigned long btSeed2 = 0;
unsigned long btRand2() unsigned long btRand2()
{ {
@@ -84,14 +90,28 @@ float btSequentialImpulseConstraintSolver::solveGroup(btPersistentManifold** man
btProfiler::beginBlock("solve"); btProfiler::beginBlock("solve");
#endif //USE_PROFILE #endif //USE_PROFILE
int totalPoints = 0;
{ {
int j; int j;
for (j=0;j<numManifolds;j++) for (j=0;j<numManifolds;j++)
{ {
gOrder[j] = j;
prepareConstraints(manifoldPtr[j],info,debugDrawer); prepareConstraints(manifoldPtr[j],info,debugDrawer);
} }
} }
{
int j;
for (j=0;j<numManifolds;j++)
{
for (int p=0;p<manifoldPtr[j]->getNumContacts();p++)
{
gOrder[totalPoints].m_manifoldIndex = j;
gOrder[totalPoints].m_pointIndex = p;
totalPoints++;
}
}
}
//should traverse the contacts random order... //should traverse the contacts random order...
@@ -100,23 +120,27 @@ float btSequentialImpulseConstraintSolver::solveGroup(btPersistentManifold** man
{ {
int j; int j;
if ((iteration & 7) == 0) { if ((iteration & 7) == 0) {
for (j=0; j<numManifolds; ++j) { for (j=0; j<totalPoints; ++j) {
int tmp = gOrder[j]; btOrderIndex tmp = gOrder[j];
int swapi = btRandInt2(j+1); int swapi = btRandInt2(j+1);
gOrder[j] = gOrder[swapi]; gOrder[j] = gOrder[swapi];
gOrder[swapi] = tmp; gOrder[swapi] = tmp;
} }
} }
for (j=0;j<numManifolds;j++) for (j=0;j<totalPoints;j++)
{ {
solve(manifoldPtr[gOrder[j]],info,iteration,debugDrawer); btPersistentManifold* manifold = manifoldPtr[gOrder[j].m_manifoldIndex];
solve( (btRigidBody*)manifold->getBody0(),
(btRigidBody*)manifold->getBody1()
,manifold->getContactPoint(gOrder[j].m_pointIndex),info,iteration,debugDrawer);
} }
for (j=0;j<numManifolds;j++) for (j=0;j<totalPoints;j++)
{ {
solveFriction(manifoldPtr[gOrder[j]],info,iteration,debugDrawer); btPersistentManifold* manifold = manifoldPtr[gOrder[j].m_manifoldIndex];
solveFriction((btRigidBody*)manifold->getBody0(),
(btRigidBody*)manifold->getBody1(),manifold->getContactPoint(gOrder[j].m_pointIndex),info,iteration,debugDrawer);
} }
} }
@@ -311,25 +335,16 @@ void btSequentialImpulseConstraintSolver::prepareConstraints(btPersistentManifol
} }
} }
float btSequentialImpulseConstraintSolver::solve(btPersistentManifold* manifoldPtr, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer) float btSequentialImpulseConstraintSolver::solve(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer)
{ {
btRigidBody* body0 = (btRigidBody*)manifoldPtr->getBody0();
btRigidBody* body1 = (btRigidBody*)manifoldPtr->getBody1();
float maxImpulse = 0.f; float maxImpulse = 0.f;
{ {
const int numpoints = manifoldPtr->getNumContacts();
btVector3 color(0,1,0); btVector3 color(0,1,0);
for (int i=0;i<numpoints ;i++)
{ {
if (cp.getDistance() <= 0.f)
int j=i;//(i&1)? i : numpoints-1-i;
btManifoldPoint& cp = manifoldPtr->getContactPoint(j);
if (cp.getDistance() <= 0.f)
{ {
if (iter == 0) if (iter == 0)
@@ -356,22 +371,15 @@ float btSequentialImpulseConstraintSolver::solve(btPersistentManifold* manifoldP
return maxImpulse; return maxImpulse;
} }
float btSequentialImpulseConstraintSolver::solveFriction(btPersistentManifold* manifoldPtr, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer) float btSequentialImpulseConstraintSolver::solveFriction(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer)
{ {
btRigidBody* body0 = (btRigidBody*)manifoldPtr->getBody0();
btRigidBody* body1 = (btRigidBody*)manifoldPtr->getBody1();
{ {
const int numpoints = manifoldPtr->getNumContacts();
btVector3 color(0,1,0); btVector3 color(0,1,0);
for (int i=0;i<numpoints ;i++)
{ {
int j=i;//(i&1)? i : numpoints-1-i;
btManifoldPoint& cp = manifoldPtr->getContactPoint(j);
if (cp.getDistance() <= 0.f) if (cp.getDistance() <= 0.f)
{ {

View File

@@ -29,8 +29,9 @@ class btIDebugDraw;
/// Applies impulses for combined restitution and penetration recovery and to simulate friction /// Applies impulses for combined restitution and penetration recovery and to simulate friction
class btSequentialImpulseConstraintSolver : public btConstraintSolver class btSequentialImpulseConstraintSolver : public btConstraintSolver
{ {
float solve(btPersistentManifold* manifold, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer);
float solveFriction(btPersistentManifold* manifoldPtr, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer); float solve(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer);
float solveFriction(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer);
void prepareConstraints(btPersistentManifold* manifoldPtr, const btContactSolverInfo& info,btIDebugDraw* debugDrawer); void prepareConstraints(btPersistentManifold* manifoldPtr, const btContactSolverInfo& info,btIDebugDraw* debugDrawer);
ContactSolverFunc m_contactDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES]; ContactSolverFunc m_contactDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES];

View File

@@ -56,6 +56,7 @@ subject to the following restrictions:
#include <algorithm> #include <algorithm>
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btConstraintSolver* constraintSolver) btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btConstraintSolver* constraintSolver)
:btDynamicsWorld(), :btDynamicsWorld(),
m_constraintSolver(constraintSolver? constraintSolver: new btSequentialImpulseConstraintSolver), m_constraintSolver(constraintSolver? constraintSolver: new btSequentialImpulseConstraintSolver),
@@ -69,6 +70,7 @@ m_profileTimings(0)
m_ownsConstraintSolver = (constraintSolver==0); m_ownsConstraintSolver = (constraintSolver==0);
} }
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver) btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver)
:btDynamicsWorld(dispatcher,pairCache), :btDynamicsWorld(dispatcher,pairCache),
m_constraintSolver(constraintSolver? constraintSolver: new btSequentialImpulseConstraintSolver), m_constraintSolver(constraintSolver? constraintSolver: new btSequentialImpulseConstraintSolver),

View File

@@ -116,18 +116,18 @@ btRigidBody::btRigidBody( float mass,const btTransform& worldTransform,btCollisi
//note there this influences deactivation thresholds! //note there this influences deactivation thresholds!
float gClippedAngvelThresholdSqr = 0.01f; float gClippedAngvelThresholdSqr = 0.01f;
float gClippedLinearThresholdSqr = 0.01f; float gClippedLinearThresholdSqr = 0.01f;
float gJitterVelocityDampingFactor = 1.0f; float gJitterVelocityDampingFactor = 1.f;
#endif //EXPERIMENTAL_JITTER_REMOVAL #endif //EXPERIMENTAL_JITTER_REMOVAL
void btRigidBody::predictIntegratedTransform(btScalar timeStep,btTransform& predictedTransform) void btRigidBody::predictIntegratedTransform(btScalar timeStep,btTransform& predictedTransform)
{ {
#ifdef EXPERIMENTAL_JITTER_REMOVAL #ifdef EXPERIMENTAL_JITTER_REMOVAL
if (wantsSleeping()) //if (wantsSleeping())
{ {
//clip to avoid jitter //clip to avoid jitter
// if ((m_angularVelocity.length2() < gClippedAngvelThresholdSqr) && if ((m_angularVelocity.length2() < gClippedAngvelThresholdSqr) &&
// (m_linearVelocity.length2() < gClippedLinearThresholdSqr)) (m_linearVelocity.length2() < gClippedLinearThresholdSqr))
{ {
m_angularVelocity *= gJitterVelocityDampingFactor; m_angularVelocity *= gJitterVelocityDampingFactor;
m_linearVelocity *= gJitterVelocityDampingFactor; m_linearVelocity *= gJitterVelocityDampingFactor;

View File

@@ -194,4 +194,4 @@ void btSimpleDynamicsWorld::setConstraintSolver(btConstraintSolver* solver)
} }
m_ownsConstraintSolver = false; m_ownsConstraintSolver = false;
m_constraintSolver = solver; m_constraintSolver = solver;
} }

View File

@@ -88,13 +88,13 @@ SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); }
#endif #endif
const btScalar SIMD_2_PI = 6.283185307179586232f; #define SIMD_2_PI 6.283185307179586232f
const btScalar SIMD_PI = SIMD_2_PI * btScalar(0.5f); #define SIMD_PI (SIMD_2_PI * btScalar(0.5f))
const btScalar SIMD_HALF_PI = SIMD_2_PI * btScalar(0.25f); #define SIMD_HALF_PI (SIMD_2_PI * btScalar(0.25f))
const btScalar SIMD_RADS_PER_DEG = SIMD_2_PI / btScalar(360.0f); #define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0f))
const btScalar SIMD_DEGS_PER_RAD = btScalar(360.0f) / SIMD_2_PI; #define SIMD_DEGS_PER_RAD (btScalar(360.0f) / SIMD_2_PI)
const btScalar SIMD_EPSILON = FLT_EPSILON; #define SIMD_EPSILON FLT_EPSILON
const btScalar SIMD_INFINITY = FLT_MAX; #define SIMD_INFINITY FLT_MAX
SIMD_FORCE_INLINE bool btFuzzyZero(btScalar x) { return btFabs(x) < SIMD_EPSILON; } SIMD_FORCE_INLINE bool btFuzzyZero(btScalar x) { return btFabs(x) < SIMD_EPSILON; }
@@ -121,6 +121,7 @@ SIMD_FORCE_INLINE int btSign(btScalar x) {
SIMD_FORCE_INLINE btScalar btRadians(btScalar x) { return x * SIMD_RADS_PER_DEG; } SIMD_FORCE_INLINE btScalar btRadians(btScalar x) { return x * SIMD_RADS_PER_DEG; }
SIMD_FORCE_INLINE btScalar btDegrees(btScalar x) { return x * SIMD_DEGS_PER_RAD; } SIMD_FORCE_INLINE btScalar btDegrees(btScalar x) { return x * SIMD_DEGS_PER_RAD; }
#define BT_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
#endif //SIMD___SCALAR_H #endif //SIMD___SCALAR_H