Add btBroadphaseInterface::aabbTest. btDbvtBroadphase and btAxisSweep3 should perform well, as long as the raycast accelerator is enabled.
This should fix the btCollisionWorld::contactTest(btCollisionObject* colObj, ContactResultCallback& resultCallback); Thanks to Ola for the report!
This commit is contained in:
@@ -83,11 +83,10 @@ void CollisionInterfaceDemo::initPhysics()
|
|||||||
collisionWorld->setDebugDrawer(&debugDrawer);
|
collisionWorld->setDebugDrawer(&debugDrawer);
|
||||||
|
|
||||||
#ifdef TEST_NOT_ADDING_OBJECTS_TO_WORLD
|
#ifdef TEST_NOT_ADDING_OBJECTS_TO_WORLD
|
||||||
collisionWorld->addCollisionObject(&objects[0]);
|
// collisionWorld->addCollisionObject(&objects[0]);
|
||||||
collisionWorld->addCollisionObject(&objects[1]);
|
collisionWorld->addCollisionObject(&objects[1]);
|
||||||
#endif //TEST_NOT_ADDING_OBJECTS_TO_WORLD
|
#endif //TEST_NOT_ADDING_OBJECTS_TO_WORLD
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -103,7 +102,24 @@ void CollisionInterfaceDemo::clientMoveAndDisplay()
|
|||||||
static btVoronoiSimplexSolver sGjkSimplexSolver;
|
static btVoronoiSimplexSolver sGjkSimplexSolver;
|
||||||
btSimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
|
btSimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
|
||||||
|
|
||||||
|
struct btDrawingResult : public btCollisionWorld::ContactResultCallback
|
||||||
|
{
|
||||||
|
virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
|
||||||
|
{
|
||||||
|
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glColor3f(0, 0, 0);
|
||||||
|
|
||||||
|
btVector3 ptA = cp.getPositionWorldOnA();
|
||||||
|
btVector3 ptB = cp.getPositionWorldOnB();
|
||||||
|
|
||||||
|
glVertex3d(ptA.x(),ptA.y(),ptA.z());
|
||||||
|
glVertex3d(ptB.x(),ptB.y(),ptB.z());
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void CollisionInterfaceDemo::displayCallback(void) {
|
void CollisionInterfaceDemo::displayCallback(void) {
|
||||||
|
|
||||||
@@ -166,12 +182,20 @@ void CollisionInterfaceDemo::displayCallback(void) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
for (i=0;i<numObjects;i++)
|
for (i=0;i<numObjects;i++)
|
||||||
{
|
{
|
||||||
collisionWorld->debugDrawObject(objects[i].getWorldTransform(),objects[i].getCollisionShape(), btVector3(1,1,0));
|
collisionWorld->debugDrawObject(objects[i].getWorldTransform(),objects[i].getCollisionShape(), btVector3(1,1,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btDrawingResult renderCallback;
|
||||||
|
|
||||||
|
//collisionWorld->contactPairTest(&objects[0],&objects[1], renderCallback);
|
||||||
|
collisionWorld->contactTest(&objects[0],renderCallback);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
//another way is to directly query the dispatcher for both objects. The objects don't need to be inserted into the world
|
//another way is to directly query the dispatcher for both objects. The objects don't need to be inserted into the world
|
||||||
|
|
||||||
btCollisionAlgorithm* algo = collisionWorld->getDispatcher()->findAlgorithm(&objects[0],&objects[1]);
|
btCollisionAlgorithm* algo = collisionWorld->getDispatcher()->findAlgorithm(&objects[0],&objects[1]);
|
||||||
@@ -210,6 +234,8 @@ void CollisionInterfaceDemo::displayCallback(void) {
|
|||||||
//you can un-comment out this line, and then all points are removed
|
//you can un-comment out this line, and then all points are removed
|
||||||
//contactManifold->clearManifold();
|
//contactManifold->clearManifold();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -150,6 +150,8 @@ public:
|
|||||||
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
|
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
|
||||||
|
|
||||||
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0));
|
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0));
|
||||||
|
virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
|
||||||
|
|
||||||
|
|
||||||
void quantize(BP_FP_INT_TYPE* out, const btVector3& point, int isMax) const;
|
void quantize(BP_FP_INT_TYPE* out, const btVector3& point, int isMax) const;
|
||||||
///unQuantize should be conservative: aabbMin/aabbMax should be larger then 'getAabb' result
|
///unQuantize should be conservative: aabbMin/aabbMax should be larger then 'getAabb' result
|
||||||
@@ -285,6 +287,31 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::rayTest(const btVector3& rayFrom,cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename BP_FP_INT_TYPE>
|
||||||
|
void btAxisSweep3Internal<BP_FP_INT_TYPE>::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback)
|
||||||
|
{
|
||||||
|
if (m_raycastAccelerator)
|
||||||
|
{
|
||||||
|
m_raycastAccelerator->aabbTest(aabbMin,aabbMax,callback);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
//choose axis?
|
||||||
|
BP_FP_INT_TYPE axis = 0;
|
||||||
|
//for each proxy
|
||||||
|
for (BP_FP_INT_TYPE i=1;i<m_numHandles*2+1;i++)
|
||||||
|
{
|
||||||
|
if (m_pEdges[axis][i].IsMax())
|
||||||
|
{
|
||||||
|
Handle* handle = getHandle(m_pEdges[axis][i].m_handle);
|
||||||
|
if (TestAabbAgainstAabb2(aabbMin,aabbMax,handle->m_aabbMin,handle->m_aabbMax))
|
||||||
|
{
|
||||||
|
callback.process(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <typename BP_FP_INT_TYPE>
|
template <typename BP_FP_INT_TYPE>
|
||||||
|
|||||||
@@ -26,7 +26,14 @@ class btOverlappingPairCache;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct btBroadphaseRayCallback
|
struct btBroadphaseAabbCallback
|
||||||
|
{
|
||||||
|
virtual ~btBroadphaseAabbCallback() {}
|
||||||
|
virtual bool process(const btBroadphaseProxy* proxy) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct btBroadphaseRayCallback : public btBroadphaseAabbCallback
|
||||||
{
|
{
|
||||||
///added some cached data to accelerate ray-AABB tests
|
///added some cached data to accelerate ray-AABB tests
|
||||||
btVector3 m_rayDirectionInverse;
|
btVector3 m_rayDirectionInverse;
|
||||||
@@ -34,7 +41,6 @@ struct btBroadphaseRayCallback
|
|||||||
btScalar m_lambda_max;
|
btScalar m_lambda_max;
|
||||||
|
|
||||||
virtual ~btBroadphaseRayCallback() {}
|
virtual ~btBroadphaseRayCallback() {}
|
||||||
virtual bool process(const btBroadphaseProxy* proxy) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "LinearMath/btVector3.h"
|
#include "LinearMath/btVector3.h"
|
||||||
@@ -54,6 +60,8 @@ public:
|
|||||||
|
|
||||||
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)) = 0;
|
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)) = 0;
|
||||||
|
|
||||||
|
virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback) = 0;
|
||||||
|
|
||||||
///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
|
///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
|
||||||
virtual void calculateOverlappingPairs(btDispatcher* dispatcher)=0;
|
virtual void calculateOverlappingPairs(btDispatcher* dispatcher)=0;
|
||||||
|
|
||||||
|
|||||||
@@ -251,6 +251,32 @@ void btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct BroadphaseAabbTester : btDbvt::ICollide
|
||||||
|
{
|
||||||
|
btBroadphaseAabbCallback& m_aabbCallback;
|
||||||
|
BroadphaseAabbTester(btBroadphaseAabbCallback& orgCallback)
|
||||||
|
:m_aabbCallback(orgCallback)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void Process(const btDbvtNode* leaf)
|
||||||
|
{
|
||||||
|
btDbvtProxy* proxy=(btDbvtProxy*)leaf->data;
|
||||||
|
m_aabbCallback.process(proxy);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void btDbvtBroadphase::aabbTest(const btVector3& aabbMin,const btVector3& aabbMax,btBroadphaseAabbCallback& aabbCallback)
|
||||||
|
{
|
||||||
|
BroadphaseAabbTester callback(aabbCallback);
|
||||||
|
|
||||||
|
const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds=btDbvtVolume::FromMM(aabbMin,aabbMax);
|
||||||
|
//process all children, that overlap with the given AABB bounds
|
||||||
|
m_sets[0].collideTV(m_sets[0].m_root,bounds,callback);
|
||||||
|
m_sets[1].collideTV(m_sets[1].m_root,bounds,callback);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
void btDbvtBroadphase::setAabb( btBroadphaseProxy* absproxy,
|
void btDbvtBroadphase::setAabb( btBroadphaseProxy* absproxy,
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ struct btDbvtBroadphase : btBroadphaseInterface
|
|||||||
virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
|
virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
|
||||||
virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
|
virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
|
||||||
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0));
|
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0));
|
||||||
|
virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
|
||||||
|
|
||||||
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
|
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
|
||||||
virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
|
virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ subject to the following restrictions:
|
|||||||
#include "LinearMath/btVector3.h"
|
#include "LinearMath/btVector3.h"
|
||||||
#include "LinearMath/btTransform.h"
|
#include "LinearMath/btTransform.h"
|
||||||
#include "LinearMath/btMatrix3x3.h"
|
#include "LinearMath/btMatrix3x3.h"
|
||||||
|
#include "LinearMath/btAabbUtil2.h"
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
extern int gOverlappingPairs;
|
extern int gOverlappingPairs;
|
||||||
@@ -166,6 +168,23 @@ void btSimpleBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void btSimpleBroadphase::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback)
|
||||||
|
{
|
||||||
|
for (int i=0; i <= m_LastHandleIndex; i++)
|
||||||
|
{
|
||||||
|
btSimpleBroadphaseProxy* proxy = &m_pHandles[i];
|
||||||
|
if(!proxy->m_clientObject)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (TestAabbAgainstAabb2(aabbMin,aabbMax,proxy->m_aabbMin,proxy->m_aabbMax))
|
||||||
|
{
|
||||||
|
callback.process(proxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ public:
|
|||||||
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
|
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
|
||||||
|
|
||||||
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0),const btVector3& aabbMax=btVector3(0,0,0));
|
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0),const btVector3& aabbMax=btVector3(0,0,0));
|
||||||
|
virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
|
||||||
|
|
||||||
btOverlappingPairCache* getOverlappingPairCache()
|
btOverlappingPairCache* getOverlappingPairCache()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -965,7 +965,7 @@ struct btBridgedManifoldResult : public btManifoldResult
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct btSingleContactCallback : public btBroadphaseRayCallback
|
struct btSingleContactCallback : public btBroadphaseAabbCallback
|
||||||
{
|
{
|
||||||
|
|
||||||
btCollisionObject* m_collisionObject;
|
btCollisionObject* m_collisionObject;
|
||||||
@@ -1012,8 +1012,8 @@ void btCollisionWorld::contactTest( btCollisionObject* colObj, ContactResultCall
|
|||||||
btVector3 aabbMin,aabbMax;
|
btVector3 aabbMin,aabbMax;
|
||||||
colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(),aabbMin,aabbMax);
|
colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(),aabbMin,aabbMax);
|
||||||
btSingleContactCallback contactCB(colObj,this,resultCallback);
|
btSingleContactCallback contactCB(colObj,this,resultCallback);
|
||||||
|
|
||||||
m_broadphasePairCache->rayTest(colObj->getWorldTransform().getOrigin(),colObj->getWorldTransform().getOrigin(),contactCB,aabbMin,aabbMax);
|
m_broadphasePairCache->aabbTest(aabbMin,aabbMax,contactCB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user