disable constraints when they exceed a breaking threshold, control it with new methods in btTypedConstraint: get/setBreakingImpulseThreshold and get/setEnabled
Disabled constraints are not removed from the world and they use negligible CPU cycles
This commit is contained in:
@@ -805,7 +805,14 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
for (i=0;i<numConstraints;i++)
|
||||
{
|
||||
btTypedConstraint::btConstraintInfo1& info1 = m_tmpConstraintSizesPool[i];
|
||||
constraints[i]->getInfo1(&info1);
|
||||
if (constraints[i]->isEnabled())
|
||||
{
|
||||
constraints[i]->getInfo1(&info1);
|
||||
} else
|
||||
{
|
||||
info1.m_numConstraintRows = 0;
|
||||
info1.nub = 0;
|
||||
}
|
||||
totalNumRows += info1.m_numConstraintRows;
|
||||
}
|
||||
m_tmpSolverNonContactConstraintPool.resize(totalNumRows);
|
||||
@@ -826,7 +833,6 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
btTypedConstraint* constraint = constraints[i];
|
||||
|
||||
|
||||
|
||||
btRigidBody& rbA = constraint->getRigidBodyA();
|
||||
btRigidBody& rbB = constraint->getRigidBodyB();
|
||||
|
||||
@@ -835,8 +841,8 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
for ( j=0;j<info1.m_numConstraintRows;j++)
|
||||
{
|
||||
memset(¤tConstraintRow[j],0,sizeof(btSolverConstraint));
|
||||
currentConstraintRow[j].m_lowerLimit = -FLT_MAX;
|
||||
currentConstraintRow[j].m_upperLimit = FLT_MAX;
|
||||
currentConstraintRow[j].m_lowerLimit = -SIMD_INFINITY;
|
||||
currentConstraintRow[j].m_upperLimit = SIMD_INFINITY;
|
||||
currentConstraintRow[j].m_appliedImpulse = 0.f;
|
||||
currentConstraintRow[j].m_appliedPushImpulse = 0.f;
|
||||
currentConstraintRow[j].m_solverBodyA = &rbA;
|
||||
@@ -869,6 +875,18 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
info2.m_numIterations = infoGlobal.m_numIterations;
|
||||
constraints[i]->getInfo2(&info2);
|
||||
|
||||
if (currentConstraintRow->m_upperLimit>constraints[i]->getBreakingImpulseThreshold())
|
||||
{
|
||||
currentConstraintRow->m_upperLimit = constraints[i]->getBreakingImpulseThreshold();
|
||||
}
|
||||
|
||||
if (currentConstraintRow->m_lowerLimit<-constraints[i]->getBreakingImpulseThreshold())
|
||||
{
|
||||
currentConstraintRow->m_lowerLimit = -constraints[i]->getBreakingImpulseThreshold();
|
||||
}
|
||||
|
||||
|
||||
|
||||
///finalize the constraint setup
|
||||
for ( j=0;j<info1.m_numConstraintRows;j++)
|
||||
{
|
||||
@@ -1153,9 +1171,11 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyFinish(btCo
|
||||
{
|
||||
const btSolverConstraint& solverConstr = m_tmpSolverNonContactConstraintPool[j];
|
||||
btTypedConstraint* constr = (btTypedConstraint*)solverConstr.m_originalContactPoint;
|
||||
btScalar sum = constr->internalGetAppliedImpulse();
|
||||
sum += solverConstr.m_appliedImpulse;
|
||||
constr->internalSetAppliedImpulse(sum);
|
||||
constr->internalSetAppliedImpulse(solverConstr.m_appliedImpulse);
|
||||
if (solverConstr.m_appliedImpulse>constr->getBreakingImpulseThreshold())
|
||||
{
|
||||
constr->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,9 @@ m_needsFeedback(false),
|
||||
m_rbA(rbA),
|
||||
m_rbB(getFixedBody()),
|
||||
m_appliedImpulse(btScalar(0.)),
|
||||
m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE)
|
||||
m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE),
|
||||
m_breakingImpulseThreshold(SIMD_INFINITY),
|
||||
m_isEnabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -42,7 +44,9 @@ m_needsFeedback(false),
|
||||
m_rbA(rbA),
|
||||
m_rbB(rbB),
|
||||
m_appliedImpulse(btScalar(0.)),
|
||||
m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE)
|
||||
m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE),
|
||||
m_breakingImpulseThreshold(SIMD_INFINITY),
|
||||
m_isEnabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,10 @@ class btTypedConstraint : public btTypedObject
|
||||
void* m_userConstraintPtr;
|
||||
};
|
||||
|
||||
btScalar m_breakingImpulseThreshold;
|
||||
bool m_isEnabled;
|
||||
|
||||
|
||||
bool m_needsFeedback;
|
||||
|
||||
btTypedConstraint& operator=(btTypedConstraint& other)
|
||||
@@ -155,6 +159,28 @@ public:
|
||||
return m_appliedImpulse;
|
||||
}
|
||||
|
||||
|
||||
btScalar getBreakingImpulseThreshold() const
|
||||
{
|
||||
return m_breakingImpulseThreshold;
|
||||
}
|
||||
|
||||
void setBreakingImpulseThreshold(btScalar threshold)
|
||||
{
|
||||
m_breakingImpulseThreshold = threshold;
|
||||
}
|
||||
|
||||
bool isEnabled() const
|
||||
{
|
||||
return m_isEnabled;
|
||||
}
|
||||
|
||||
void setEnabled(bool enabled)
|
||||
{
|
||||
m_isEnabled=enabled;
|
||||
}
|
||||
|
||||
|
||||
///internal method used by the constraint solver, don't use them directly
|
||||
virtual void solveConstraintObsolete(btRigidBody& /*bodyA*/,btRigidBody& /*bodyB*/,btScalar /*timeStep*/) {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user