Calculate multiple contact points (for convex-convex and convex-plane) when less then 3 points exist in the persistent manifold.

Uses the normal pertubation method, described by Gino van den Bergen:  http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=4&t=288&p=888#p888
Made btRigidBody::getInvInertiaDiagLocal const, thanks to abhikp (http://code.google.com/p/bullet/issues/detail?id=183 )
This commit is contained in:
erwin.coumans
2009-02-03 00:54:01 +00:00
parent bcbe730471
commit 0754876d77
7 changed files with 145 additions and 30 deletions

View File

@@ -22,13 +22,13 @@ subject to the following restrictions:
//#include <stdio.h>
btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped, int numPertubationIterations,btScalar pertubeAngle)
btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped, int numPertubationIterations,int minimumPointsPertubationThreshold)
: btCollisionAlgorithm(ci),
m_ownManifold(false),
m_manifoldPtr(mf),
m_isSwapped(isSwapped),
m_numPertubationIterations(numPertubationIterations),
m_pertubeAngle(pertubeAngle)
m_minimumPointsPertubationThreshold(minimumPointsPertubationThreshold)
{
btCollisionObject* convexObj = m_isSwapped? col1 : col0;
btCollisionObject* planeObj = m_isSwapped? col0 : col1;
@@ -89,6 +89,7 @@ void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion&
}
}
void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
{
(void)dispatchInfo;
@@ -105,23 +106,33 @@ void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0
const btVector3& planeNormal = planeShape->getPlaneNormal();
const btScalar& planeConstant = planeShape->getPlaneConstant();
btVector3 v0,v1;
btPlaneSpace1(planeNormal,v0,v1);
//first perform a collision query with the non-pertubated collision objects
{
btQuaternion rotq(0,0,0,1);
collideSingleContact(rotq,body0,body1,dispatchInfo,resultOut);
}
//now perform 'm_numPertubationIterations' collision queries with the pertubated collision objects
btQuaternion pertubeRot(v0,m_pertubeAngle);
for (int i=0;i<m_numPertubationIterations;i++)
{
btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPertubationIterations));
btQuaternion rotq(planeNormal,iterationAngle);
collideSingleContact(rotq.inverse()*pertubeRot*rotq,body0,body1,dispatchInfo,resultOut);
}
if (resultOut->getPersistentManifold()->getNumContacts()<m_minimumPointsPertubationThreshold)
{
btVector3 v0,v1;
btPlaneSpace1(planeNormal,v0,v1);
//now perform 'm_numPertubationIterations' collision queries with the pertubated collision objects
const btScalar angleLimit = 0.125f * SIMD_PI;
btScalar pertubeAngle;
btScalar radius = convexShape->getAngularMotionDisc();
pertubeAngle = gContactBreakingThreshold / radius;
if ( pertubeAngle > angleLimit )
pertubeAngle = angleLimit;
btQuaternion pertubeRot(v0,pertubeAngle);
for (int i=0;i<m_numPertubationIterations;i++)
{
btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPertubationIterations));
btQuaternion rotq(planeNormal,iterationAngle);
collideSingleContact(rotq.inverse()*pertubeRot*rotq,body0,body1,dispatchInfo,resultOut);
}
}
if (m_ownManifold)
{