pass collision shapes as const. fixed some issues with continuous convex cast (resulting hitnormal was not initialized properly, results not proper)

This commit is contained in:
ejcoumans
2007-07-11 02:16:39 +00:00
parent 8c01430151
commit 7cd651c266
14 changed files with 42 additions and 29 deletions

View File

@@ -24,6 +24,9 @@ subject to the following restrictions:
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h" #include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
#include "BulletCollision/CollisionShapes/btCompoundShape.h" #include "BulletCollision/CollisionShapes/btCompoundShape.h"
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h" #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
#include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
#include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
#include "LinearMath/btAabbUtil2.h" #include "LinearMath/btAabbUtil2.h"
#include "LinearMath/btQuickprof.h" #include "LinearMath/btQuickprof.h"
@@ -210,8 +213,8 @@ void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
btConvexShape* convexShape = (btConvexShape*) collisionShape; btConvexShape* convexShape = (btConvexShape*) collisionShape;
btVoronoiSimplexSolver simplexSolver; btVoronoiSimplexSolver simplexSolver;
btSubsimplexConvexCast convexCaster(castShape,convexShape,&simplexSolver); btSubsimplexConvexCast convexCaster(castShape,convexShape,&simplexSolver);
//GjkConvexCast convexCaster(castShape,convexShape,&simplexSolver); //btGjkConvexCast convexCaster(castShape,convexShape,&simplexSolver);
//ContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0); //btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0);
if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,colObjWorldTransform,colObjWorldTransform,castResult)) if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
{ {

View File

@@ -26,7 +26,7 @@ subject to the following restrictions:
btContinuousConvexCollision::btContinuousConvexCollision ( btConvexShape* convexA,btConvexShape* convexB,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* penetrationDepthSolver) btContinuousConvexCollision::btContinuousConvexCollision ( const btConvexShape* convexA,const btConvexShape* convexB,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* penetrationDepthSolver)
:m_simplexSolver(simplexSolver), :m_simplexSolver(simplexSolver),
m_penetrationDepthSolver(penetrationDepthSolver), m_penetrationDepthSolver(penetrationDepthSolver),
m_convexA(convexA),m_convexB(convexB) m_convexA(convexA),m_convexB(convexB)
@@ -93,7 +93,7 @@ bool btContinuousConvexCollision::calcTimeOfImpact(
btGjkPairDetector::ClosestPointInput input; btGjkPairDetector::ClosestPointInput input;
//we don't use margins during CCD //we don't use margins during CCD
gjk.setIgnoreMargin(true); // gjk.setIgnoreMargin(true);
input.m_transformA = fromA; input.m_transformA = fromA;
input.m_transformB = fromB; input.m_transformB = fromB;
@@ -108,22 +108,26 @@ bool btContinuousConvexCollision::calcTimeOfImpact(
btScalar dist; btScalar dist;
dist = pointCollector1.m_distance; dist = pointCollector1.m_distance;
n = pointCollector1.m_normalOnBInWorld; n = pointCollector1.m_normalOnBInWorld;
//not close enough //not close enough
while (dist > radius) while (dist > radius)
{ {
numIter++; numIter++;
if (numIter > maxIter) if (numIter > maxIter)
{
return false; //todo: report a failure return false; //todo: report a failure
}
btScalar dLambda = btScalar(0.); btScalar dLambda = btScalar(0.);
btScalar projectedLinearVelocity = (linVelB-linVelA).dot(n);
//calculate safe moving fraction from distance / (linear+rotational velocity) //calculate safe moving fraction from distance / (linear+rotational velocity)
//btScalar clippedDist = GEN_min(angularConservativeRadius,dist); //btScalar clippedDist = GEN_min(angularConservativeRadius,dist);
//btScalar clippedDist = dist; //btScalar clippedDist = dist;
btScalar projectedLinearVelocity = (linVelB-linVelA).dot(n);
dLambda = dist / (projectedLinearVelocity+ maxAngularProjectedVelocity); dLambda = dist / (projectedLinearVelocity+ maxAngularProjectedVelocity);
@@ -135,9 +139,14 @@ bool btContinuousConvexCollision::calcTimeOfImpact(
if (lambda < btScalar(0.)) if (lambda < btScalar(0.))
return false; return false;
//todo: next check with relative epsilon //todo: next check with relative epsilon
if (lambda <= lastLambda) if (lambda <= lastLambda)
{
return false;
//n.setValue(0,0,0);
break; break;
}
lastLambda = lambda; lastLambda = lambda;
@@ -163,11 +172,12 @@ bool btContinuousConvexCollision::calcTimeOfImpact(
{ {
//degenerate ?! //degenerate ?!
result.m_fraction = lastLambda; result.m_fraction = lastLambda;
result.m_normal = n; n = pointCollector.m_normalOnBInWorld;
result.m_normal=n;//.setValue(1,1,1);// = n;
return true; return true;
} }
c = pointCollector.m_pointInWorld; c = pointCollector.m_pointInWorld;
n = pointCollector.m_normalOnBInWorld;
dist = pointCollector.m_distance; dist = pointCollector.m_distance;
} else } else
{ {

View File

@@ -30,13 +30,13 @@ class btContinuousConvexCollision : public btConvexCast
{ {
btSimplexSolverInterface* m_simplexSolver; btSimplexSolverInterface* m_simplexSolver;
btConvexPenetrationDepthSolver* m_penetrationDepthSolver; btConvexPenetrationDepthSolver* m_penetrationDepthSolver;
btConvexShape* m_convexA; const btConvexShape* m_convexA;
btConvexShape* m_convexB; const btConvexShape* m_convexB;
public: public:
btContinuousConvexCollision (btConvexShape* shapeA,btConvexShape* shapeB ,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver); btContinuousConvexCollision (const btConvexShape* shapeA,const btConvexShape* shapeB ,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver);
virtual bool calcTimeOfImpact( virtual bool calcTimeOfImpact(
const btTransform& fromA, const btTransform& fromA,

View File

@@ -31,7 +31,7 @@ public:
virtual ~btConvexPenetrationDepthSolver() {}; virtual ~btConvexPenetrationDepthSolver() {};
virtual bool calcPenDepth( btSimplexSolverInterface& simplexSolver, virtual bool calcPenDepth( btSimplexSolverInterface& simplexSolver,
btConvexShape* convexA,btConvexShape* convexB, const btConvexShape* convexA,const btConvexShape* convexB,
const btTransform& transA,const btTransform& transB, const btTransform& transA,const btTransform& transB,
btVector3& v, btPoint3& pa, btPoint3& pb, btVector3& v, btPoint3& pa, btPoint3& pb,
class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc

View File

@@ -22,7 +22,7 @@ subject to the following restrictions:
#include "btPointCollector.h" #include "btPointCollector.h"
btGjkConvexCast::btGjkConvexCast(btConvexShape* convexA,btConvexShape* convexB,btSimplexSolverInterface* simplexSolver) btGjkConvexCast::btGjkConvexCast(const btConvexShape* convexA,const btConvexShape* convexB,btSimplexSolverInterface* simplexSolver)
:m_simplexSolver(simplexSolver), :m_simplexSolver(simplexSolver),
m_convexA(convexA), m_convexA(convexA),
m_convexB(convexB) m_convexB(convexB)

View File

@@ -30,12 +30,12 @@ class btMinkowskiSumShape;
class btGjkConvexCast : public btConvexCast class btGjkConvexCast : public btConvexCast
{ {
btSimplexSolverInterface* m_simplexSolver; btSimplexSolverInterface* m_simplexSolver;
btConvexShape* m_convexA; const btConvexShape* m_convexA;
btConvexShape* m_convexB; const btConvexShape* m_convexB;
public: public:
btGjkConvexCast(btConvexShape* convexA,btConvexShape* convexB,btSimplexSolverInterface* simplexSolver); btGjkConvexCast(const btConvexShape* convexA,const btConvexShape* convexB,btSimplexSolverInterface* simplexSolver);
/// cast a convex against another convex object /// cast a convex against another convex object
virtual bool calcTimeOfImpact( virtual bool calcTimeOfImpact(

View File

@@ -580,8 +580,8 @@ using namespace gjkepa_impl;
// //
bool btGjkEpaSolver::Collide(btConvexShape *shape0,const btTransform &wtrs0, bool btGjkEpaSolver::Collide(const btConvexShape *shape0,const btTransform &wtrs0,
btConvexShape *shape1,const btTransform &wtrs1, const btConvexShape *shape1,const btTransform &wtrs1,
btScalar radialmargin, btScalar radialmargin,
btStackAlloc* stackAlloc, btStackAlloc* stackAlloc,
sResults& results) sResults& results)

View File

@@ -43,8 +43,8 @@ struct sResults
int epa_iterations; int epa_iterations;
int gjk_iterations; int gjk_iterations;
}; };
static bool Collide(btConvexShape* shape0,const btTransform& wtrs0, static bool Collide(const btConvexShape* shape0,const btTransform& wtrs0,
btConvexShape* shape1,const btTransform& wtrs1, const btConvexShape* shape1,const btTransform& wtrs1,
btScalar radialmargin, btScalar radialmargin,
btStackAlloc* stackAlloc, btStackAlloc* stackAlloc,
sResults& results); sResults& results);

View File

@@ -20,7 +20,7 @@ subject to the following restrictions:
#include "BulletCollision/NarrowPhaseCollision/btGjkEpa.h" #include "BulletCollision/NarrowPhaseCollision/btGjkEpa.h"
bool btGjkEpaPenetrationDepthSolver::calcPenDepth( btSimplexSolverInterface& simplexSolver, bool btGjkEpaPenetrationDepthSolver::calcPenDepth( btSimplexSolverInterface& simplexSolver,
btConvexShape* pConvexA, btConvexShape* pConvexB, const btConvexShape* pConvexA, const btConvexShape* pConvexB,
const btTransform& transformA, const btTransform& transformB, const btTransform& transformA, const btTransform& transformB,
btVector3& v, btPoint3& wWitnessOnA, btPoint3& wWitnessOnB, btVector3& v, btPoint3& wWitnessOnA, btPoint3& wWitnessOnB,
class btIDebugDraw* debugDraw, btStackAlloc* stackAlloc ) class btIDebugDraw* debugDraw, btStackAlloc* stackAlloc )

View File

@@ -26,7 +26,7 @@ class btGjkEpaPenetrationDepthSolver : public btConvexPenetrationDepthSolver
public : public :
bool calcPenDepth( btSimplexSolverInterface& simplexSolver, bool calcPenDepth( btSimplexSolverInterface& simplexSolver,
btConvexShape* pConvexA, btConvexShape* pConvexB, const btConvexShape* pConvexA, const btConvexShape* pConvexB,
const btTransform& transformA, const btTransform& transformB, const btTransform& transformA, const btTransform& transformB,
btVector3& v, btPoint3& wWitnessOnA, btPoint3& wWitnessOnB, btVector3& v, btPoint3& wWitnessOnA, btPoint3& wWitnessOnB,
class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc ); class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc );

View File

@@ -35,7 +35,7 @@ int gNumGjkChecks = 0;
btGjkPairDetector::btGjkPairDetector(btConvexShape* objectA,btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver) btGjkPairDetector::btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver)
:m_cachedSeparatingAxis(btScalar(0.),btScalar(0.),btScalar(1.)), :m_cachedSeparatingAxis(btScalar(0.),btScalar(0.),btScalar(1.)),
m_penetrationDepthSolver(penetrationDepthSolver), m_penetrationDepthSolver(penetrationDepthSolver),
m_simplexSolver(simplexSolver), m_simplexSolver(simplexSolver),

View File

@@ -35,8 +35,8 @@ class btGjkPairDetector : public btDiscreteCollisionDetectorInterface
btVector3 m_cachedSeparatingAxis; btVector3 m_cachedSeparatingAxis;
btConvexPenetrationDepthSolver* m_penetrationDepthSolver; btConvexPenetrationDepthSolver* m_penetrationDepthSolver;
btSimplexSolverInterface* m_simplexSolver; btSimplexSolverInterface* m_simplexSolver;
btConvexShape* m_minkowskiA; const btConvexShape* m_minkowskiA;
btConvexShape* m_minkowskiB; const btConvexShape* m_minkowskiB;
bool m_ignoreMargin; bool m_ignoreMargin;
@@ -49,7 +49,7 @@ public:
int m_catchDegeneracies; int m_catchDegeneracies;
btGjkPairDetector(btConvexShape* objectA,btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver); btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver);
virtual ~btGjkPairDetector() {}; virtual ~btGjkPairDetector() {};
virtual void getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw); virtual void getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw);

View File

@@ -71,7 +71,7 @@ btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))
bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& simplexSolver, bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& simplexSolver,
btConvexShape* convexA,btConvexShape* convexB, const btConvexShape* convexA,const btConvexShape* convexB,
const btTransform& transA,const btTransform& transB, const btTransform& transA,const btTransform& transB,
btVector3& v, btPoint3& pa, btPoint3& pb, btVector3& v, btPoint3& pa, btPoint3& pb,
class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc

View File

@@ -25,7 +25,7 @@ class btMinkowskiPenetrationDepthSolver : public btConvexPenetrationDepthSolver
public: public:
virtual bool calcPenDepth( btSimplexSolverInterface& simplexSolver, virtual bool calcPenDepth( btSimplexSolverInterface& simplexSolver,
btConvexShape* convexA,btConvexShape* convexB, const btConvexShape* convexA,const btConvexShape* convexB,
const btTransform& transA,const btTransform& transB, const btTransform& transA,const btTransform& transB,
btVector3& v, btPoint3& pa, btPoint3& pb, btVector3& v, btPoint3& pa, btPoint3& pb,
class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc