remove speculative contacts, they break restitution and cause other artifacts
use btConvexPolyhedron for debug rendering, if available fixes in btConvexConvexAlgorithm for polyhedral contact clipping, if GJK separating normal is zero don't shift vertices in btPolyhedralConvexShape
This commit is contained in:
1 parent
ad76b3222f
commit
642a6821a5
10 files changed
+127
-219
No files matched your search
@@ -327,9 +327,6 @@ void btDiscreteDynamicsWorld::internalSingleStepSimulation(btScalar timeStep)
|
||||
///perform collision detection
|
||||
performDiscreteCollisionDetection();
|
||||
|
||||
if (getDispatchInfo().m_useContinuous)
|
||||
addSpeculativeContacts(timeStep);
|
||||
|
||||
|
||||
calculateSimulationIslands();
|
||||
|
||||
@@ -951,114 +948,6 @@ void btDiscreteDynamicsWorld::integrateTransforms(btScalar timeStep)
|
||||
}
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::addSpeculativeContacts(btScalar timeStep)
|
||||
{
|
||||
BT_PROFILE("addSpeculativeContacts");
|
||||
btTransform predictedTrans;
|
||||
for ( int i=0;i<m_nonStaticRigidBodies.size();i++)
|
||||
{
|
||||
btRigidBody* body = m_nonStaticRigidBodies[i];
|
||||
body->setHitFraction(1.f);
|
||||
|
||||
if (body->isActive() && (!body->isStaticOrKinematicObject()))
|
||||
{
|
||||
body->predictIntegratedTransform(timeStep, predictedTrans);
|
||||
btScalar squareMotion = (predictedTrans.getOrigin()-body->getWorldTransform().getOrigin()).length2();
|
||||
|
||||
if (body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion)
|
||||
{
|
||||
BT_PROFILE("search speculative contacts");
|
||||
if (body->getCollisionShape()->isConvex())
|
||||
{
|
||||
gNumClampedCcdMotions++;
|
||||
|
||||
btClosestNotMeConvexResultCallback sweepResults(body,body->getWorldTransform().getOrigin(),predictedTrans.getOrigin(),getBroadphase()->getOverlappingPairCache(),getDispatcher());
|
||||
//btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape());
|
||||
btSphereShape tmpSphere(body->getCcdSweptSphereRadius());//btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape());
|
||||
|
||||
sweepResults.m_collisionFilterGroup = body->getBroadphaseProxy()->m_collisionFilterGroup;
|
||||
sweepResults.m_collisionFilterMask = body->getBroadphaseProxy()->m_collisionFilterMask;
|
||||
btTransform modifiedPredictedTrans;
|
||||
modifiedPredictedTrans = predictedTrans;
|
||||
modifiedPredictedTrans.setBasis(body->getWorldTransform().getBasis());
|
||||
|
||||
convexSweepTest(&tmpSphere,body->getWorldTransform(),modifiedPredictedTrans,sweepResults);
|
||||
if (sweepResults.hasHit() && (sweepResults.m_closestHitFraction < 1.f))
|
||||
{
|
||||
btBroadphaseProxy* proxy0 = body->getBroadphaseHandle();
|
||||
btBroadphaseProxy* proxy1 = sweepResults.m_hitCollisionObject->getBroadphaseHandle();
|
||||
btBroadphasePair* pair = sweepResults.m_pairCache->findPair(proxy0,proxy1);
|
||||
if (pair)
|
||||
{
|
||||
if (pair->m_algorithm)
|
||||
{
|
||||
btManifoldArray contacts;
|
||||
pair->m_algorithm->getAllContactManifolds(contacts);
|
||||
if (contacts.size())
|
||||
{
|
||||
btManifoldResult result(body,sweepResults.m_hitCollisionObject);
|
||||
result.setPersistentManifold(contacts[0]);
|
||||
|
||||
btVector3 vec = (modifiedPredictedTrans.getOrigin()-body->getWorldTransform().getOrigin());
|
||||
vec*=sweepResults.m_closestHitFraction;
|
||||
|
||||
btScalar lenSqr = vec.length2();
|
||||
btScalar depth = 0.f;
|
||||
btVector3 pointWorld = sweepResults.m_hitPointWorld;
|
||||
if (lenSqr>SIMD_EPSILON)
|
||||
{
|
||||
depth = btSqrt(lenSqr);
|
||||
pointWorld -= vec;
|
||||
vec /= depth;
|
||||
}
|
||||
|
||||
if (contacts[0]->getBody0()==body)
|
||||
{
|
||||
result.addContactPoint(sweepResults.m_hitNormalWorld,pointWorld,depth);
|
||||
#if 0
|
||||
debugContacts.push_back(sweepResults.m_hitPointWorld);//sweepResults.m_hitPointWorld);
|
||||
debugNormals.push_back(sweepResults.m_hitNormalWorld);
|
||||
#endif
|
||||
} else
|
||||
{
|
||||
//swapped
|
||||
result.addContactPoint(-sweepResults.m_hitNormalWorld,pointWorld,depth);
|
||||
//sweepResults.m_hitPointWorld,depth);
|
||||
|
||||
#if 0
|
||||
if (1)//firstHit==1)
|
||||
{
|
||||
firstHit=0;
|
||||
debugNormals.push_back(sweepResults.m_hitNormalWorld);
|
||||
debugContacts.push_back(pointWorld);//sweepResults.m_hitPointWorld);
|
||||
debugNormals.push_back(sweepResults.m_hitNormalWorld);
|
||||
debugContacts.push_back(sweepResults.m_hitPointWorld);
|
||||
}
|
||||
firstHit--;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
//no algorithm, use dispatcher to create one
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else
|
||||
{
|
||||
//add an overlapping pair
|
||||
//printf("pair missing\n");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -62,8 +62,6 @@ protected:
|
||||
|
||||
virtual void integrateTransforms(btScalar timeStep);
|
||||
|
||||
virtual void addSpeculativeContacts(btScalar timeStep);
|
||||
|
||||
virtual void calculateSimulationIslands();
|
||||
|
||||
virtual void solveConstraints(btContactSolverInfo& solverInfo);
|
||||
|
||||
Reference in new issue
Block a user