Disable friction warmstarting by default, removing second friction direction. This gives a large performance increase.
friction warmstarting can be turned on using: dynamicsWorld ->getSolverInfo().m_solverMode |= SOLVER_USE_FRICTION_WARMSTARTING;
This commit is contained in:
@@ -21,7 +21,8 @@ enum btSolverMode
|
|||||||
SOLVER_RANDMIZE_ORDER = 1,
|
SOLVER_RANDMIZE_ORDER = 1,
|
||||||
SOLVER_FRICTION_SEPARATE = 2,
|
SOLVER_FRICTION_SEPARATE = 2,
|
||||||
SOLVER_USE_WARMSTARTING = 4,
|
SOLVER_USE_WARMSTARTING = 4,
|
||||||
SOLVER_CACHE_FRIENDLY = 8
|
SOLVER_USE_FRICTION_WARMSTARTING = 8,
|
||||||
|
SOLVER_CACHE_FRIENDLY = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
struct btContactSolverInfoData
|
struct btContactSolverInfoData
|
||||||
@@ -69,7 +70,7 @@ struct btContactSolverInfo : public btContactSolverInfoData
|
|||||||
m_splitImpulsePenetrationThreshold = -0.02f;
|
m_splitImpulsePenetrationThreshold = -0.02f;
|
||||||
m_linearSlop = btScalar(0.0);
|
m_linearSlop = btScalar(0.0);
|
||||||
m_warmstartingFactor=btScalar(0.85);
|
m_warmstartingFactor=btScalar(0.85);
|
||||||
m_solverMode = SOLVER_RANDMIZE_ORDER | SOLVER_CACHE_FRIENDLY | SOLVER_USE_WARMSTARTING;
|
m_solverMode = SOLVER_CACHE_FRIENDLY | SOLVER_RANDMIZE_ORDER | SOLVER_USE_WARMSTARTING;
|
||||||
m_restingContactRestitutionThreshold = 2;//resting contact lifetime threshold to disable restitution
|
m_restingContactRestitutionThreshold = 2;//resting contact lifetime threshold to disable restitution
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ btScalar resolveSingleFrictionCacheFriendly(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void btSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation)
|
btSolverConstraint& btSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation)
|
||||||
{
|
{
|
||||||
|
|
||||||
btRigidBody* body0=btRigidBody::upcast(colObj0);
|
btRigidBody* body0=btRigidBody::upcast(colObj0);
|
||||||
@@ -491,7 +491,7 @@ void btSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3&
|
|||||||
btScalar denom = relaxation/(denom0+denom1);
|
btScalar denom = relaxation/(denom0+denom1);
|
||||||
solverConstraint.m_jacDiagABInv = denom;
|
solverConstraint.m_jacDiagABInv = denom;
|
||||||
|
|
||||||
|
return solverConstraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -760,7 +760,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|||||||
solverConstraint.m_appliedPushImpulse = 0.f;
|
solverConstraint.m_appliedPushImpulse = 0.f;
|
||||||
|
|
||||||
solverConstraint.m_frictionIndex = m_tmpSolverFrictionConstraintPool.size();
|
solverConstraint.m_frictionIndex = m_tmpSolverFrictionConstraintPool.size();
|
||||||
if (!cp.m_lateralFrictionInitialized)
|
if ((!infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING) || !cp.m_lateralFrictionInitialized)
|
||||||
{
|
{
|
||||||
cp.m_lateralFrictionDir1 = vel - cp.m_normalWorldOnB * rel_vel;
|
cp.m_lateralFrictionDir1 = vel - cp.m_normalWorldOnB * rel_vel;
|
||||||
btScalar lat_rel_vel = cp.m_lateralFrictionDir1.length2();
|
btScalar lat_rel_vel = cp.m_lateralFrictionDir1.length2();
|
||||||
@@ -768,9 +768,12 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|||||||
{
|
{
|
||||||
cp.m_lateralFrictionDir1 /= btSqrt(lat_rel_vel);
|
cp.m_lateralFrictionDir1 /= btSqrt(lat_rel_vel);
|
||||||
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
||||||
|
if(infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING)
|
||||||
|
{
|
||||||
cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB);
|
cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB);
|
||||||
cp.m_lateralFrictionDir2.normalize();//??
|
cp.m_lateralFrictionDir2.normalize();//??
|
||||||
addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
//re-calculate friction direction every frame, todo: check if this is really needed
|
//re-calculate friction direction every frame, todo: check if this is really needed
|
||||||
@@ -784,9 +787,12 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
||||||
|
if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING)
|
||||||
addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING)
|
||||||
|
{
|
||||||
{
|
{
|
||||||
btSolverConstraint& frictionConstraint1 = m_tmpSolverFrictionConstraintPool[solverConstraint.m_frictionIndex];
|
btSolverConstraint& frictionConstraint1 = m_tmpSolverFrictionConstraintPool[solverConstraint.m_frictionIndex];
|
||||||
if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING)
|
if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING)
|
||||||
@@ -816,6 +822,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ protected:
|
|||||||
btScalar solve(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer);
|
btScalar solve(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer);
|
||||||
btScalar solveFriction(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer);
|
btScalar 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);
|
||||||
void addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation);
|
btSolverConstraint& addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation);
|
||||||
|
|
||||||
ContactSolverFunc m_contactDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES];
|
ContactSolverFunc m_contactDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES];
|
||||||
ContactSolverFunc m_frictionDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES];
|
ContactSolverFunc m_frictionDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES];
|
||||||
|
|||||||
Reference in New Issue
Block a user