Bullet Collision Detection & Physics Library
btSimpleBroadphase.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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 #ifndef BT_SIMPLE_BROADPHASE_H
17 #define BT_SIMPLE_BROADPHASE_H
18 
19 
20 #include "btOverlappingPairCache.h"
21 
22 
24 {
26 
27 // int m_handleId;
28 
29 
31 
32  btSimpleBroadphaseProxy(const btVector3& minpt,const btVector3& maxpt,int shapeType,void* userPtr, int collisionFilterGroup, int collisionFilterMask)
33  :btBroadphaseProxy(minpt,maxpt,userPtr,collisionFilterGroup,collisionFilterMask)
34  {
35  (void)shapeType;
36  }
37 
38 
39  SIMD_FORCE_INLINE void SetNextFree(int next) {m_nextFree = next;}
41 
42 
43 
44 
45 };
46 
50 {
51 
52 protected:
53 
54  int m_numHandles; // number of active handles
55  int m_maxHandles; // max number of handles
57 
59 
61  int m_firstFreeHandle; // free handles list
62 
64  {
68  m_numHandles++;
70  {
72  }
73  return freeHandle;
74  }
75 
77  {
78  int handle = int(proxy-m_pHandles);
79  btAssert(handle >= 0 && handle < m_maxHandles);
80  if(handle == m_LastHandleIndex)
81  {
83  }
85  m_firstFreeHandle = handle;
86 
87  proxy->m_clientObject = 0;
88 
89  m_numHandles--;
90  }
91 
94 
96 
97 
98 
100  {
101  btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy);
102  return proxy0;
103  }
104 
106  {
107  const btSimpleBroadphaseProxy* proxy0 = static_cast<const btSimpleBroadphaseProxy*>(proxy);
108  return proxy0;
109  }
110 
112  virtual void resetPool(btDispatcher* dispatcher);
113 
114 
115  void validate();
116 
117 protected:
118 
119 
120 
121 
122 public:
123  btSimpleBroadphase(int maxProxies=16384,btOverlappingPairCache* overlappingPairCache=0);
124  virtual ~btSimpleBroadphase();
125 
126 
127  static bool aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1);
128 
129 
130  virtual btBroadphaseProxy* createProxy( const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr , int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher);
131 
132  virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
133 
134  virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
135  virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher);
136  virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
137 
138  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));
139  virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
140 
142  {
143  return m_pairCache;
144  }
146  {
147  return m_pairCache;
148  }
149 
151 
152 
155  virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
156  {
159  }
160 
161  virtual void printStats()
162  {
163 // printf("btSimpleBroadphase.h\n");
164 // printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles);
165  }
166 };
167 
168 
169 
170 #endif //BT_SIMPLE_BROADPHASE_H
171 
btBroadphaseProxy
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
Definition: btBroadphaseProxy.h:85
btBroadphaseAabbCallback
Definition: btBroadphaseInterface.h:29
btSimpleBroadphase::validate
void validate()
Definition: btSimpleBroadphase.cpp:29
btSimpleBroadphase::allocHandle
int allocHandle()
Definition: btSimpleBroadphase.h:63
btSimpleBroadphase::calculateOverlappingPairs
virtual void calculateOverlappingPairs(btDispatcher *dispatcher)
calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during th...
Definition: btSimpleBroadphase.cpp:213
btVector3::setValue
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:652
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:75
btSimpleBroadphase::freeHandle
void freeHandle(btSimpleBroadphaseProxy *proxy)
Definition: btSimpleBroadphase.h:76
btSimpleBroadphase::testAabbOverlap
bool testAabbOverlap(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1)
Definition: btSimpleBroadphase.cpp:339
btSimpleBroadphase::getSimpleProxyFromProxy
btSimpleBroadphaseProxy * getSimpleProxyFromProxy(btBroadphaseProxy *proxy)
Definition: btSimpleBroadphase.h:99
btSimpleBroadphase::aabbOverlap
static bool aabbOverlap(btSimpleBroadphaseProxy *proxy0, btSimpleBroadphaseProxy *proxy1)
Definition: btSimpleBroadphase.cpp:193
btSimpleBroadphase::getOverlappingPairCache
const btOverlappingPairCache * getOverlappingPairCache() const
Definition: btSimpleBroadphase.h:145
btSimpleBroadphaseProxy::btSimpleBroadphaseProxy
btSimpleBroadphaseProxy(const btVector3 &minpt, const btVector3 &maxpt, int shapeType, void *userPtr, int collisionFilterGroup, int collisionFilterMask)
Definition: btSimpleBroadphase.h:32
btSimpleBroadphaseProxy::GetNextFree
int GetNextFree() const
Definition: btSimpleBroadphase.h:40
btSimpleBroadphase::m_LastHandleIndex
int m_LastHandleIndex
Definition: btSimpleBroadphase.h:56
btSimpleBroadphase::m_firstFreeHandle
int m_firstFreeHandle
Definition: btSimpleBroadphase.h:61
btSimpleBroadphase::m_invalidPair
int m_invalidPair
Definition: btSimpleBroadphase.h:95
btAssert
#define btAssert(x)
Definition: btScalar.h:131
BT_LARGE_FLOAT
#define BT_LARGE_FLOAT
Definition: btScalar.h:294
btSimpleBroadphase::getOverlappingPairCache
btOverlappingPairCache * getOverlappingPairCache()
Definition: btSimpleBroadphase.h:141
btSimpleBroadphase::getSimpleProxyFromProxy
const btSimpleBroadphaseProxy * getSimpleProxyFromProxy(btBroadphaseProxy *proxy) const
Definition: btSimpleBroadphase.h:105
btSimpleBroadphaseProxy::m_nextFree
int m_nextFree
Definition: btSimpleBroadphase.h:25
btSimpleBroadphase::btSimpleBroadphase
btSimpleBroadphase(int maxProxies=16384, btOverlappingPairCache *overlappingPairCache=0)
Definition: btSimpleBroadphase.cpp:41
btSimpleBroadphase::resetPool
virtual void resetPool(btDispatcher *dispatcher)
reset broadphase internal structures, to ensure determinism/reproducability
Definition: btSimpleBroadphase.cpp:346
btOverlappingPairCache.h
btSimpleBroadphase::m_pairCache
btOverlappingPairCache * m_pairCache
Definition: btSimpleBroadphase.h:92
btBroadphaseProxy::m_clientObject
void * m_clientObject
Definition: btBroadphaseProxy.h:103
btOverlappingPairCache
The btOverlappingPairCache provides an interface for overlapping pair management (add,...
Definition: btOverlappingPairCache.h:60
btSimpleBroadphase::rayTest
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))
Definition: btSimpleBroadphase.cpp:157
btSimpleBroadphase::m_ownsPairCache
bool m_ownsPairCache
Definition: btSimpleBroadphase.h:93
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btSimpleBroadphase::~btSimpleBroadphase
virtual ~btSimpleBroadphase()
Definition: btSimpleBroadphase.cpp:75
btSimpleBroadphase::m_maxHandles
int m_maxHandles
Definition: btSimpleBroadphase.h:55
btSimpleBroadphase::getAabb
virtual void getAabb(btBroadphaseProxy *proxy, btVector3 &aabbMin, btVector3 &aabbMax) const
Definition: btSimpleBroadphase.cpp:143
btSimpleBroadphaseProxy::btSimpleBroadphaseProxy
btSimpleBroadphaseProxy()
Definition: btSimpleBroadphase.h:30
btSimpleBroadphaseProxy::SetNextFree
void SetNextFree(int next)
Definition: btSimpleBroadphase.h:39
btSimpleBroadphase::aabbTest
virtual void aabbTest(const btVector3 &aabbMin, const btVector3 &aabbMax, btBroadphaseAabbCallback &callback)
Definition: btSimpleBroadphase.cpp:171
btSimpleBroadphase::m_pHandles
btSimpleBroadphaseProxy * m_pHandles
Definition: btSimpleBroadphase.h:58
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:81
btSimpleBroadphase::getBroadphaseAabb
virtual void getBroadphaseAabb(btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb returns the axis aligned bounding box in the 'global' coordinate frame will add some transfor...
Definition: btSimpleBroadphase.h:155
btSimpleBroadphase::m_pHandlesRawPtr
void * m_pHandlesRawPtr
Definition: btSimpleBroadphase.h:60
btBroadphaseInterface
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs.
Definition: btBroadphaseInterface.h:55
btSimpleBroadphase::printStats
virtual void printStats()
Definition: btSimpleBroadphase.h:161
btSimpleBroadphase::createProxy
virtual btBroadphaseProxy * createProxy(const btVector3 &aabbMin, const btVector3 &aabbMax, int shapeType, void *userPtr, int collisionFilterGroup, int collisionFilterMask, btDispatcher *dispatcher)
Definition: btSimpleBroadphase.cpp:87
btSimpleBroadphase::m_numHandles
int m_numHandles
Definition: btSimpleBroadphase.h:54
btSimpleBroadphase::setAabb
virtual void setAabb(btBroadphaseProxy *proxy, const btVector3 &aabbMin, const btVector3 &aabbMax, btDispatcher *dispatcher)
Definition: btSimpleBroadphase.cpp:150
btSimpleBroadphaseProxy
Definition: btSimpleBroadphase.h:23
btSimpleBroadphase
The SimpleBroadphase is just a unit-test for btAxisSweep3, bt32BitAxisSweep3, or btDbvtBroadphase,...
Definition: btSimpleBroadphase.h:49
btSimpleBroadphase::destroyProxy
virtual void destroyProxy(btBroadphaseProxy *proxy, btDispatcher *dispatcher)
Definition: btSimpleBroadphase.cpp:131
btBroadphaseRayCallback
Definition: btBroadphaseInterface.h:36