Bullet Collision Detection & Physics Library
btGpu3DGridBroadphase.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
3 Copyright (C) 2006, 2009 Sony Computer Entertainment Inc.
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 //----------------------------------------------------------------------------------------
17 
18 #ifndef BTGPU3DGRIDBROADPHASE_H
19 #define BTGPU3DGRIDBROADPHASE_H
20 
21 //----------------------------------------------------------------------------------------
22 
24 
26 
27 //----------------------------------------------------------------------------------------
28 
30 
32 {
33 protected:
35  unsigned int m_numBodies;
36  unsigned int m_numCells;
37  unsigned int m_maxPairsPerBody;
39  unsigned int m_maxBodiesPerCell;
42  // CPU data
43  unsigned int* m_hBodiesHash;
44  unsigned int* m_hCellStart;
45  unsigned int* m_hPairBuffStartCurr;
47  unsigned int* m_hPairBuff;
48  unsigned int* m_hPairScan;
49  unsigned int* m_hPairOut;
50 // large proxies
58  {
63  if(freeLargeHandle > m_LastLargeHandleIndex)
64  {
66  }
67  return freeLargeHandle;
68  }
70  {
71  int handle = int(proxy - m_pLargeHandles);
72  btAssert((handle >= 0) && (handle < m_maxHandles));
73  if(handle == m_LastLargeHandleIndex)
74  {
76  }
78  m_firstFreeLargeHandle = handle;
79  proxy->m_clientObject = 0;
81  }
82  bool isLargeProxy(const btVector3& aabbMin, const btVector3& aabbMax);
83  bool isLargeProxy(btBroadphaseProxy* proxy);
84 // debug
85  unsigned int m_numPairsAdded;
86  unsigned int m_numPairsRemoved;
87  unsigned int m_numOverflows;
88 //
89 public:
90  btGpu3DGridBroadphase(const btVector3& worldAabbMin,const btVector3& worldAabbMax,
91  int gridSizeX, int gridSizeY, int gridSizeZ,
92  int maxSmallProxies, int maxLargeProxies, int maxPairsPerBody,
93  int maxBodiesPerCell = 8,
94  btScalar cellFactorAABB = btScalar(1.0f));
95  btGpu3DGridBroadphase( btOverlappingPairCache* overlappingPairCache,
96  const btVector3& worldAabbMin,const btVector3& worldAabbMax,
97  int gridSizeX, int gridSizeY, int gridSizeZ,
98  int maxSmallProxies, int maxLargeProxies, int maxPairsPerBody,
99  int maxBodiesPerCell = 8,
100  btScalar cellFactorAABB = btScalar(1.0f));
101  virtual ~btGpu3DGridBroadphase();
102  virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
103 
104  virtual btBroadphaseProxy* createProxy(const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy);
105  virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
106  virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0),const btVector3& aabbMax=btVector3(0,0,0));
107 
108 
109  virtual void resetPool(btDispatcher* dispatcher);
110 
111 protected:
112  void _initialize( const btVector3& worldAabbMin,const btVector3& worldAabbMax,
113  int gridSizeX, int gridSizeY, int gridSizeZ,
114  int maxSmallProxies, int maxLargeProxies, int maxPairsPerBody,
115  int maxBodiesPerCell = 8,
116  btScalar cellFactorAABB = btScalar(1.0f));
117  void _finalize();
118  void addPairsToCache(btDispatcher* dispatcher);
119  void addLarge2LargePairsToCache(btDispatcher* dispatcher);
120 
121 // overrides for CPU version
122  virtual void setParameters(bt3DGridBroadphaseParams* hostParams);
123  virtual void prepareAABB();
124  virtual void calcHashAABB();
125  virtual void sortHash();
126  virtual void findCellStart();
127  virtual void findOverlappingPairs();
128  virtual void findPairsLarge();
129  virtual void computePairCacheChanges();
130  virtual void scanOverlappingPairBuff();
131  virtual void squeezeOverlappingPairBuff();
132 };
133 
134 //----------------------------------------------------------------------------------------
135 
136 #endif //BTGPU3DGRIDBROADPHASE_H
137 
138 //----------------------------------------------------------------------------------------
139 //----------------------------------------------------------------------------------------
140 //----------------------------------------------------------------------------------------
bt3DGridBroadphaseParams m_params
The btGpu3DGridBroadphase uses GPU-style code compiled for CPU to compute overlapping pairs...
virtual void computePairCacheChanges()
virtual void setParameters(bt3DGridBroadphaseParams *hostParams)
#define btAssert(x)
Definition: btScalar.h:101
virtual void destroyProxy(btBroadphaseProxy *proxy, btDispatcher *dispatcher)
void freeLargeHandle(btSimpleBroadphaseProxy *proxy)
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 squeezeOverlappingPairBuff()
void _initialize(const btVector3 &worldAabbMin, const btVector3 &worldAabbMax, int gridSizeX, int gridSizeY, int gridSizeZ, int maxSmallProxies, int maxLargeProxies, int maxPairsPerBody, int maxBodiesPerCell=8, btScalar cellFactorAABB=btScalar(1.0f))
virtual void scanOverlappingPairBuff()
The btOverlappingPairCache provides an interface for overlapping pair management (add, remove, storage), used by the btBroadphaseInterface broadphases.
void addPairsToCache(btDispatcher *dispatcher)
bool isLargeProxy(const btVector3 &aabbMin, const btVector3 &aabbMax)
btGpu3DGridBroadphase(const btVector3 &worldAabbMin, const btVector3 &worldAabbMax, int gridSizeX, int gridSizeY, int gridSizeZ, int maxSmallProxies, int maxLargeProxies, int maxPairsPerBody, int maxBodiesPerCell=8, btScalar cellFactorAABB=btScalar(1.0f))
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
unsigned int * m_hPairBuffStartCurr
btSimpleBroadphaseProxy * m_pLargeHandles
The SimpleBroadphase is just a unit-test for btAxisSweep3, bt32BitAxisSweep3, or btDbvtBroadphase, so use those classes instead.
virtual void resetPool(btDispatcher *dispatcher)
reset broadphase internal structures, to ensure determinism/reproducability
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:69
void addLarge2LargePairsToCache(btDispatcher *dispatcher)
virtual void calculateOverlappingPairs(btDispatcher *dispatcher)
calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during th...
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:266
virtual void rayTest(const btVector3 &rayFrom, const btVector3 &rayTo, btBroadphaseRayCallback &rayCallback, const btVector3 &aabbMin=btVector3(0, 0, 0), const btVector3 &aabbMax=btVector3(0, 0, 0))