Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
btSimpleBroadphase Class Reference

SimpleBroadphase is a brute force aabb culling broadphase based on O(n^2) aabb checks btSimpleBroadphase is just a unit-test implementation to verify and test other broadphases. So please don't use this class, but use bt32BitAxisSweep3 or btAxisSweep3 instead! More...

#include <btSimpleBroadphase.h>

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

List of all members.

Public Member Functions

 btSimpleBroadphase (int maxProxies=16384, btOverlappingPairCache *overlappingPairCache=0)
virtual ~btSimpleBroadphase ()
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 calculateOverlappingPairs (btDispatcher *dispatcher)
 calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
virtual void destroyProxy (btBroadphaseProxy *proxy, btDispatcher *dispatcher)
virtual void setAabb (btBroadphaseProxy *proxy, const btVector3 &aabbMin, const btVector3 &aabbMax, btDispatcher *dispatcher)
btOverlappingPairCachegetOverlappingPairCache ()
const btOverlappingPairCachegetOverlappingPairCache () const
bool testAabbOverlap (btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1)
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
virtual void printStats ()

Static Public Member Functions

static bool aabbOverlap (btSimpleBroadphaseProxy *proxy0, btSimpleBroadphaseProxy *proxy1)

Protected Member Functions

int allocHandle ()
void freeHandle (btSimpleBroadphaseProxy *proxy)
btSimpleBroadphaseProxygetSimpleProxyFromProxy (btBroadphaseProxy *proxy)
void validate ()

Protected Attributes

int m_numHandles
int m_maxHandles
btSimpleBroadphaseProxym_pHandles
int m_firstFreeHandle
int m_firstAllocatedHandle
btOverlappingPairCachem_pairCache
bool m_ownsPairCache
int m_invalidPair

Detailed Description

SimpleBroadphase is a brute force aabb culling broadphase based on O(n^2) aabb checks btSimpleBroadphase is just a unit-test implementation to verify and test other broadphases. So please don't use this class, but use bt32BitAxisSweep3 or btAxisSweep3 instead!

Definition at line 54 of file btSimpleBroadphase.h.


Constructor & Destructor Documentation

btSimpleBroadphase::btSimpleBroadphase ( int  maxProxies = 16384,
btOverlappingPairCache overlappingPairCache = 0 
)

Definition at line 39 of file btSimpleBroadphase.cpp.

       :m_pairCache(overlappingPairCache),
       m_ownsPairCache(false),
       m_invalidPair(0)
{

       if (!overlappingPairCache)
       {
              void* mem = btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16);
              m_pairCache = new (mem)btHashedOverlappingPairCache();
              m_ownsPairCache = true;
       }

       // allocate handles buffer and put all handles on free list
       void* ptr = btAlignedAlloc(sizeof(btSimpleBroadphaseProxy)*maxProxies,16);
       m_pHandles = new(ptr) btSimpleBroadphaseProxy[maxProxies];
       m_maxHandles = maxProxies;
       m_numHandles = 0;
       m_firstFreeHandle = 0;
       m_firstAllocatedHandle = -1;

       {
              for (int i = m_firstFreeHandle; i < maxProxies; i++)
              {
                     m_pHandles[i].SetNextFree(i + 1);
                     m_pHandles[i].m_uniqueId = i+2;//any UID will do, we just avoid too trivial values (0,1) for debugging purposes
                     m_pHandles[i].SetNextAllocated(-1);
              }
              m_pHandles[maxProxies - 1].SetNextFree(0);
              m_pHandles[maxProxies - 1].SetNextAllocated(-1);
       
       }

}

Here is the call graph for this function:

Definition at line 74 of file btSimpleBroadphase.cpp.

{
       btAlignedFree(m_pHandles);

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

Member Function Documentation

Definition at line 157 of file btSimpleBroadphase.cpp.

{
       return proxy0->m_min[0] <= proxy1->m_max[0] && proxy1->m_min[0] <= proxy0->m_max[0] && 
                 proxy0->m_min[1] <= proxy1->m_max[1] && proxy1->m_min[1] <= proxy0->m_max[1] &&
                 proxy0->m_min[2] <= proxy1->m_max[2] && proxy1->m_min[2] <= proxy0->m_max[2];

}

Here is the caller graph for this function:

int btSimpleBroadphase::allocHandle ( ) [inline, protected]

Definition at line 65 of file btSimpleBroadphase.h.

Here is the call graph for this function:

Here is the caller 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 177 of file btSimpleBroadphase.cpp.

{
       //first check for new overlapping pairs
       int i,j;

       if (m_firstAllocatedHandle >= 0)
       {

              btSimpleBroadphaseProxy* proxy0 = &m_pHandles[m_firstAllocatedHandle];

              for (i=0;i<m_numHandles;i++)
              {
                     btSimpleBroadphaseProxy* proxy1 = &m_pHandles[m_firstAllocatedHandle];

                     for (j=0;j<m_numHandles;j++)
                     {
                            
                            if (proxy0 != proxy1)
                            {
                                   btSimpleBroadphaseProxy* p0 = getSimpleProxyFromProxy(proxy0);
                                   btSimpleBroadphaseProxy* p1 = getSimpleProxyFromProxy(proxy1);

                                   if (aabbOverlap(p0,p1))
                                   {
                                          if ( !m_pairCache->findPair(proxy0,proxy1))
                                          {
                                                 m_pairCache->addOverlappingPair(proxy0,proxy1);
                                          }
                                   } else
                                   {
                                   if (!m_pairCache->hasDeferredRemoval())
                                   {
                                          if ( m_pairCache->findPair(proxy0,proxy1))
                                          {
                                                 m_pairCache->removeOverlappingPair(proxy0,proxy1,dispatcher);
                                          }
                                   }

                                   }
                            }
                            proxy1 = &m_pHandles[proxy1->GetNextAllocated()];

                     }
                     proxy0 = &m_pHandles[proxy0->GetNextAllocated()];

              }

              if (m_ownsPairCache && m_pairCache->hasDeferredRemoval())
              {
                     
                     btBroadphasePairArray&      overlappingPairArray = m_pairCache->getOverlappingPairArray();

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

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


                     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];

                            bool isDuplicate = (pair == previousPair);

                            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)
                            {
                                   m_pairCache->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.quickSort(btBroadphasePairSortPredicate());

                     overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair);
                     m_invalidPair = 0;
              #endif//CLEAN_INVALID_PAIRS

              }
       }
}

Here is the call graph for this function:

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

Implements btBroadphaseInterface.

Definition at line 86 of file btSimpleBroadphase.cpp.

{
       if (m_numHandles >= m_maxHandles)
       {
              btAssert(0);
              return 0; //should never happen, but don't let the game crash ;-)
       }
       assert(aabbMin[0]<= aabbMax[0] && aabbMin[1]<= aabbMax[1] && aabbMin[2]<= aabbMax[2]);

       int newHandleIndex = allocHandle();
       btSimpleBroadphaseProxy* proxy = new (&m_pHandles[newHandleIndex])btSimpleBroadphaseProxy(aabbMin,aabbMax,shapeType,userPtr,collisionFilterGroup,collisionFilterMask,multiSapProxy);

       return proxy;
}

Here is the call graph for this function:

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

Implements btBroadphaseInterface.

Definition at line 130 of file btSimpleBroadphase.cpp.

{
              
              btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxyOrg);
              freeHandle(proxy0);

              m_pairCache->removeOverlappingPairsContainingProxy(proxyOrg,dispatcher);

              //validate();
              
}

Here is the call graph for this function:

void btSimpleBroadphase::freeHandle ( btSimpleBroadphaseProxy proxy) [inline, protected]

Definition at line 79 of file btSimpleBroadphase.h.

       {
              int handle = int(proxy-m_pHandles);
              btAssert(handle >= 0 && handle < m_maxHandles);

              proxy->SetNextFree(m_firstFreeHandle);
              m_firstFreeHandle = handle;

              m_firstAllocatedHandle = proxy->GetNextAllocated();
              proxy->SetNextAllocated(-1);

              m_numHandles--;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void btSimpleBroadphase::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 144 of file btSimpleBroadphase.h.

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

Here is the call graph for this function:

Implements btBroadphaseInterface.

Definition at line 130 of file btSimpleBroadphase.h.

       {
              return m_pairCache;
       }

Implements btBroadphaseInterface.

Definition at line 134 of file btSimpleBroadphase.h.

       {
              return m_pairCache;
       }
btSimpleBroadphaseProxy* btSimpleBroadphase::getSimpleProxyFromProxy ( btBroadphaseProxy *  proxy) [inline, protected]

Definition at line 101 of file btSimpleBroadphase.h.

       {
              btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy);
              return proxy0;
       }

Here is the caller graph for this function:

virtual void btSimpleBroadphase::printStats ( ) [inline, virtual]

Implements btBroadphaseInterface.

Definition at line 150 of file btSimpleBroadphase.h.

       {
//            printf("btSimpleBroadphase.h\n");
//            printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles);
       }
void btSimpleBroadphase::setAabb ( btBroadphaseProxy *  proxy,
const btVector3 aabbMin,
const btVector3 aabbMax,
btDispatcher dispatcher 
) [virtual]

Implements btBroadphaseInterface.

Definition at line 142 of file btSimpleBroadphase.cpp.

{
       btSimpleBroadphaseProxy* sbp = getSimpleProxyFromProxy(proxy);
       sbp->m_min = aabbMin;
       sbp->m_max = aabbMax;
}

Here is the call graph for this function:

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

Definition at line 302 of file btSimpleBroadphase.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void btSimpleBroadphase::validate ( ) [protected]

Definition at line 27 of file btSimpleBroadphase.cpp.

{
       for (int i=0;i<m_numHandles;i++)
       {
              for (int j=i+1;j<m_numHandles;j++)
              {
                     btAssert(&m_pHandles[i] != &m_pHandles[j]);
              }
       }
       
}

Member Data Documentation

Definition at line 63 of file btSimpleBroadphase.h.

Definition at line 62 of file btSimpleBroadphase.h.

Definition at line 97 of file btSimpleBroadphase.h.

Definition at line 60 of file btSimpleBroadphase.h.

Definition at line 59 of file btSimpleBroadphase.h.

Definition at line 95 of file btSimpleBroadphase.h.

Definition at line 94 of file btSimpleBroadphase.h.

Definition at line 61 of file btSimpleBroadphase.h.


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