add penetration depth solver for btCollisionWorld::convexSweepTest, to handle touching/penetrating contact (useful for character controller)

This commit is contained in:
erwin.coumans
2008-05-24 05:22:41 +00:00
parent f8e5481612
commit 3d32cf7ddf
4 changed files with 57 additions and 44 deletions

View File

@@ -18,7 +18,7 @@ subject to the following restrictions:
#include "BulletCollision/CollisionDispatch/btCollisionObject.h" #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
#include "BulletCollision/CollisionShapes/btCollisionShape.h" #include "BulletCollision/CollisionShapes/btCollisionShape.h"
#include "BulletCollision/CollisionShapes/btConvexShape.h" #include "BulletCollision/CollisionShapes/btConvexShape.h"
#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
#include "BulletCollision/CollisionShapes/btSphereShape.h" //for raycasting #include "BulletCollision/CollisionShapes/btSphereShape.h" //for raycasting
#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" //for raycasting #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" //for raycasting
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h" #include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
@@ -403,7 +403,8 @@ void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
btConvexShape* convexShape = (btConvexShape*) collisionShape; btConvexShape* convexShape = (btConvexShape*) collisionShape;
btVoronoiSimplexSolver simplexSolver; btVoronoiSimplexSolver simplexSolver;
btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0); btGjkEpaPenetrationDepthSolver gjkEpaPenetrationSolver;
btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,&gjkEpaPenetrationSolver);
if (convexCaster.calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult)) if (convexCaster.calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
{ {

View File

@@ -21,43 +21,43 @@ misrepresented as being the original software.
/* /*
GJK-EPA collision solver by Nathanael Presson, 2008 GJK-EPA collision solver by Nathanael Presson, 2008
*/ */
#ifndef _68DA1F85_90B7_4bb0_A705_83B4040A75C6_ #ifndef _68DA1F85_90B7_4bb0_A705_83B4040A75C6_
#define _68DA1F85_90B7_4bb0_A705_83B4040A75C6_ #define _68DA1F85_90B7_4bb0_A705_83B4040A75C6_
#include "BulletCollision/CollisionShapes/btConvexShape.h" #include "BulletCollision/CollisionShapes/btConvexShape.h"
///btGjkEpaSolver contributed under zlib by Nathanael Presson ///btGjkEpaSolver contributed under zlib by Nathanael Presson
struct btGjkEpaSolver2 struct btGjkEpaSolver2
{ {
struct sResults struct sResults
{ {
enum eStatus enum eStatus
{ {
Separated, /* Shapes doesnt penetrate */ Separated, /* Shapes doesnt penetrate */
Penetrating, /* Shapes are penetrating */ Penetrating, /* Shapes are penetrating */
GJK_Failed, /* GJK phase fail, no big issue, shapes are probably just 'touching' */ GJK_Failed, /* GJK phase fail, no big issue, shapes are probably just 'touching' */
EPA_Failed /* EPA phase fail, bigger problem, need to save parameters, and debug */ EPA_Failed /* EPA phase fail, bigger problem, need to save parameters, and debug */
} status; } status;
btVector3 witnesses[2]; btVector3 witnesses[2];
btVector3 normal; btVector3 normal;
}; };
static int StackSizeRequirement(); static int StackSizeRequirement();
static btScalar Distance( const btConvexShape* shape0,const btTransform& wtrs0, static btScalar Distance( const btConvexShape* shape0,const btTransform& wtrs0,
const btConvexShape* shape1,const btTransform& wtrs1, const btConvexShape* shape1,const btTransform& wtrs1,
sResults& results); sResults& results);
static btScalar SignedDistance( const btVector3& position, static btScalar SignedDistance( const btVector3& position,
btScalar margin, btScalar margin,
const btConvexShape* shape, const btConvexShape* shape,
const btTransform& wtrs, const btTransform& wtrs,
sResults& results); sResults& results);
static bool Penetration(const btConvexShape* shape0,const btTransform& wtrs0, static bool Penetration(const btConvexShape* shape0,const btTransform& wtrs0,
const btConvexShape* shape1,const btTransform& wtrs1, const btConvexShape* shape1,const btTransform& wtrs1,
const btVector3& guess, const btVector3& guess,
sResults& results); sResults& results);
}; };
#endif #endif

View File

@@ -18,6 +18,7 @@ subject to the following restrictions:
#include "BulletCollision/CollisionShapes/btConvexShape.h" #include "BulletCollision/CollisionShapes/btConvexShape.h"
#include "btGjkEpaPenetrationDepthSolver.h" #include "btGjkEpaPenetrationDepthSolver.h"
#include "BulletCollision/NarrowPhaseCollision/btGjkEpa.h" #include "BulletCollision/NarrowPhaseCollision/btGjkEpa.h"
#include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
bool btGjkEpaPenetrationDepthSolver::calcPenDepth( btSimplexSolverInterface& simplexSolver, bool btGjkEpaPenetrationDepthSolver::calcPenDepth( btSimplexSolverInterface& simplexSolver,
const btConvexShape* pConvexA, const btConvexShape* pConvexB, const btConvexShape* pConvexA, const btConvexShape* pConvexB,
@@ -32,10 +33,20 @@ bool btGjkEpaPenetrationDepthSolver::calcPenDepth( btSimplexSolverInterface& sim
const btScalar radialmargin(btScalar(0.)); const btScalar radialmargin(btScalar(0.));
//#define USE_ORIGINAL_GJK 1
#ifdef USE_ORIGINAL_GJK
btGjkEpaSolver::sResults results; btGjkEpaSolver::sResults results;
if(btGjkEpaSolver::Collide( pConvexA,transformA, if(btGjkEpaSolver::Collide( pConvexA,transformA,
pConvexB,transformB, pConvexB,transformB,
radialmargin,stackAlloc,results)) radialmargin,stackAlloc,results))
#else
btVector3 guessVector(transformA.getOrigin()-transformB.getOrigin());
btGjkEpaSolver2::sResults results;
if(btGjkEpaSolver2::Penetration(pConvexA,transformA,
pConvexB,transformB,
guessVector,results))
#endif
{ {
// debugDraw->drawLine(results.witnesses[1],results.witnesses[1]+results.normal,btVector3(255,0,0)); // debugDraw->drawLine(results.witnesses[1],results.witnesses[1]+results.normal,btVector3(255,0,0));
//resultOut->addContactPoint(results.normal,results.witnesses[1],-results.depth); //resultOut->addContactPoint(results.normal,results.witnesses[1],-results.depth);

View File

@@ -20,6 +20,7 @@ subject to the following restrictions:
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h" #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
#include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h" #include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
#include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h" #include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
#include "btRaycastCallback.h" #include "btRaycastCallback.h"
btTriangleRaycastCallback::btTriangleRaycastCallback(const btVector3& from,const btVector3& to) btTriangleRaycastCallback::btTriangleRaycastCallback(const btVector3& from,const btVector3& to)
@@ -122,7 +123,7 @@ btTriangleConvexcastCallback::processTriangle (btVector3* triangle, int partId,
triangleShape.setMargin(m_triangleCollisionMargin); triangleShape.setMargin(m_triangleCollisionMargin);
btVoronoiSimplexSolver simplexSolver; btVoronoiSimplexSolver simplexSolver;
btGjkEpaPenetrationDepthSolver gjkEpaPenetrationSolver;
//#define USE_SUBSIMPLEX_CONVEX_CAST 1 //#define USE_SUBSIMPLEX_CONVEX_CAST 1
//if you reenable USE_SUBSIMPLEX_CONVEX_CAST see commented out code below //if you reenable USE_SUBSIMPLEX_CONVEX_CAST see commented out code below
@@ -130,7 +131,7 @@ btTriangleConvexcastCallback::processTriangle (btVector3* triangle, int partId,
btSubsimplexConvexCast convexCaster(m_convexShape, &triangleShape, &simplexSolver); btSubsimplexConvexCast convexCaster(m_convexShape, &triangleShape, &simplexSolver);
#else #else
//btGjkConvexCast convexCaster(m_convexShape,&triangleShape,&simplexSolver); //btGjkConvexCast convexCaster(m_convexShape,&triangleShape,&simplexSolver);
btContinuousConvexCollision convexCaster(m_convexShape,&triangleShape,&simplexSolver,NULL); btContinuousConvexCollision convexCaster(m_convexShape,&triangleShape,&simplexSolver,&gjkEpaPenetrationSolver);
#endif //#USE_SUBSIMPLEX_CONVEX_CAST #endif //#USE_SUBSIMPLEX_CONVEX_CAST
btConvexCast::CastResult castResult; btConvexCast::CastResult castResult;