Back to index

supertuxkart  0.5+dfsg1
btSimpleBroadphase.h
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #ifndef SIMPLE_BROADPHASE_H
00017 #define SIMPLE_BROADPHASE_H
00018 
00019 
00020 #include "btOverlappingPairCache.h"
00021 
00022 
00023 struct btSimpleBroadphaseProxy : public btBroadphaseProxy
00024 {
00025        btVector3     m_min;
00026        btVector3     m_max;
00027        int                  m_nextFree;
00028        int                  m_nextAllocated;
00029 //     int                  m_handleId;
00030 
00031        
00032        btSimpleBroadphaseProxy() {};
00033 
00034        btSimpleBroadphaseProxy(const btPoint3& minpt,const btPoint3& maxpt,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,void* multiSapProxy)
00035        :btBroadphaseProxy(userPtr,collisionFilterGroup,collisionFilterMask,multiSapProxy),
00036        m_min(minpt),m_max(maxpt)          
00037        {
00038               (void)shapeType;
00039        }
00040        
00041        
00042        SIMD_FORCE_INLINE void SetNextFree(int next) {m_nextFree = next;}
00043        SIMD_FORCE_INLINE int GetNextFree() const {return m_nextFree;}
00044 
00045        SIMD_FORCE_INLINE void SetNextAllocated(int next) {m_nextAllocated = next;}
00046        SIMD_FORCE_INLINE int GetNextAllocated() const {return m_nextAllocated;}
00047 
00048 
00049 };
00050 
00054 class btSimpleBroadphase : public btBroadphaseInterface
00055 {
00056 
00057 protected:
00058 
00059        int           m_numHandles;                                    // number of active handles
00060        int           m_maxHandles;                                    // max number of handles
00061        btSimpleBroadphaseProxy* m_pHandles;                                         // handles pool
00062        int           m_firstFreeHandle;          // free handles list
00063        int           m_firstAllocatedHandle;
00064 
00065        int allocHandle()
00066        {
00067 
00068               int freeHandle = m_firstFreeHandle;
00069               m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree();
00070               
00071               m_pHandles[freeHandle].SetNextAllocated(m_firstAllocatedHandle);
00072               m_firstAllocatedHandle = freeHandle;
00073               
00074               m_numHandles++;
00075 
00076               return freeHandle;
00077        }
00078 
00079        void freeHandle(btSimpleBroadphaseProxy* proxy)
00080        {
00081               int handle = int(proxy-m_pHandles);
00082               btAssert(handle >= 0 && handle < m_maxHandles);
00083 
00084               proxy->SetNextFree(m_firstFreeHandle);
00085               m_firstFreeHandle = handle;
00086 
00087               m_firstAllocatedHandle = proxy->GetNextAllocated();
00088               proxy->SetNextAllocated(-1);
00089 
00090               m_numHandles--;
00091        }
00092 
00093 
00094        btOverlappingPairCache*     m_pairCache;
00095        bool   m_ownsPairCache;
00096 
00097        int    m_invalidPair;
00098 
00099        
00100        
00101        inline btSimpleBroadphaseProxy*    getSimpleProxyFromProxy(btBroadphaseProxy* proxy)
00102        {
00103               btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy);
00104               return proxy0;
00105        }
00106 
00107 
00108        void   validate();
00109 
00110 protected:
00111 
00112 
00113        
00114 
00115 public:
00116        btSimpleBroadphase(int maxProxies=16384,btOverlappingPairCache* overlappingPairCache=0);
00117        virtual ~btSimpleBroadphase();
00118 
00119 
00120               static bool   aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1);
00121 
00122 
00123        virtual btBroadphaseProxy*  createProxy(  const btVector3& aabbMin,  const btVector3& aabbMax,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy);
00124 
00125        virtual void  calculateOverlappingPairs(btDispatcher* dispatcher);
00126 
00127        virtual void  destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
00128        virtual void  setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher);
00129               
00130        btOverlappingPairCache*     getOverlappingPairCache()
00131        {
00132               return m_pairCache;
00133        }
00134        const btOverlappingPairCache*      getOverlappingPairCache() const
00135        {
00136               return m_pairCache;
00137        }
00138 
00139        bool   testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
00140 
00141 
00144        virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
00145        {
00146               aabbMin.setValue(-1e30f,-1e30f,-1e30f);
00147               aabbMax.setValue(1e30f,1e30f,1e30f);
00148        }
00149 
00150        virtual void  printStats()
00151        {
00152 //            printf("btSimpleBroadphase.h\n");
00153 //            printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles);
00154        }
00155 };
00156 
00157 
00158 
00159 #endif //SIMPLE_BROADPHASE_H
00160