|
Bullet Collision Detection & Physics Library
|
00001 /* 00002 Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org 00003 Copyright (C) 2006, 2009 Sony Computer Entertainment Inc. 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 //---------------------------------------------------------------------------------------- 00017 00018 #ifndef BTGPU3DGRIDBROADPHASE_H 00019 #define BTGPU3DGRIDBROADPHASE_H 00020 00021 //---------------------------------------------------------------------------------------- 00022 00023 #include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h" 00024 00025 #include "btGpu3DGridBroadphaseSharedTypes.h" 00026 00027 //---------------------------------------------------------------------------------------- 00028 00030 00031 class btGpu3DGridBroadphase : public btSimpleBroadphase 00032 { 00033 protected: 00034 bool m_bInitialized; 00035 unsigned int m_numBodies; 00036 unsigned int m_numCells; 00037 unsigned int m_maxPairsPerBody; 00038 btScalar m_cellFactorAABB; 00039 unsigned int m_maxBodiesPerCell; 00040 bt3DGridBroadphaseParams m_params; 00041 btScalar m_maxRadius; 00042 // CPU data 00043 unsigned int* m_hBodiesHash; 00044 unsigned int* m_hCellStart; 00045 unsigned int* m_hPairBuffStartCurr; 00046 bt3DGrid3F1U* m_hAABB; 00047 unsigned int* m_hPairBuff; 00048 unsigned int* m_hPairScan; 00049 unsigned int* m_hPairOut; 00050 // large proxies 00051 int m_numLargeHandles; 00052 int m_maxLargeHandles; 00053 int m_LastLargeHandleIndex; 00054 btSimpleBroadphaseProxy* m_pLargeHandles; 00055 void* m_pLargeHandlesRawPtr; 00056 int m_firstFreeLargeHandle; 00057 int allocLargeHandle() 00058 { 00059 btAssert(m_numLargeHandles < m_maxLargeHandles); 00060 int freeLargeHandle = m_firstFreeLargeHandle; 00061 m_firstFreeLargeHandle = m_pLargeHandles[freeLargeHandle].GetNextFree(); 00062 m_numLargeHandles++; 00063 if(freeLargeHandle > m_LastLargeHandleIndex) 00064 { 00065 m_LastLargeHandleIndex = freeLargeHandle; 00066 } 00067 return freeLargeHandle; 00068 } 00069 void freeLargeHandle(btSimpleBroadphaseProxy* proxy) 00070 { 00071 int handle = int(proxy - m_pLargeHandles); 00072 btAssert((handle >= 0) && (handle < m_maxHandles)); 00073 if(handle == m_LastLargeHandleIndex) 00074 { 00075 m_LastLargeHandleIndex--; 00076 } 00077 proxy->SetNextFree(m_firstFreeLargeHandle); 00078 m_firstFreeLargeHandle = handle; 00079 proxy->m_clientObject = 0; 00080 m_numLargeHandles--; 00081 } 00082 bool isLargeProxy(const btVector3& aabbMin, const btVector3& aabbMax); 00083 bool isLargeProxy(btBroadphaseProxy* proxy); 00084 // debug 00085 unsigned int m_numPairsAdded; 00086 unsigned int m_numPairsRemoved; 00087 unsigned int m_numOverflows; 00088 // 00089 public: 00090 btGpu3DGridBroadphase(const btVector3& worldAabbMin,const btVector3& worldAabbMax, 00091 int gridSizeX, int gridSizeY, int gridSizeZ, 00092 int maxSmallProxies, int maxLargeProxies, int maxPairsPerBody, 00093 int maxBodiesPerCell = 8, 00094 btScalar cellFactorAABB = btScalar(1.0f)); 00095 btGpu3DGridBroadphase( btOverlappingPairCache* overlappingPairCache, 00096 const btVector3& worldAabbMin,const btVector3& worldAabbMax, 00097 int gridSizeX, int gridSizeY, int gridSizeZ, 00098 int maxSmallProxies, int maxLargeProxies, int maxPairsPerBody, 00099 int maxBodiesPerCell = 8, 00100 btScalar cellFactorAABB = btScalar(1.0f)); 00101 virtual ~btGpu3DGridBroadphase(); 00102 virtual void calculateOverlappingPairs(btDispatcher* dispatcher); 00103 00104 virtual btBroadphaseProxy* createProxy(const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy); 00105 virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher); 00106 virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback); 00107 virtual void resetPool(btDispatcher* dispatcher); 00108 00109 protected: 00110 void _initialize( const btVector3& worldAabbMin,const btVector3& worldAabbMax, 00111 int gridSizeX, int gridSizeY, int gridSizeZ, 00112 int maxSmallProxies, int maxLargeProxies, int maxPairsPerBody, 00113 int maxBodiesPerCell = 8, 00114 btScalar cellFactorAABB = btScalar(1.0f)); 00115 void _finalize(); 00116 void addPairsToCache(btDispatcher* dispatcher); 00117 void addLarge2LargePairsToCache(btDispatcher* dispatcher); 00118 00119 // overrides for CPU version 00120 virtual void setParameters(bt3DGridBroadphaseParams* hostParams); 00121 virtual void prepareAABB(); 00122 virtual void calcHashAABB(); 00123 virtual void sortHash(); 00124 virtual void findCellStart(); 00125 virtual void findOverlappingPairs(); 00126 virtual void findPairsLarge(); 00127 virtual void computePairCacheChanges(); 00128 virtual void scanOverlappingPairBuff(); 00129 virtual void squeezeOverlappingPairBuff(); 00130 }; 00131 00132 //---------------------------------------------------------------------------------------- 00133 00134 #endif //BTGPU3DGRIDBROADPHASE_H 00135 00136 //---------------------------------------------------------------------------------------- 00137 //---------------------------------------------------------------------------------------- 00138 //----------------------------------------------------------------------------------------