diff --git a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp index d8e13758c..007d7fa1f 100644 --- a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp +++ b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp @@ -121,7 +121,10 @@ void ConcaveDemo::initPhysics() { for (int j=0;jprocessAllTriangles(&drawCallback,aabbMin,aabbMax); diff --git a/Extras/ExtraSolid35/Solid3EpaPenetrationDepth.cpp b/Extras/ExtraSolid35/Solid3EpaPenetrationDepth.cpp index 52723d85a..80b001af9 100644 --- a/Extras/ExtraSolid35/Solid3EpaPenetrationDepth.cpp +++ b/Extras/ExtraSolid35/Solid3EpaPenetrationDepth.cpp @@ -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); diff --git a/Extras/ExtraSolid35/Solid3EpaPenetrationDepth.h b/Extras/ExtraSolid35/Solid3EpaPenetrationDepth.h index d1757202f..501beac27 100644 --- a/Extras/ExtraSolid35/Solid3EpaPenetrationDepth.h +++ b/Extras/ExtraSolid35/Solid3EpaPenetrationDepth.h @@ -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 + ); }; diff --git a/VERSION b/VERSION index afbce2d01..b49971824 100644 --- a/VERSION +++ b/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 diff --git a/src/BulletCollision/CollisionShapes/btBoxShape.h b/src/BulletCollision/CollisionShapes/btBoxShape.h index b137eb115..e85a36c0b 100644 --- a/src/BulletCollision/CollisionShapes/btBoxShape.h +++ b/src/BulletCollision/CollisionShapes/btBoxShape.h @@ -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); + } + } }; diff --git a/src/BulletCollision/CollisionShapes/btConvexShape.h b/src/BulletCollision/CollisionShapes/btConvexShape.h index 3ffde1ba5..0de334b35 100644 --- a/src/BulletCollision/CollisionShapes/btConvexShape.h +++ b/src/BulletCollision/CollisionShapes/btConvexShape.h @@ -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); + } + + }; diff --git a/src/BulletCollision/CollisionShapes/btTriangleShape.h b/src/BulletCollision/CollisionShapes/btTriangleShape.h index 8f0a06f75..8e6e2daa4 100644 --- a/src/BulletCollision/CollisionShapes/btTriangleShape.h +++ b/src/BulletCollision/CollisionShapes/btTriangleShape.h @@ -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; + } + }; diff --git a/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp b/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp index 34daacf26..6b2112ef3 100644 --- a/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp +++ b/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp @@ -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;ibatchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInABatch,supportVerticesABatch,NUM_UNITSPHERE_POINTS); - convexB->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInBBatch,supportVerticesBBatch,NUM_UNITSPHERE_POINTS); - for (i=0;igetNumPreferredPenetrationDirections(); + if (numPDA) + { + for (int i=0;igetPreferredPenetrationDirection(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;igetPreferredPenetrationDirection(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;igetNumPreferredPenetrationDirections(); + if (numPDA) + { + for (int i=0;igetPreferredPenetrationDirection(i,norm); + norm = transA.getBasis() * norm; + sPenetrationDirections[numSampleDirections] = norm; + numSampleDirections++; + } + } + } + + { + int numPDB = convexB->getNumPreferredPenetrationDirections(); + if (numPDB) + { + for (int i=0;igetPreferredPenetrationDirection(i,norm); + norm = transB.getBasis() * norm; + sPenetrationDirections[numSampleDirections] = norm; + numSampleDirections++; + } + } + } + + for (int i=0;i