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:
@@ -121,7 +121,10 @@ void ConcaveDemo::initPhysics()
|
|||||||
{
|
{
|
||||||
for (int j=0;j<NUM_VERTS_Y;j++)
|
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;
|
float mass = 0.f;
|
||||||
btTransform startTransform;
|
btTransform startTransform;
|
||||||
startTransform.setIdentity();
|
startTransform.setIdentity();
|
||||||
startTransform.setOrigin(btVector3(0,0,0));
|
startTransform.setOrigin(btVector3(0,-2,0));
|
||||||
|
|
||||||
btRigidBody* staticBody = localCreateRigidBody(mass, startTransform,trimeshShape);
|
btRigidBody* staticBody = localCreateRigidBody(mass, startTransform,trimeshShape);
|
||||||
|
|
||||||
|
|||||||
@@ -65,9 +65,20 @@ void GL_ShapeDrawer::drawCoordSystem() {
|
|||||||
|
|
||||||
class GlDrawcallback : public btTriangleCallback
|
class GlDrawcallback : public btTriangleCallback
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
bool m_wireframe;
|
||||||
|
|
||||||
|
GlDrawcallback()
|
||||||
|
:m_wireframe(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex)
|
virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (m_wireframe)
|
||||||
{
|
{
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glColor3f(1, 0, 0);
|
glColor3f(1, 0, 0);
|
||||||
@@ -80,7 +91,17 @@ public:
|
|||||||
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
||||||
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
||||||
glEnd();
|
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);
|
btVector3 aabbMin(-1e30f,-1e30f,-1e30f);
|
||||||
|
|
||||||
GlDrawcallback drawCallback;
|
GlDrawcallback drawCallback;
|
||||||
|
drawCallback.m_wireframe = (debugMode & btIDebugDraw::DBG_DrawWireframe)!=0;
|
||||||
|
|
||||||
concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
|
concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
|
||||||
|
|
||||||
|
|||||||
@@ -320,7 +320,9 @@ inline bool originInTetrahedron(const btVector3& p1, const btVector3& p2,
|
|||||||
bool Solid3EpaPenetrationDepth::calcPenDepth( btSimplexSolverInterface& simplexSolver,
|
bool Solid3EpaPenetrationDepth::calcPenDepth( btSimplexSolverInterface& simplexSolver,
|
||||||
btConvexShape* convexA,btConvexShape* convexB,
|
btConvexShape* convexA,btConvexShape* convexB,
|
||||||
const btTransform& transformA,const btTransform& transformB,
|
const btTransform& transformA,const btTransform& transformB,
|
||||||
btVector3& v, btPoint3& pa, btPoint3& pb)
|
btVector3& v, btPoint3& pa, btPoint3& pb,
|
||||||
|
class btIDebugDraw* debugDraw
|
||||||
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
int num_verts = simplexSolver.getSimplex(pBuf, qBuf, yBuf);
|
int num_verts = simplexSolver.getSimplex(pBuf, qBuf, yBuf);
|
||||||
|
|||||||
@@ -34,8 +34,10 @@ public:
|
|||||||
|
|
||||||
virtual bool calcPenDepth( btSimplexSolverInterface& simplexSolver,
|
virtual bool calcPenDepth( btSimplexSolverInterface& simplexSolver,
|
||||||
btConvexShape* convexA,btConvexShape* convexB,
|
btConvexShape* convexA,btConvexShape* convexB,
|
||||||
const btTransform& transformA,const btTransform& transformB,
|
const btTransform& transA,const btTransform& transB,
|
||||||
btVector3& v, btPoint3& pa, btPoint3& pb);
|
btVector3& v, btPoint3& pa, btPoint3& pb,
|
||||||
|
class btIDebugDraw* debugDraw
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
2
VERSION
2
VERSION
@@ -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
|
http://bullet.sourceforge.net
|
||||||
|
|
||||||
|
|||||||
@@ -255,6 +255,37 @@ public:
|
|||||||
return "Box";
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
//todo: get rid of this btConvexCastResult thing!
|
//todo: get rid of this btConvexCastResult thing!
|
||||||
struct btConvexCastResult;
|
struct btConvexCastResult;
|
||||||
|
#define MAX_PREFERRED_PENETRATION_DIRECTIONS 10
|
||||||
|
|
||||||
/// btConvexShape is an abstract shape interface.
|
/// btConvexShape is an abstract shape interface.
|
||||||
/// The explicit part provides plane-equations, the implicit part provides GetClosestPoint interface.
|
/// The explicit part provides plane-equations, the implicit part provides GetClosestPoint interface.
|
||||||
@@ -84,6 +84,17 @@ public:
|
|||||||
return m_collisionMargin;
|
return m_collisionMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual int getNumPreferredPenetrationDirections() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
|
||||||
|
{
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -157,6 +157,18 @@ public:
|
|||||||
return "Triangle";
|
return "Triangle";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual int getNumPreferredPenetrationDirections() const
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
|
||||||
|
{
|
||||||
|
calcNormal(penetrationVector);
|
||||||
|
if (index)
|
||||||
|
penetrationVector *= -1.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ struct MyResult : public btDiscreteCollisionDetectorInterface::Result
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define NUM_UNITSPHERE_POINTS 42
|
#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.000000f , -0.000000f,-1.000000f),
|
||||||
btVector3(0.723608f , -0.525725f,-0.447219f),
|
btVector3(0.723608f , -0.525725f,-0.447219f),
|
||||||
@@ -110,22 +110,62 @@ bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& s
|
|||||||
|
|
||||||
#define USE_BATCHED_SUPPORT 1
|
#define USE_BATCHED_SUPPORT 1
|
||||||
#ifdef USE_BATCHED_SUPPORT
|
#ifdef USE_BATCHED_SUPPORT
|
||||||
btVector3 supportVerticesABatch[NUM_UNITSPHERE_POINTS];
|
|
||||||
btVector3 supportVerticesBBatch[NUM_UNITSPHERE_POINTS];
|
btVector3 supportVerticesABatch[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
|
||||||
btVector3 seperatingAxisInABatch[NUM_UNITSPHERE_POINTS];
|
btVector3 supportVerticesBBatch[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
|
||||||
btVector3 seperatingAxisInBBatch[NUM_UNITSPHERE_POINTS];
|
btVector3 seperatingAxisInABatch[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
|
||||||
|
btVector3 seperatingAxisInBBatch[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
|
||||||
int i;
|
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];
|
const btVector3& norm = sPenetrationDirections[i];
|
||||||
seperatingAxisInABatch[i] = (-norm) * transA.getBasis() ;
|
seperatingAxisInABatch[i] = (-norm) * transA.getBasis() ;
|
||||||
seperatingAxisInBBatch[i] = norm * transB.getBasis() ;
|
seperatingAxisInBBatch[i] = norm * transB.getBasis() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
convexA->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInABatch,supportVerticesABatch,NUM_UNITSPHERE_POINTS);
|
{
|
||||||
convexB->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInBBatch,supportVerticesBBatch,NUM_UNITSPHERE_POINTS);
|
int numPDA = convexA->getNumPreferredPenetrationDirections();
|
||||||
for (i=0;i<NUM_UNITSPHERE_POINTS;i++)
|
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];
|
const btVector3& norm = sPenetrationDirections[i];
|
||||||
seperatingAxisInA = seperatingAxisInABatch[i];
|
seperatingAxisInA = seperatingAxisInABatch[i];
|
||||||
@@ -148,7 +188,40 @@ bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#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];
|
const btVector3& norm = sPenetrationDirections[i];
|
||||||
seperatingAxisInA = (-norm)* transA.getBasis();
|
seperatingAxisInA = (-norm)* transA.getBasis();
|
||||||
|
|||||||
Reference in New Issue
Block a user