Back to index

supertuxkart  0.5+dfsg1
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
btMultiSapBroadphase Class Reference

multi SAP broadphase See http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=328 and http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1329 More...

#include <btMultiSapBroadphase.h>

Inheritance diagram for btMultiSapBroadphase:
Inheritance graph
[legend]
Collaboration diagram for btMultiSapBroadphase:
Collaboration graph
[legend]

List of all members.

Classes

struct  btBridgeProxy
struct  btMultiSapProxy

Public Member Functions

 btMultiSapBroadphase (int maxProxies=16384, btOverlappingPairCache *pairCache=0)
btSapBroadphaseArraygetBroadphaseArray ()
const btSapBroadphaseArraygetBroadphaseArray () const
virtual ~btMultiSapBroadphase ()
virtual btBroadphaseProxy * createProxy (const btVector3 &aabbMin, const btVector3 &aabbMax, int shapeType, void *userPtr, short int collisionFilterGroup, short int collisionFilterMask, btDispatcher *dispatcher, void *multiSapProxy)
virtual void destroyProxy (btBroadphaseProxy *proxy, btDispatcher *dispatcher)
virtual void setAabb (btBroadphaseProxy *proxy, const btVector3 &aabbMin, const btVector3 &aabbMax, btDispatcher *dispatcher)
virtual void calculateOverlappingPairs (btDispatcher *dispatcher)
 calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
bool testAabbOverlap (btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1)
virtual btOverlappingPairCachegetOverlappingPairCache ()
virtual const
btOverlappingPairCache
getOverlappingPairCache () const
virtual void getBroadphaseAabb (btVector3 &aabbMin, btVector3 &aabbMax) const
 getAabb returns the axis aligned bounding box in the 'global' coordinate frame will add some transform later
void buildTree (const btVector3 &bvhAabbMin, const btVector3 &bvhAabbMax)
virtual void printStats ()
void quicksort (btBroadphasePairArray &a, int lo, int hi)

Protected Member Functions

void addToChildBroadphase (btMultiSapProxy *parentMultiSapProxy, btBroadphaseProxy *childProxy, btBroadphaseInterface *childBroadphase)

Protected Attributes

btAlignedObjectArray
< btMultiSapProxy * > 
m_multiSapProxies

Private Attributes

btSapBroadphaseArray m_sapBroadphases
btSimpleBroadphasem_simpleBroadphase
btOverlappingPairCachem_overlappingPairs
class btOptimizedBvh * m_optimizedAabbTree
bool m_ownsPairCache
btOverlapFilterCallbackm_filterCallback
int m_invalidPair

Detailed Description

multi SAP broadphase See http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=328 and http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1329

Definition at line 32 of file btMultiSapBroadphase.h.


Class Documentation

struct btMultiSapBroadphase::btBridgeProxy

Definition at line 49 of file btMultiSapBroadphase.h.

Collaboration diagram for btMultiSapBroadphase::btBridgeProxy:
Class Members
btBroadphaseInterface * m_childBroadphase
btBroadphaseProxy * m_childProxy

Constructor & Destructor Documentation

btMultiSapBroadphase::btMultiSapBroadphase ( int  maxProxies = 16384,
btOverlappingPairCache pairCache = 0 
)

Definition at line 40 of file btMultiSapBroadphase.cpp.

:m_overlappingPairs(pairCache),
m_ownsPairCache(false),
m_invalidPair(0),
m_optimizedAabbTree(0)
{
       if (!m_overlappingPairs)
       {
              m_ownsPairCache = true;
              void* mem = btAlignedAlloc(sizeof(btSortedOverlappingPairCache),16);
              m_overlappingPairs = new (mem)btSortedOverlappingPairCache();
       }

       struct btMultiSapOverlapFilterCallback : public btOverlapFilterCallback
       {
              virtual ~btMultiSapOverlapFilterCallback()
              {}
              // return true when pairs need collision
              virtual bool  needBroadphaseCollision(btBroadphaseProxy* childProxy0,btBroadphaseProxy* childProxy1) const
              {
                     btBroadphaseProxy* multiProxy0 = (btBroadphaseProxy*)childProxy0->m_multiSapParentProxy;
                     btBroadphaseProxy* multiProxy1 = (btBroadphaseProxy*)childProxy1->m_multiSapParentProxy;
                     
                     bool collides = (multiProxy0->m_collisionFilterGroup & multiProxy1->m_collisionFilterMask) != 0;
                     collides = collides && (multiProxy1->m_collisionFilterGroup & multiProxy0->m_collisionFilterMask);
       
                     return collides;
              }
       };

       void* mem = btAlignedAlloc(sizeof(btMultiSapOverlapFilterCallback),16);
       m_filterCallback = new (mem)btMultiSapOverlapFilterCallback();

       m_overlappingPairs->setOverlapFilterCallback(m_filterCallback);
//     mem = btAlignedAlloc(sizeof(btSimpleBroadphase),16);
//     m_simpleBroadphase = new (mem) btSimpleBroadphase(maxProxies,m_overlappingPairs);
}

Here is the call graph for this function:

Definition at line 78 of file btMultiSapBroadphase.cpp.

{
       if (m_ownsPairCache)
       {
              m_overlappingPairs->~btOverlappingPairCache();
              btAlignedFree(m_overlappingPairs);
       }
}

Member Function Documentation

void btMultiSapBroadphase::addToChildBroadphase ( btMultiSapProxy parentMultiSapProxy,
btBroadphaseProxy *  childProxy,
btBroadphaseInterface childBroadphase 
) [protected]

Definition at line 128 of file btMultiSapBroadphase.cpp.

{
       void* mem = btAlignedAlloc(sizeof(btBridgeProxy),16);
       btBridgeProxy* bridgeProxyRef = new(mem) btBridgeProxy();
       bridgeProxyRef->m_childProxy = childProxy;
       bridgeProxyRef->m_childBroadphase = childBroadphase;
       parentMultiSapProxy->m_bridgeProxies.push_back(bridgeProxyRef);
}

Here is the call graph for this function:

void btMultiSapBroadphase::buildTree ( const btVector3 bvhAabbMin,
const btVector3 bvhAabbMax 
)

Definition at line 88 of file btMultiSapBroadphase.cpp.

{
       m_optimizedAabbTree = new btOptimizedBvh();
       m_optimizedAabbTree->setQuantizationValues(bvhAabbMin,bvhAabbMax);
       QuantizedNodeArray&  nodes = m_optimizedAabbTree->getLeafNodeArray();
       for (int i=0;i<m_sapBroadphases.size();i++)
       {
              btQuantizedBvhNode node;
              btVector3 aabbMin,aabbMax;
              m_sapBroadphases[i]->getBroadphaseAabb(aabbMin,aabbMax);
              m_optimizedAabbTree->quantize(&node.m_quantizedAabbMin[0],aabbMin,0);
              m_optimizedAabbTree->quantize(&node.m_quantizedAabbMax[0],aabbMax,1);
              int partId = 0;
              node.m_escapeIndexOrTriangleIndex = (partId<<(31-MAX_NUM_PARTS_IN_BITS)) | i;
              nodes.push_back(node);
       }
       m_optimizedAabbTree->buildInternal();
}

Here is the call graph for this function:

calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb

if you don't like to skip the invalid pairs in the array, execute following code:

Implements btBroadphaseInterface.

Definition at line 339 of file btMultiSapBroadphase.cpp.

{

//     m_simpleBroadphase->calculateOverlappingPairs(dispatcher);

       if (!stopUpdating && getOverlappingPairCache()->hasDeferredRemoval())
       {
       
              btBroadphasePairArray&      overlappingPairArray = getOverlappingPairCache()->getOverlappingPairArray();

       //     quicksort(overlappingPairArray,0,overlappingPairArray.size());

              overlappingPairArray.quickSort(btMultiSapBroadphasePairSortPredicate());

              //perform a sort, to find duplicates and to sort 'invalid' pairs to the end
       //     overlappingPairArray.heapSort(btMultiSapBroadphasePairSortPredicate());

              overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair);
              m_invalidPair = 0;

              
              int i;

              btBroadphasePair previousPair;
              previousPair.m_pProxy0 = 0;
              previousPair.m_pProxy1 = 0;
              previousPair.m_algorithm = 0;
              
              
              for (i=0;i<overlappingPairArray.size();i++)
              {
              
                     btBroadphasePair& pair = overlappingPairArray[i];

                     btMultiSapProxy* aProxy0 = pair.m_pProxy0 ? (btMultiSapProxy*)pair.m_pProxy0->m_multiSapParentProxy : 0;
                     btMultiSapProxy* aProxy1 = pair.m_pProxy1 ? (btMultiSapProxy*)pair.m_pProxy1->m_multiSapParentProxy : 0;
                     btMultiSapProxy* bProxy0 = previousPair.m_pProxy0 ? (btMultiSapProxy*)previousPair.m_pProxy0->m_multiSapParentProxy : 0;
                     btMultiSapProxy* bProxy1 = previousPair.m_pProxy1 ? (btMultiSapProxy*)previousPair.m_pProxy1->m_multiSapParentProxy : 0;

                     bool isDuplicate = (aProxy0 == bProxy0) && (aProxy1 == bProxy1);
                     
                     previousPair = pair;

                     bool needsRemoval = false;

                     if (!isDuplicate)
                     {
                            bool hasOverlap = testAabbOverlap(pair.m_pProxy0,pair.m_pProxy1);

                            if (hasOverlap)
                            {
                                   needsRemoval = false;//callback->processOverlap(pair);
                            } else
                            {
                                   needsRemoval = true;
                            }
                     } else
                     {
                            //remove duplicate
                            needsRemoval = true;
                            //should have no algorithm
                            btAssert(!pair.m_algorithm);
                     }
                     
                     if (needsRemoval)
                     {
                            getOverlappingPairCache()->cleanOverlappingPair(pair,dispatcher);

              //            m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1);
              //            m_overlappingPairArray.pop_back();
                            pair.m_pProxy0 = 0;
                            pair.m_pProxy1 = 0;
                            m_invalidPair++;
                            gOverlappingPairs--;
                     } 
                     
              }

       #define CLEAN_INVALID_PAIRS 1
       #ifdef CLEAN_INVALID_PAIRS

              //perform a sort, to sort 'invalid' pairs to the end
              //overlappingPairArray.heapSort(btMultiSapBroadphasePairSortPredicate());
              overlappingPairArray.quickSort(btMultiSapBroadphasePairSortPredicate());

              overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair);
              m_invalidPair = 0;
       #endif//CLEAN_INVALID_PAIRS
              
              //printf("overlappingPairArray.size()=%d\n",overlappingPairArray.size());
       }


}

Here is the call graph for this function:

btBroadphaseProxy * btMultiSapBroadphase::createProxy ( const btVector3 aabbMin,
const btVector3 aabbMax,
int  shapeType,
void *  userPtr,
short int  collisionFilterGroup,
short int  collisionFilterMask,
btDispatcher dispatcher,
void *  multiSapProxy 
) [virtual]

this should deal with inserting/removal into child broadphases

Implements btBroadphaseInterface.

Definition at line 107 of file btMultiSapBroadphase.cpp.

{
       //void* ignoreMe -> we could think of recursive multi-sap, if someone is interested

       void* mem = btAlignedAlloc(sizeof(btMultiSapProxy),16);
       btMultiSapProxy* proxy = new (mem)btMultiSapProxy(aabbMin,  aabbMax,shapeType,userPtr, collisionFilterGroup,collisionFilterMask);
       m_multiSapProxies.push_back(proxy);

       setAabb(proxy,aabbMin,aabbMax,dispatcher);
       return proxy;
}

Here is the call graph for this function:

void btMultiSapBroadphase::destroyProxy ( btBroadphaseProxy *  proxy,
btDispatcher dispatcher 
) [virtual]

not yet

Implements btBroadphaseInterface.

Definition at line 120 of file btMultiSapBroadphase.cpp.

{
       btAssert(0);

}
virtual void btMultiSapBroadphase::getBroadphaseAabb ( btVector3 aabbMin,
btVector3 aabbMax 
) const [inline, virtual]

getAabb returns the axis aligned bounding box in the 'global' coordinate frame will add some transform later

Implements btBroadphaseInterface.

Definition at line 127 of file btMultiSapBroadphase.h.

       {
              aabbMin.setValue(-1e30f,-1e30f,-1e30f);
              aabbMax.setValue(1e30f,1e30f,1e30f);
       }

Here is the call graph for this function:

Definition at line 95 of file btMultiSapBroadphase.h.

       {
              return m_sapBroadphases;
       }

Definition at line 100 of file btMultiSapBroadphase.h.

       {
              return m_sapBroadphases;
       }

Implements btBroadphaseInterface.

Definition at line 116 of file btMultiSapBroadphase.h.

       {
              return m_overlappingPairs;
       }

Here is the caller graph for this function:

virtual const btOverlappingPairCache* btMultiSapBroadphase::getOverlappingPairCache ( ) const [inline, virtual]

Implements btBroadphaseInterface.

Definition at line 120 of file btMultiSapBroadphase.h.

       {
              return m_overlappingPairs;
       }

Implements btBroadphaseInterface.

Definition at line 447 of file btMultiSapBroadphase.cpp.

{
/*     printf("---------------------------------\n");
       
              printf("btMultiSapBroadphase.h\n");
              printf("numHandles = %d\n",m_multiSapProxies.size());
                     //find broadphase that contain this multiProxy
              int numChildBroadphases = getBroadphaseArray().size();
              for (int i=0;i<numChildBroadphases;i++)
              {

                     btBroadphaseInterface* childBroadphase = getBroadphaseArray()[i];
                     childBroadphase->printStats();

              }
              */

}
void btMultiSapBroadphase::quicksort ( btBroadphasePairArray a,
int  lo,
int  hi 
)
void btMultiSapBroadphase::setAabb ( btBroadphaseProxy *  proxy,
const btVector3 aabbMin,
const btVector3 aabbMax,
btDispatcher dispatcher 
) [virtual]

Implements btBroadphaseInterface.

Definition at line 153 of file btMultiSapBroadphase.cpp.

{
       btMultiSapProxy* multiProxy = static_cast<btMultiSapProxy*>(proxy);
       multiProxy->m_aabbMin = aabbMin;
       multiProxy->m_aabbMax = aabbMax;
       
       
       bool fullyContained = false;
       bool alreadyInSimple = false;
       


       
       struct MyNodeOverlapCallback : public btNodeOverlapCallback
       {
              btMultiSapBroadphase*       m_multiSap;
              btMultiSapProxy*            m_multiProxy;
              btDispatcher*               m_dispatcher;

              MyNodeOverlapCallback(btMultiSapBroadphase* multiSap,btMultiSapProxy* multiProxy,btDispatcher* dispatcher)
                     :m_multiSap(multiSap),
                     m_multiProxy(multiProxy),
                     m_dispatcher(dispatcher)
              {

              }

              virtual void processNode(int nodeSubPart, int broadphaseIndex)
              {
                     btBroadphaseInterface* childBroadphase = m_multiSap->getBroadphaseArray()[broadphaseIndex];

                     int containingBroadphaseIndex = -1;
                     //already found?
                     for (int i=0;i<m_multiProxy->m_bridgeProxies.size();i++)
                     {

                            if (m_multiProxy->m_bridgeProxies[i]->m_childBroadphase == childBroadphase)
                            {
                                   containingBroadphaseIndex = i;
                                   break;
                            }
                     }
                     if (containingBroadphaseIndex<0)
                     {
                            //add it
                            btBroadphaseProxy* childProxy = childBroadphase->createProxy(m_multiProxy->m_aabbMin,m_multiProxy->m_aabbMax,m_multiProxy->m_shapeType,m_multiProxy->m_clientObject,m_multiProxy->m_collisionFilterGroup,m_multiProxy->m_collisionFilterMask, m_dispatcher,m_multiProxy);
                            m_multiSap->addToChildBroadphase(m_multiProxy,childProxy,childBroadphase);

                     }
              }
       };

       MyNodeOverlapCallback       myNodeCallback(this,multiProxy,dispatcher);



       
       m_optimizedAabbTree->reportAabbOverlappingNodex(&myNodeCallback,aabbMin,aabbMax);

              for (int i=0;i<multiProxy->m_bridgeProxies.size();i++)
       {
              btVector3 worldAabbMin,worldAabbMax;
              multiProxy->m_bridgeProxies[i]->m_childBroadphase->getBroadphaseAabb(worldAabbMin,worldAabbMax);
              bool overlapsBroadphase = TestAabbAgainstAabb2(worldAabbMin,worldAabbMax,multiProxy->m_aabbMin,multiProxy->m_aabbMax);
              if (!overlapsBroadphase)
              {
                     //remove it now
                     btBridgeProxy* bridgeProxy = multiProxy->m_bridgeProxies[i];

                     btBroadphaseProxy* childProxy = bridgeProxy->m_childProxy;
                     bridgeProxy->m_childBroadphase->destroyProxy(childProxy,dispatcher);
                     
                     multiProxy->m_bridgeProxies.swap( i,multiProxy->m_bridgeProxies.size()-1);
                     multiProxy->m_bridgeProxies.pop_back();

              }
       }


       /*

       if (1)
       {

              //find broadphase that contain this multiProxy
              int numChildBroadphases = getBroadphaseArray().size();
              for (int i=0;i<numChildBroadphases;i++)
              {
                     btBroadphaseInterface* childBroadphase = getBroadphaseArray()[i];
                     btVector3 worldAabbMin,worldAabbMax;
                     childBroadphase->getBroadphaseAabb(worldAabbMin,worldAabbMax);
                     bool overlapsBroadphase = TestAabbAgainstAabb2(worldAabbMin,worldAabbMax,multiProxy->m_aabbMin,multiProxy->m_aabbMax);
                     
              //     fullyContained = fullyContained || boxIsContainedWithinBox(worldAabbMin,worldAabbMax,multiProxy->m_aabbMin,multiProxy->m_aabbMax);
                     int containingBroadphaseIndex = -1;
                     
                     //if already contains this
                     
                     for (int i=0;i<multiProxy->m_bridgeProxies.size();i++)
                     {
                            if (multiProxy->m_bridgeProxies[i]->m_childBroadphase == childBroadphase)
                            {
                                   containingBroadphaseIndex = i;
                            }
                            alreadyInSimple = alreadyInSimple || (multiProxy->m_bridgeProxies[i]->m_childBroadphase == m_simpleBroadphase);
                     }

                     if (overlapsBroadphase)
                     {
                            if (containingBroadphaseIndex<0)
                            {
                                   btBroadphaseProxy* childProxy = childBroadphase->createProxy(aabbMin,aabbMax,multiProxy->m_shapeType,multiProxy->m_clientObject,multiProxy->m_collisionFilterGroup,multiProxy->m_collisionFilterMask, dispatcher);
                                   childProxy->m_multiSapParentProxy = multiProxy;
                                   addToChildBroadphase(multiProxy,childProxy,childBroadphase);
                            }
                     } else
                     {
                            if (containingBroadphaseIndex>=0)
                            {
                                   //remove
                                   btBridgeProxy* bridgeProxy = multiProxy->m_bridgeProxies[containingBroadphaseIndex];

                                   btBroadphaseProxy* childProxy = bridgeProxy->m_childProxy;
                                   bridgeProxy->m_childBroadphase->destroyProxy(childProxy,dispatcher);
                                   
                                   multiProxy->m_bridgeProxies.swap( containingBroadphaseIndex,multiProxy->m_bridgeProxies.size()-1);
                                   multiProxy->m_bridgeProxies.pop_back();
                            }
                     }
              }


              if (0)//!multiProxy->m_bridgeProxies.size())
              {
                     btBroadphaseProxy* childProxy = m_simpleBroadphase->createProxy(aabbMin,aabbMax,multiProxy->m_shapeType,multiProxy->m_clientObject,multiProxy->m_collisionFilterGroup,multiProxy->m_collisionFilterMask, dispatcher);
                     childProxy->m_multiSapParentProxy = multiProxy;
                     addToChildBroadphase(multiProxy,childProxy,m_simpleBroadphase);
              }
       }

       if (!multiProxy->m_bridgeProxies.size())
       {
              btBroadphaseProxy* childProxy = m_simpleBroadphase->createProxy(aabbMin,aabbMax,multiProxy->m_shapeType,multiProxy->m_clientObject,multiProxy->m_collisionFilterGroup,multiProxy->m_collisionFilterMask, dispatcher);
              childProxy->m_multiSapParentProxy = multiProxy;
              addToChildBroadphase(multiProxy,childProxy,m_simpleBroadphase);
       }
*/


       //update
       for (int i=0;i<multiProxy->m_bridgeProxies.size();i++)
       {
              btBridgeProxy* bridgeProxyRef = multiProxy->m_bridgeProxies[i];
              bridgeProxyRef->m_childBroadphase->setAabb(bridgeProxyRef->m_childProxy,aabbMin,aabbMax,dispatcher);
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

bool btMultiSapBroadphase::testAabbOverlap ( btBroadphaseProxy *  proxy0,
btBroadphaseProxy *  proxy1 
)

Definition at line 436 of file btMultiSapBroadphase.cpp.

{
       btMultiSapProxy* multiSapProxy0 = (btMultiSapProxy*)childProxy0->m_multiSapParentProxy;
              btMultiSapProxy* multiSapProxy1 = (btMultiSapProxy*)childProxy1->m_multiSapParentProxy;

              return TestAabbAgainstAabb2(multiSapProxy0->m_aabbMin,multiSapProxy0->m_aabbMax,
                     multiSapProxy1->m_aabbMin,multiSapProxy1->m_aabbMax);
              
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 45 of file btMultiSapBroadphase.h.

Definition at line 47 of file btMultiSapBroadphase.h.

Definition at line 88 of file btMultiSapBroadphase.h.

class btOptimizedBvh* btMultiSapBroadphase::m_optimizedAabbTree [private]

Definition at line 40 of file btMultiSapBroadphase.h.

Definition at line 38 of file btMultiSapBroadphase.h.

Definition at line 43 of file btMultiSapBroadphase.h.

Definition at line 34 of file btMultiSapBroadphase.h.

Definition at line 36 of file btMultiSapBroadphase.h.


The documentation for this class was generated from the following files: