update to latest Bullet 2.x sources. prepare to make near sensors much faster
This commit is contained in:
@@ -70,7 +70,8 @@ struct btBroadphaseProxy
|
||||
StaticFilter = 2,
|
||||
KinematicFilter = 4,
|
||||
DebrisFilter = 8,
|
||||
AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter,
|
||||
SensorTrigger = 16,
|
||||
AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger,
|
||||
};
|
||||
|
||||
//Usually the client btCollisionObject or Rigidbody class
|
||||
@@ -118,8 +119,7 @@ class btCollisionAlgorithm;
|
||||
|
||||
struct btBroadphaseProxy;
|
||||
|
||||
//Increase SIMPLE_MAX_ALGORITHMS to allow multiple btDispatchers caching their own algorithms
|
||||
#define SIMPLE_MAX_ALGORITHMS 1
|
||||
|
||||
|
||||
/// contains a pair of aabb-overlapping objects
|
||||
struct btBroadphasePair
|
||||
@@ -127,22 +127,16 @@ struct btBroadphasePair
|
||||
btBroadphasePair ()
|
||||
:
|
||||
m_pProxy0(0),
|
||||
m_pProxy1(0)
|
||||
m_pProxy1(0),
|
||||
m_algorithm(0)
|
||||
{
|
||||
for (int i=0;i<SIMPLE_MAX_ALGORITHMS;i++)
|
||||
{
|
||||
m_algorithms[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
btBroadphasePair(const btBroadphasePair& other)
|
||||
: m_pProxy0(other.m_pProxy0),
|
||||
m_pProxy1(other.m_pProxy1)
|
||||
m_pProxy1(other.m_pProxy1),
|
||||
m_algorithm(other.m_algorithm)
|
||||
{
|
||||
for (int i=0;i<SIMPLE_MAX_ALGORITHMS;i++)
|
||||
{
|
||||
m_algorithms[i] = other.m_algorithms[i];
|
||||
}
|
||||
}
|
||||
btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1)
|
||||
{
|
||||
@@ -159,17 +153,14 @@ struct btBroadphasePair
|
||||
m_pProxy1 = &proxy0;
|
||||
}
|
||||
|
||||
for (int i=0;i<SIMPLE_MAX_ALGORITHMS;i++)
|
||||
{
|
||||
m_algorithms[i] = 0;
|
||||
}
|
||||
m_algorithm = 0;
|
||||
|
||||
}
|
||||
|
||||
btBroadphaseProxy* m_pProxy0;
|
||||
btBroadphaseProxy* m_pProxy1;
|
||||
|
||||
mutable btCollisionAlgorithm* m_algorithms[SIMPLE_MAX_ALGORITHMS];
|
||||
mutable btCollisionAlgorithm* m_algorithm;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -22,11 +22,6 @@ class btRigidBody;
|
||||
class btCollisionObject;
|
||||
class btOverlappingPairCache;
|
||||
|
||||
enum btCollisionDispatcherId
|
||||
{
|
||||
RIGIDBODY_DISPATCHER = 0,
|
||||
USERCALLBACK_DISPATCHER
|
||||
};
|
||||
|
||||
class btPersistentManifold;
|
||||
class btStackAlloc;
|
||||
@@ -74,11 +69,6 @@ public:
|
||||
|
||||
virtual btCollisionAlgorithm* findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold=0) = 0;
|
||||
|
||||
//
|
||||
// asume dispatchers to have unique id's in the range [0..max dispacher]
|
||||
//
|
||||
virtual int getUniqueId() = 0;
|
||||
|
||||
virtual btPersistentManifold* getNewManifold(void* body0,void* body1)=0;
|
||||
|
||||
virtual void releaseManifold(btPersistentManifold* manifold)=0;
|
||||
|
||||
@@ -54,14 +54,11 @@ void btOverlappingPairCache::removeOverlappingPair(btBroadphasePair& findPair)
|
||||
|
||||
void btOverlappingPairCache::cleanOverlappingPair(btBroadphasePair& pair)
|
||||
{
|
||||
for (int dispatcherId=0;dispatcherId<SIMPLE_MAX_ALGORITHMS;dispatcherId++)
|
||||
if (pair.m_algorithm)
|
||||
{
|
||||
if (pair.m_algorithms[dispatcherId])
|
||||
{
|
||||
{
|
||||
delete pair.m_algorithms[dispatcherId];
|
||||
pair.m_algorithms[dispatcherId]=0;
|
||||
}
|
||||
delete pair.m_algorithm;;
|
||||
pair.m_algorithm=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ m_emptyCreateFunc(0)
|
||||
{
|
||||
int i;
|
||||
|
||||
setNearCallback(defaultNearCallback);
|
||||
|
||||
m_emptyCreateFunc = new btEmptyAlgorithm::CreateFunc;
|
||||
for (i=0;i<MAX_BROADPHASE_COLLISION_TYPES;i++)
|
||||
{
|
||||
@@ -61,6 +63,8 @@ btCollisionDispatcher::btCollisionDispatcher ():
|
||||
m_count(0)
|
||||
{
|
||||
int i;
|
||||
|
||||
setNearCallback(defaultNearCallback);
|
||||
|
||||
//default CreationFunctions, filling the m_doubleDispatch table
|
||||
m_convexConvexCreateFunc = new btConvexConvexAlgorithm::CreateFunc;
|
||||
@@ -275,50 +279,20 @@ class btCollisionPairCallback : public btOverlapCallback
|
||||
{
|
||||
btDispatcherInfo& m_dispatchInfo;
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
int m_dispatcherId;
|
||||
|
||||
public:
|
||||
|
||||
btCollisionPairCallback(btDispatcherInfo& dispatchInfo,btCollisionDispatcher* dispatcher,int dispatcherId)
|
||||
btCollisionPairCallback(btDispatcherInfo& dispatchInfo,btCollisionDispatcher* dispatcher)
|
||||
:m_dispatchInfo(dispatchInfo),
|
||||
m_dispatcher(dispatcher),
|
||||
m_dispatcherId(dispatcherId)
|
||||
m_dispatcher(dispatcher)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool processOverlap(btBroadphasePair& pair)
|
||||
{
|
||||
btCollisionObject* body0 = (btCollisionObject*)pair.m_pProxy0->m_clientObject;
|
||||
btCollisionObject* body1 = (btCollisionObject*)pair.m_pProxy1->m_clientObject;
|
||||
(*m_dispatcher->getNearCallback())(pair,*m_dispatcher,m_dispatchInfo);
|
||||
|
||||
if (!m_dispatcher->needsCollision(body0,body1))
|
||||
return false;
|
||||
|
||||
//dispatcher will keep algorithms persistent in the collision pair
|
||||
if (!pair.m_algorithms[m_dispatcherId])
|
||||
{
|
||||
pair.m_algorithms[m_dispatcherId] = m_dispatcher->findAlgorithm(
|
||||
body0,
|
||||
body1);
|
||||
}
|
||||
|
||||
if (pair.m_algorithms[m_dispatcherId])
|
||||
{
|
||||
btManifoldResult* resultOut = m_dispatcher->internalGetNewManifoldResult(body0,body1);
|
||||
if (m_dispatchInfo.m_dispatchFunc == btDispatcherInfo::DISPATCH_DISCRETE)
|
||||
{
|
||||
|
||||
pair.m_algorithms[m_dispatcherId]->processCollision(body0,body1,m_dispatchInfo,resultOut);
|
||||
} else
|
||||
{
|
||||
float toi = pair.m_algorithms[m_dispatcherId]->calculateTimeOfImpact(body0,body1,m_dispatchInfo,resultOut);
|
||||
if (m_dispatchInfo.m_timeOfImpact > toi)
|
||||
m_dispatchInfo.m_timeOfImpact = toi;
|
||||
|
||||
}
|
||||
m_dispatcher->internalReleaseManifoldResult(resultOut);
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -327,9 +301,7 @@ void btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pa
|
||||
{
|
||||
//m_blockedForChanges = true;
|
||||
|
||||
int dispatcherId = getUniqueId();
|
||||
|
||||
btCollisionPairCallback collisionCallback(dispatchInfo,this,dispatcherId);
|
||||
btCollisionPairCallback collisionCallback(dispatchInfo,this);
|
||||
|
||||
pairCache->processAllOverlappingPairs(&collisionCallback);
|
||||
|
||||
@@ -338,3 +310,39 @@ void btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pa
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//by default, Bullet will use this near callback
|
||||
void btCollisionDispatcher::defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, btDispatcherInfo& dispatchInfo)
|
||||
{
|
||||
btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
|
||||
btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
|
||||
|
||||
if (dispatcher.needsCollision(colObj0,colObj1))
|
||||
{
|
||||
//dispatcher will keep algorithms persistent in the collision pair
|
||||
if (!collisionPair.m_algorithm)
|
||||
{
|
||||
collisionPair.m_algorithm = dispatcher.findAlgorithm(colObj0,colObj1);
|
||||
}
|
||||
|
||||
if (collisionPair.m_algorithm)
|
||||
{
|
||||
btManifoldResult contactPointResult(colObj0,colObj1);
|
||||
|
||||
if (dispatchInfo.m_dispatchFunc == btDispatcherInfo::DISPATCH_DISCRETE)
|
||||
{
|
||||
//discrete collision detection query
|
||||
collisionPair.m_algorithm->processCollision(colObj0,colObj1,dispatchInfo,&contactPointResult);
|
||||
} else
|
||||
{
|
||||
//continuous collision detection query, time of impact (toi)
|
||||
float toi = collisionPair.m_algorithm->calculateTimeOfImpact(colObj0,colObj1,dispatchInfo,&contactPointResult);
|
||||
if (dispatchInfo.m_timeOfImpact > toi)
|
||||
dispatchInfo.m_timeOfImpact = toi;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,6 +32,10 @@ class btOverlappingPairCache;
|
||||
|
||||
#define USE_DISPATCH_REGISTRY_ARRAY 1
|
||||
|
||||
class btCollisionDispatcher;
|
||||
///user can override this nearcallback for collision filtering and more finegrained control over collision detection
|
||||
typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, btDispatcherInfo& dispatchInfo);
|
||||
|
||||
|
||||
///btCollisionDispatcher supports algorithms that handle ConvexConvex and ConvexConcave collision pairs.
|
||||
///Time of Impact, Closest Points and Penetration Depth.
|
||||
@@ -43,6 +47,8 @@ class btCollisionDispatcher : public btDispatcher
|
||||
bool m_useIslands;
|
||||
|
||||
btManifoldResult m_defaultManifoldResult;
|
||||
|
||||
btNearCallback m_nearCallback;
|
||||
|
||||
btCollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
|
||||
|
||||
@@ -62,19 +68,7 @@ class btCollisionDispatcher : public btDispatcher
|
||||
|
||||
public:
|
||||
|
||||
///allows the user to get contact point callbacks
|
||||
inline btManifoldResult* internalGetNewManifoldResult(btCollisionObject* obj0,btCollisionObject* obj1)
|
||||
{
|
||||
//in-place, this prevents parallel dispatching, but just adding a list would fix that.
|
||||
btManifoldResult* manifoldResult = new (&m_defaultManifoldResult) btManifoldResult(obj0,obj1);
|
||||
return manifoldResult;
|
||||
}
|
||||
|
||||
///allows the user to get contact point callbacks
|
||||
inline void internalReleaseManifoldResult(btManifoldResult*)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///registerCollisionCreateFunc allows registration of custom/alternative collision create functions
|
||||
void registerCollisionCreateFunc(int proxyType0,int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);
|
||||
|
||||
@@ -121,12 +115,21 @@ public:
|
||||
virtual bool needsCollision(btCollisionObject* body0,btCollisionObject* body1);
|
||||
|
||||
virtual bool needsResponse(btCollisionObject* body0,btCollisionObject* body1);
|
||||
|
||||
virtual int getUniqueId() { return RIGIDBODY_DISPATCHER;}
|
||||
|
||||
virtual void dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,btDispatcherInfo& dispatchInfo);
|
||||
|
||||
|
||||
void setNearCallback(btNearCallback nearCallback)
|
||||
{
|
||||
m_nearCallback = nearCallback;
|
||||
}
|
||||
|
||||
btNearCallback getNearCallback() const
|
||||
{
|
||||
return m_nearCallback;
|
||||
}
|
||||
|
||||
//by default, Bullet will use this near callback
|
||||
static void defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, btDispatcherInfo& dispatchInfo);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -336,7 +336,12 @@ public:
|
||||
{
|
||||
return m_angularFactor;
|
||||
}
|
||||
|
||||
|
||||
//is this rigidbody added to a btCollisionWorld/btDynamicsWorld/btBroadphase?
|
||||
bool isInWorld() const
|
||||
{
|
||||
return (getBroadphaseProxy() != 0);
|
||||
}
|
||||
|
||||
int m_debugBodyId;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user