improved robustness of penetrations involving triangles and boxes, by adding their 'preferred' penetration directions.

added wireframe/solid mode for meshes
updated solid penetration depth solver (comparison in Extras)
This commit is contained in:
ejcoumans
2006-11-05 05:12:10 +00:00
parent 6c61060339
commit 074e2b2d3b
9 changed files with 189 additions and 33 deletions

View File

@@ -121,7 +121,10 @@ void ConcaveDemo::initPhysics()
{
for (int j=0;j<NUM_VERTS_Y;j++)
{
gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,2.f*sinf((float)i)*cosf((float)j),(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
//0.f,
2.f*sinf((float)i)*cosf((float)j),
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
}
}
@@ -156,7 +159,7 @@ void ConcaveDemo::initPhysics()
float mass = 0.f;
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,0,0));
startTransform.setOrigin(btVector3(0,-2,0));
btRigidBody* staticBody = localCreateRigidBody(mass, startTransform,trimeshShape);

View File

@@ -65,22 +65,43 @@ void GL_ShapeDrawer::drawCoordSystem() {
class GlDrawcallback : public btTriangleCallback
{
public:
bool m_wireframe;
GlDrawcallback()
:m_wireframe(false)
{
}
virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex)
{
glBegin(GL_LINES);
glColor3f(1, 0, 0);
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
glColor3f(0, 1, 0);
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
glColor3f(0, 0, 1);
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
glEnd();
if (m_wireframe)
{
glBegin(GL_LINES);
glColor3f(1, 0, 0);
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
glColor3f(0, 1, 0);
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
glColor3f(0, 0, 1);
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
glEnd();
} else
{
glBegin(GL_TRIANGLES);
glColor3f(1, 0, 0);
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
glColor3f(0, 1, 0);
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
glColor3f(0, 0, 1);
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
glEnd();
}
}
};
@@ -312,6 +333,7 @@ void GL_ShapeDrawer::drawOpenGL(float* m, const btCollisionShape* shape, const b
btVector3 aabbMin(-1e30f,-1e30f,-1e30f);
GlDrawcallback drawCallback;
drawCallback.m_wireframe = (debugMode & btIDebugDraw::DBG_DrawWireframe)!=0;
concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);

View File

@@ -318,9 +318,11 @@ inline bool originInTetrahedron(const btVector3& p1, const btVector3& p2,
bool Solid3EpaPenetrationDepth::calcPenDepth( btSimplexSolverInterface& simplexSolver,
btConvexShape* convexA,btConvexShape* convexB,
const btTransform& transformA,const btTransform& transformB,
btVector3& v, btPoint3& pa, btPoint3& pb)
btConvexShape* convexA,btConvexShape* convexB,
const btTransform& transformA,const btTransform& transformB,
btVector3& v, btPoint3& pa, btPoint3& pb,
class btIDebugDraw* debugDraw
)
{
int num_verts = simplexSolver.getSimplex(pBuf, qBuf, yBuf);

View File

@@ -32,10 +32,12 @@ class Solid3EpaPenetrationDepth : public btConvexPenetrationDepthSolver
{
public:
virtual bool calcPenDepth(btSimplexSolverInterface& simplexSolver,
virtual bool calcPenDepth( btSimplexSolverInterface& simplexSolver,
btConvexShape* convexA,btConvexShape* convexB,
const btTransform& transformA,const btTransform& transformB,
btVector3& v, btPoint3& pa, btPoint3& pb);
const btTransform& transA,const btTransform& transB,
btVector3& v, btPoint3& pa, btPoint3& pb,
class btIDebugDraw* debugDraw
);
};

View File

@@ -1,3 +1,3 @@
Bullet Collision Detection and Physics Library version 2.20
Bullet Collision Detection and Physics Library version 2.22
http://bullet.sourceforge.net

View File

@@ -255,6 +255,37 @@ public:
return "Box";
}
virtual int getNumPreferredPenetrationDirections() const
{
return 6;
}
virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
{
switch (index)
{
case 0:
penetrationVector.setValue(1.f,0.f,0.f);
break;
case 1:
penetrationVector.setValue(-1.f,0.f,0.f);
break;
case 2:
penetrationVector.setValue(0.f,1.f,0.f);
break;
case 3:
penetrationVector.setValue(0.f,-1.f,0.f);
break;
case 4:
penetrationVector.setValue(0.f,0.f,1.f);
break;
case 5:
penetrationVector.setValue(0.f,0.f,-1.f);
break;
default:
assert(0);
}
}
};

View File

@@ -26,7 +26,7 @@ subject to the following restrictions:
//todo: get rid of this btConvexCastResult thing!
struct btConvexCastResult;
#define MAX_PREFERRED_PENETRATION_DIRECTIONS 10
/// btConvexShape is an abstract shape interface.
/// The explicit part provides plane-equations, the implicit part provides GetClosestPoint interface.
@@ -84,6 +84,17 @@ public:
return m_collisionMargin;
}
virtual int getNumPreferredPenetrationDirections() const
{
return 0;
}
virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
{
assert(0);
}
};

View File

@@ -157,6 +157,18 @@ public:
return "Triangle";
}
virtual int getNumPreferredPenetrationDirections() const
{
return 2;
}
virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
{
calcNormal(penetrationVector);
if (index)
penetrationVector *= -1.f;
}
};

View File

@@ -45,7 +45,7 @@ struct MyResult : public btDiscreteCollisionDetectorInterface::Result
};
#define NUM_UNITSPHERE_POINTS 42
static btVector3 sPenetrationDirections[NUM_UNITSPHERE_POINTS] =
static btVector3 sPenetrationDirections[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =
{
btVector3(0.000000f , -0.000000f,-1.000000f),
btVector3(0.723608f , -0.525725f,-0.447219f),
@@ -110,22 +110,62 @@ bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& s
#define USE_BATCHED_SUPPORT 1
#ifdef USE_BATCHED_SUPPORT
btVector3 supportVerticesABatch[NUM_UNITSPHERE_POINTS];
btVector3 supportVerticesBBatch[NUM_UNITSPHERE_POINTS];
btVector3 seperatingAxisInABatch[NUM_UNITSPHERE_POINTS];
btVector3 seperatingAxisInBBatch[NUM_UNITSPHERE_POINTS];
btVector3 supportVerticesABatch[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
btVector3 supportVerticesBBatch[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
btVector3 seperatingAxisInABatch[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
btVector3 seperatingAxisInBBatch[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
int i;
for (i=0;i<NUM_UNITSPHERE_POINTS;i++)
int numSampleDirections = NUM_UNITSPHERE_POINTS;
for (i=0;i<numSampleDirections;i++)
{
const btVector3& norm = sPenetrationDirections[i];
seperatingAxisInABatch[i] = (-norm)* transA.getBasis();
seperatingAxisInBBatch[i] = norm * transB.getBasis();
seperatingAxisInABatch[i] = (-norm) * transA.getBasis() ;
seperatingAxisInBBatch[i] = norm * transB.getBasis() ;
}
convexA->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInABatch,supportVerticesABatch,NUM_UNITSPHERE_POINTS);
convexB->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInBBatch,supportVerticesBBatch,NUM_UNITSPHERE_POINTS);
for (i=0;i<NUM_UNITSPHERE_POINTS;i++)
{
int numPDA = convexA->getNumPreferredPenetrationDirections();
if (numPDA)
{
for (int i=0;i<numPDA;i++)
{
btVector3 norm;
convexA->getPreferredPenetrationDirection(i,norm);
norm = transA.getBasis() * norm;
sPenetrationDirections[numSampleDirections] = norm;
seperatingAxisInABatch[numSampleDirections] = (-norm) * transA.getBasis();
seperatingAxisInBBatch[numSampleDirections] = norm * transB.getBasis();
numSampleDirections++;
}
}
}
{
int numPDB = convexB->getNumPreferredPenetrationDirections();
if (numPDB)
{
for (int i=0;i<numPDB;i++)
{
btVector3 norm;
convexB->getPreferredPenetrationDirection(i,norm);
norm = transB.getBasis() * norm;
sPenetrationDirections[numSampleDirections] = norm;
seperatingAxisInABatch[numSampleDirections] = (-norm) * transA.getBasis();
seperatingAxisInBBatch[numSampleDirections] = norm * transB.getBasis();
numSampleDirections++;
}
}
}
convexA->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInABatch,supportVerticesABatch,numSampleDirections);
convexB->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInBBatch,supportVerticesBBatch,numSampleDirections);
for (i=0;i<numSampleDirections;i++)
{
const btVector3& norm = sPenetrationDirections[i];
seperatingAxisInA = seperatingAxisInABatch[i];
@@ -148,7 +188,40 @@ bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& s
}
}
#else
for (int i=0;i<NUM_UNITSPHERE_POINTS;i++)
int numSampleDirections = NUM_UNITSPHERE_POINTS;
{
int numPDA = convexA->getNumPreferredPenetrationDirections();
if (numPDA)
{
for (int i=0;i<numPDA;i++)
{
btVector3 norm;
convexA->getPreferredPenetrationDirection(i,norm);
norm = transA.getBasis() * norm;
sPenetrationDirections[numSampleDirections] = norm;
numSampleDirections++;
}
}
}
{
int numPDB = convexB->getNumPreferredPenetrationDirections();
if (numPDB)
{
for (int i=0;i<numPDB;i++)
{
btVector3 norm;
convexB->getPreferredPenetrationDirection(i,norm);
norm = transB.getBasis() * norm;
sPenetrationDirections[numSampleDirections] = norm;
numSampleDirections++;
}
}
}
for (int i=0;i<numSampleDirections;i++)
{
const btVector3& norm = sPenetrationDirections[i];
seperatingAxisInA = (-norm)* transA.getBasis();