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:
@@ -114,9 +114,12 @@ btCollisionShape* shapePtr[numShapes] =
|
||||
|
||||
GLDebugDrawer debugDrawer;
|
||||
|
||||
//experimental jitter damping (1 = no damping, 0 = total damping once motion below threshold)
|
||||
extern float gJitterVelocityDampingFactor;
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
gJitterVelocityDampingFactor = 0.7;
|
||||
|
||||
CcdPhysicsDemo* ccdDemo = new CcdPhysicsDemo();
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ struct btDispatcherInfo
|
||||
m_timeOfImpact(1.f),
|
||||
m_useContinuous(false),
|
||||
m_debugDraw(0),
|
||||
m_enableSatConvex(false)
|
||||
m_enableSatConvex(false),
|
||||
m_enableSPU(false)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -53,6 +54,7 @@ struct btDispatcherInfo
|
||||
bool m_useContinuous;
|
||||
class btIDebugDraw* m_debugDraw;
|
||||
bool m_enableSatConvex;
|
||||
bool m_enableSPU;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ subject to the following restrictions:
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "btCollisionDispatcher.h"
|
||||
|
||||
|
||||
@@ -34,8 +35,8 @@ int gNumManifold = 0;
|
||||
|
||||
btCollisionDispatcher::btCollisionDispatcher(bool noDefaultAlgorithms)
|
||||
:m_useIslands(true),
|
||||
m_count(0),
|
||||
m_convexConvexCreateFunc(0),
|
||||
m_count(0),
|
||||
m_convexConcaveCreateFunc(0),
|
||||
m_swappedConvexConcaveCreateFunc(0),
|
||||
m_compoundCreateFunc(0),
|
||||
|
||||
@@ -40,6 +40,7 @@ m_ownsBroadphasePairCache(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
btCollisionWorld::btCollisionWorld()
|
||||
: m_dispatcher1(new btCollisionDispatcher()),
|
||||
m_broadphasePairCache(new btSimpleBroadphase()),
|
||||
|
||||
@@ -22,9 +22,9 @@ subject to the following restrictions:
|
||||
#include <stdio.h> //for debug printf
|
||||
#endif
|
||||
|
||||
static const btScalar rel_error = btScalar(1.0e-5);
|
||||
btScalar rel_error2 = rel_error * rel_error;
|
||||
float maxdist2 = 1.e30f;
|
||||
|
||||
#define REL_ERROR2 1.0e-10f
|
||||
|
||||
|
||||
#ifdef __SPU__
|
||||
#include <spu_printf.h>
|
||||
@@ -102,7 +102,7 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
|
||||
break;
|
||||
}
|
||||
// are we getting any closer ?
|
||||
if (squaredDistance - delta <= squaredDistance * rel_error2)
|
||||
if (squaredDistance - delta <= squaredDistance * REL_ERROR2)
|
||||
{
|
||||
checkSimplex = true;
|
||||
break;
|
||||
@@ -172,6 +172,7 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
|
||||
float rlen = 1.f / btSqrt(lenSqr );
|
||||
normalInB *= rlen; //normalize
|
||||
btScalar s = btSqrt(squaredDistance);
|
||||
|
||||
ASSERT(s > btScalar(0.0));
|
||||
pointOnA -= m_cachedSeparatingAxis * (marginA / s);
|
||||
pointOnB += m_cachedSeparatingAxis * (marginB / s);
|
||||
|
||||
@@ -32,8 +32,14 @@ int totalCpd = 0;
|
||||
|
||||
int gTotalContactPoints = 0;
|
||||
|
||||
#define SEQUENTIAL_IMPULSE_MAX_SOLVER_BODIES 16384
|
||||
static int gOrder[SEQUENTIAL_IMPULSE_MAX_SOLVER_BODIES];
|
||||
struct btOrderIndex
|
||||
{
|
||||
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;
|
||||
unsigned long btRand2()
|
||||
{
|
||||
@@ -84,15 +90,29 @@ float btSequentialImpulseConstraintSolver::solveGroup(btPersistentManifold** man
|
||||
btProfiler::beginBlock("solve");
|
||||
#endif //USE_PROFILE
|
||||
|
||||
int totalPoints = 0;
|
||||
|
||||
{
|
||||
int j;
|
||||
for (j=0;j<numManifolds;j++)
|
||||
{
|
||||
gOrder[j] = j;
|
||||
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...
|
||||
int iteration;
|
||||
@@ -100,23 +120,27 @@ float btSequentialImpulseConstraintSolver::solveGroup(btPersistentManifold** man
|
||||
{
|
||||
int j;
|
||||
if ((iteration & 7) == 0) {
|
||||
for (j=0; j<numManifolds; ++j) {
|
||||
int tmp = gOrder[j];
|
||||
for (j=0; j<totalPoints; ++j) {
|
||||
btOrderIndex tmp = gOrder[j];
|
||||
int swapi = btRandInt2(j+1);
|
||||
gOrder[j] = gOrder[swapi];
|
||||
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;
|
||||
|
||||
{
|
||||
const int numpoints = manifoldPtr->getNumContacts();
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
if (iter == 0)
|
||||
@@ -356,22 +371,15 @@ float btSequentialImpulseConstraintSolver::solve(btPersistentManifold* manifoldP
|
||||
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);
|
||||
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)
|
||||
{
|
||||
|
||||
|
||||
@@ -29,8 +29,9 @@ class btIDebugDraw;
|
||||
/// Applies impulses for combined restitution and penetration recovery and to simulate friction
|
||||
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);
|
||||
|
||||
ContactSolverFunc m_contactDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES];
|
||||
|
||||
@@ -56,6 +56,7 @@ subject to the following restrictions:
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btConstraintSolver* constraintSolver)
|
||||
:btDynamicsWorld(),
|
||||
m_constraintSolver(constraintSolver? constraintSolver: new btSequentialImpulseConstraintSolver),
|
||||
@@ -69,6 +70,7 @@ m_profileTimings(0)
|
||||
m_ownsConstraintSolver = (constraintSolver==0);
|
||||
}
|
||||
|
||||
|
||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver)
|
||||
:btDynamicsWorld(dispatcher,pairCache),
|
||||
m_constraintSolver(constraintSolver? constraintSolver: new btSequentialImpulseConstraintSolver),
|
||||
|
||||
@@ -116,18 +116,18 @@ btRigidBody::btRigidBody( float mass,const btTransform& worldTransform,btCollisi
|
||||
//note there this influences deactivation thresholds!
|
||||
float gClippedAngvelThresholdSqr = 0.01f;
|
||||
float gClippedLinearThresholdSqr = 0.01f;
|
||||
float gJitterVelocityDampingFactor = 1.0f;
|
||||
float gJitterVelocityDampingFactor = 1.f;
|
||||
#endif //EXPERIMENTAL_JITTER_REMOVAL
|
||||
|
||||
void btRigidBody::predictIntegratedTransform(btScalar timeStep,btTransform& predictedTransform)
|
||||
{
|
||||
|
||||
#ifdef EXPERIMENTAL_JITTER_REMOVAL
|
||||
if (wantsSleeping())
|
||||
//if (wantsSleeping())
|
||||
{
|
||||
//clip to avoid jitter
|
||||
// if ((m_angularVelocity.length2() < gClippedAngvelThresholdSqr) &&
|
||||
// (m_linearVelocity.length2() < gClippedLinearThresholdSqr))
|
||||
if ((m_angularVelocity.length2() < gClippedAngvelThresholdSqr) &&
|
||||
(m_linearVelocity.length2() < gClippedLinearThresholdSqr))
|
||||
{
|
||||
m_angularVelocity *= gJitterVelocityDampingFactor;
|
||||
m_linearVelocity *= gJitterVelocityDampingFactor;
|
||||
|
||||
@@ -88,13 +88,13 @@ SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); }
|
||||
#endif
|
||||
|
||||
|
||||
const btScalar SIMD_2_PI = 6.283185307179586232f;
|
||||
const btScalar SIMD_PI = SIMD_2_PI * btScalar(0.5f);
|
||||
const btScalar SIMD_HALF_PI = SIMD_2_PI * btScalar(0.25f);
|
||||
const btScalar SIMD_RADS_PER_DEG = SIMD_2_PI / btScalar(360.0f);
|
||||
const btScalar SIMD_DEGS_PER_RAD = btScalar(360.0f) / SIMD_2_PI;
|
||||
const btScalar SIMD_EPSILON = FLT_EPSILON;
|
||||
const btScalar SIMD_INFINITY = FLT_MAX;
|
||||
#define SIMD_2_PI 6.283185307179586232f
|
||||
#define SIMD_PI (SIMD_2_PI * btScalar(0.5f))
|
||||
#define SIMD_HALF_PI (SIMD_2_PI * btScalar(0.25f))
|
||||
#define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0f))
|
||||
#define SIMD_DEGS_PER_RAD (btScalar(360.0f) / SIMD_2_PI)
|
||||
#define SIMD_EPSILON FLT_EPSILON
|
||||
#define SIMD_INFINITY FLT_MAX
|
||||
|
||||
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 btDegrees(btScalar x) { return x * SIMD_DEGS_PER_RAD; }
|
||||
|
||||
#define BT_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
|
||||
|
||||
|
||||
#endif //SIMD___SCALAR_H
|
||||
|
||||
Reference in New Issue
Block a user