One of the last parts of the refactoring (hopefully), made most members of btCollisionObject protected.

Also did some work on improving the constraint solver.
This commit is contained in:
ejcoumans
2006-11-02 03:42:53 +00:00
parent 82ba30caa6
commit 4050da0e2f
34 changed files with 485 additions and 265 deletions

View File

@@ -164,7 +164,8 @@ float resolveSingleFriction(
float combinedFriction = cpd->m_friction;
btScalar limit = cpd->m_appliedImpulse * combinedFriction;
//if (contactPoint.m_appliedImpulse>0.f)
if (cpd->m_appliedImpulse>0.f)
//friction
{
//apply friction in the 2 tangential directions
@@ -182,11 +183,12 @@ float resolveSingleFriction(
// calculate j that moves us to zero relative velocity
j1 = -vrel * cpd->m_jacDiagABInvTangent0;
float total = cpd->m_accumulatedTangentImpulse0 + j1;
GEN_set_min(total, limit);
GEN_set_max(total, -limit);
j1 = total - cpd->m_accumulatedTangentImpulse0;
cpd->m_accumulatedTangentImpulse0 = total;
float oldTangentImpulse = cpd->m_accumulatedTangentImpulse0;
cpd->m_accumulatedTangentImpulse0 = oldTangentImpulse + j1;
GEN_set_min(cpd->m_accumulatedTangentImpulse0, limit);
GEN_set_max(cpd->m_accumulatedTangentImpulse0, -limit);
j1 = cpd->m_accumulatedTangentImpulse0 - oldTangentImpulse;
}
{
// 2nd tangent
@@ -195,11 +197,11 @@ float resolveSingleFriction(
// calculate j that moves us to zero relative velocity
j2 = -vrel * cpd->m_jacDiagABInvTangent1;
float total = cpd->m_accumulatedTangentImpulse1 + j2;
GEN_set_min(total, limit);
GEN_set_max(total, -limit);
j2 = total - cpd->m_accumulatedTangentImpulse1;
cpd->m_accumulatedTangentImpulse1 = total;
float oldTangentImpulse = cpd->m_accumulatedTangentImpulse1;
cpd->m_accumulatedTangentImpulse1 = oldTangentImpulse + j2;
GEN_set_min(cpd->m_accumulatedTangentImpulse1, limit);
GEN_set_max(cpd->m_accumulatedTangentImpulse1, -limit);
j2 = cpd->m_accumulatedTangentImpulse1 - oldTangentImpulse;
}
#ifdef USE_INTERNAL_APPLY_IMPULSE

View File

@@ -32,6 +32,21 @@ int totalCpd = 0;
int gTotalContactPoints = 0;
#define SEQUENTIAL_IMPULSE_MAX_SOLVER_BODIES 16384
static int gOrder[SEQUENTIAL_IMPULSE_MAX_SOLVER_BODIES];
static unsigned long btSeed2 = 0;
unsigned long btRand2()
{
btSeed2 = (1664525L*btSeed2 + 1013904223L) & 0xffffffff;
return btSeed2;
}
int btRandInt2 (int n)
{
float a = float(n) / 4294967296.0f;
return (int) (float(btRand2()) * a);
}
bool MyContactDestroyedCallback(void* userPersistentData)
{
assert (userPersistentData);
@@ -73,48 +88,40 @@ float btSequentialImpulseConstraintSolver::solveGroup(btPersistentManifold** man
int j;
for (j=0;j<numManifolds;j++)
{
int k=j;
prepareConstraints(manifoldPtr[k],info,debugDrawer);
solve(manifoldPtr[k],info,0,debugDrawer);
gOrder[j] = j;
prepareConstraints(manifoldPtr[j],info,debugDrawer);
}
}
//should traverse the contacts random order...
int i;
for ( i = 0;i<numiter-1;i++)
int iteration;
for ( iteration = 0;iteration<numiter-1;iteration++)
{
int j;
if ((iteration & 7) == 0) {
for (j=0; j<numManifolds; ++j) {
int tmp = gOrder[j];
int swapi = btRandInt2(j+1);
gOrder[j] = gOrder[swapi];
gOrder[swapi] = tmp;
}
}
for (j=0;j<numManifolds;j++)
{
int k=j;
if (i&1)
k=numManifolds-j-1;
solve(manifoldPtr[k],info,i,debugDrawer);
solve(manifoldPtr[gOrder[j]],info,iteration,debugDrawer);
}
for (j=0;j<numManifolds;j++)
{
solveFriction(manifoldPtr[gOrder[j]],info,iteration,debugDrawer);
}
}
#ifdef USE_PROFILE
btProfiler::endBlock("solve");
btProfiler::beginBlock("solveFriction");
#endif //USE_PROFILE
//now solve the friction
for (i = 0;i<numiter-1;i++)
{
int j;
for (j=0;j<numManifolds;j++)
{
int k = j;
if (i&1)
k=numManifolds-j-1;
solveFriction(manifoldPtr[k],info,i,debugDrawer);
}
}
#ifdef USE_PROFILE
btProfiler::endBlock("solveFriction");
#endif //USE_PROFILE
return 0.f;
@@ -225,7 +232,7 @@ void btSequentialImpulseConstraintSolver::prepareConstraints(btPersistentManifol
btScalar penVel = -cpd->m_penetration/info.m_timeStep;
if (cpd->m_restitution >= penVel)
if (cpd->m_restitution > penVel)
{
cpd->m_penetration = 0.f;
}
@@ -233,7 +240,7 @@ void btSequentialImpulseConstraintSolver::prepareConstraints(btPersistentManifol
float relaxation = info.m_damping;
cpd->m_appliedImpulse *= relaxation;
cpd->m_appliedImpulse =0.f;//*= relaxation;
//for friction
cpd->m_prevAppliedImpulse = cpd->m_appliedImpulse;
@@ -260,8 +267,8 @@ void btSequentialImpulseConstraintSolver::prepareConstraints(btPersistentManifol
btVector3 totalImpulse =
#ifndef NO_FRICTION_WARMSTART
cp.m_frictionWorldTangential0*cp.m_accumulatedTangentImpulse0+
cp.m_frictionWorldTangential1*cp.m_accumulatedTangentImpulse1+
cpd->m_frictionWorldTangential0*cpd->m_accumulatedTangentImpulse0+
cpd->m_frictionWorldTangential1*cpd->m_accumulatedTangentImpulse1+
#endif //NO_FRICTION_WARMSTART
cp.m_normalWorldOnB*cpd->m_appliedImpulse;
@@ -320,11 +327,7 @@ float btSequentialImpulseConstraintSolver::solve(btPersistentManifold* manifoldP
{
int j=i;
if (iter % 2)
j = numpoints-1-i;
else
j=i;
btManifoldPoint& cp = manifoldPtr->getContactPoint(j);
if (cp.getDistance() <= 0.f)
{
@@ -367,9 +370,7 @@ float btSequentialImpulseConstraintSolver::solveFriction(btPersistentManifold* m
{
int j=i;
//if (iter % 2)
// j = numpoints-1-i;
btManifoldPoint& cp = manifoldPtr->getContactPoint(j);
if (cp.getDistance() <= 0.f)
{

View File

@@ -17,7 +17,7 @@ subject to the following restrictions:
#include "btTypedConstraint.h"
#include "BulletDynamics/Dynamics/btRigidBody.h"
static btRigidBody s_fixed(0, btTransform::getIdentity(),0);
static btRigidBody s_fixed(0, 0,0);
btTypedConstraint::btTypedConstraint()
: m_userConstraintType(-1),