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 #include "btOverlappingPairCache.h"
20 
22 {
24 
25  // int m_handleId;
26 
28 
29  btSimpleBroadphaseProxy(const btVector3& minpt, const btVector3& maxpt, int shapeType, void* userPtr, int collisionFilterGroup, int collisionFilterMask)
30  : btBroadphaseProxy(minpt, maxpt, userPtr, collisionFilterGroup, collisionFilterMask)
31  {
32  (void)shapeType;
33  }
34 
35  SIMD_FORCE_INLINE void SetNextFree(int next) { m_nextFree = next; }
36  SIMD_FORCE_INLINE int GetNextFree() const { return m_nextFree; }
37 };
38 
42 {
43 protected:
44  int m_numHandles; // number of active handles
45  int m_maxHandles; // max number of handles
47 
49 
51  int m_firstFreeHandle; // free handles list
52 
54  {
58  m_numHandles++;
60  {
62  }
63  return freeHandle;
64  }
65 
67  {
68  int handle = int(proxy - m_pHandles);
69  btAssert(handle >= 0 && handle < m_maxHandles);
70  if (handle == m_LastHandleIndex)
71  {
73  }
75  m_firstFreeHandle = handle;
76 
77  proxy->m_clientObject = 0;
78 
79  m_numHandles--;
80  }
81 
84 
86 
88  {
89  btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy);
90  return proxy0;
91  }
92 
94  {
95  const btSimpleBroadphaseProxy* proxy0 = static_cast<const btSimpleBroadphaseProxy*>(proxy);
96  return proxy0;
97  }
98 
100  virtual void resetPool(btDispatcher* dispatcher);
101 
102  void validate();
103 
104 protected:
105 public:
106  btSimpleBroadphase(int maxProxies = 16384, btOverlappingPairCache* overlappingPairCache = 0);
107  virtual ~btSimpleBroadphase();
108 
109  static bool aabbOverlap(btSimpleBroadphaseProxy* proxy0, btSimpleBroadphaseProxy* proxy1);
110 
111  virtual btBroadphaseProxy* createProxy(const btVector3& aabbMin, const btVector3& aabbMax, int shapeType, void* userPtr, int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher);
112 
113  virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
114 
115  virtual void destroyProxy(btBroadphaseProxy* proxy, btDispatcher* dispatcher);
116  virtual void setAabb(btBroadphaseProxy* proxy, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* dispatcher);
117  virtual void getAabb(btBroadphaseProxy* proxy, btVector3& aabbMin, btVector3& aabbMax) const;
118 
119  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));
120  virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
121 
123  {
124  return m_pairCache;
125  }
127  {
128  return m_pairCache;
129  }
130 
131  bool testAabbOverlap(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1);
132 
135  virtual void getBroadphaseAabb(btVector3& aabbMin, btVector3& aabbMax) const
136  {
139  }
140 
141  virtual void printStats()
142  {
143  // printf("btSimpleBroadphase.h\n");
144  // printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles);
145  }
146 };
147 
148 #endif //BT_SIMPLE_BROADPHASE_H
btBroadphaseProxy
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
Definition: btBroadphaseProxy.h:84
btBroadphaseAabbCallback
Definition: btBroadphaseInterface.h:25
btSimpleBroadphase::validate
void validate()
Definition: btSimpleBroadphase.cpp:27
btSimpleBroadphase::allocHandle
int allocHandle()
Definition: btSimpleBroadphase.h:53
btSimpleBroadphase::calculateOverlappingPairs
virtual void calculateOverlappingPairs(btDispatcher *dispatcher)
calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during th...
Definition: btSimpleBroadphase.cpp:194
btVector3::setValue
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:640
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:76
btSimpleBroadphase::freeHandle
void freeHandle(btSimpleBroadphaseProxy *proxy)
Definition: btSimpleBroadphase.h:66
btSimpleBroadphase::testAabbOverlap
bool testAabbOverlap(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1)
Definition: btSimpleBroadphase.cpp:315
btSimpleBroadphase::getSimpleProxyFromProxy
btSimpleBroadphaseProxy * getSimpleProxyFromProxy(btBroadphaseProxy *proxy)
Definition: btSimpleBroadphase.h:87
btSimpleBroadphase::aabbOverlap
static bool aabbOverlap(btSimpleBroadphaseProxy *proxy0, btSimpleBroadphaseProxy *proxy1)
Definition: btSimpleBroadphase.cpp:177
btSimpleBroadphase::getOverlappingPairCache
const btOverlappingPairCache * getOverlappingPairCache() const
Definition: btSimpleBroadphase.h:126
btSimpleBroadphaseProxy::btSimpleBroadphaseProxy
btSimpleBroadphaseProxy(const btVector3 &minpt, const btVector3 &maxpt, int shapeType, void *userPtr, int collisionFilterGroup, int collisionFilterMask)
Definition: btSimpleBroadphase.h:29
btSimpleBroadphaseProxy::GetNextFree
int GetNextFree() const
Definition: btSimpleBroadphase.h:36
btSimpleBroadphase::m_LastHandleIndex
int m_LastHandleIndex
Definition: btSimpleBroadphase.h:46
btSimpleBroadphase::m_firstFreeHandle
int m_firstFreeHandle
Definition: btSimpleBroadphase.h:51
btSimpleBroadphase::m_invalidPair
int m_invalidPair
Definition: btSimpleBroadphase.h:85
btAssert
#define btAssert(x)
Definition: btScalar.h:133
BT_LARGE_FLOAT
#define BT_LARGE_FLOAT
Definition: btScalar.h:296
btSimpleBroadphase::getOverlappingPairCache
btOverlappingPairCache * getOverlappingPairCache()
Definition: btSimpleBroadphase.h:122
btSimpleBroadphase::getSimpleProxyFromProxy
const btSimpleBroadphaseProxy * getSimpleProxyFromProxy(btBroadphaseProxy *proxy) const
Definition: btSimpleBroadphase.h:93
btSimpleBroadphaseProxy::m_nextFree
int m_nextFree
Definition: btSimpleBroadphase.h:23
btSimpleBroadphase::btSimpleBroadphase
btSimpleBroadphase(int maxProxies=16384, btOverlappingPairCache *overlappingPairCache=0)
Definition: btSimpleBroadphase.cpp:38
btSimpleBroadphase::resetPool
virtual void resetPool(btDispatcher *dispatcher)
reset broadphase internal structures, to ensure determinism/reproducability
Definition: btSimpleBroadphase.cpp:322
btOverlappingPairCache.h
btSimpleBroadphase::m_pairCache
btOverlappingPairCache * m_pairCache
Definition: btSimpleBroadphase.h:82
btBroadphaseProxy::m_clientObject
void * m_clientObject
Definition: btBroadphaseProxy.h:102
btOverlappingPairCache
The btOverlappingPairCache provides an interface for overlapping pair management (add,...
Definition: btOverlappingPairCache.h:50
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:148
btSimpleBroadphase::m_ownsPairCache
bool m_ownsPairCache
Definition: btSimpleBroadphase.h:83
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:80
btSimpleBroadphase::~btSimpleBroadphase
virtual ~btSimpleBroadphase()
Definition: btSimpleBroadphase.cpp:68
btSimpleBroadphase::m_maxHandles
int m_maxHandles
Definition: btSimpleBroadphase.h:45
btSimpleBroadphase::getAabb
virtual void getAabb(btBroadphaseProxy *proxy, btVector3 &aabbMin, btVector3 &aabbMax) const
Definition: btSimpleBroadphase.cpp:134
btSimpleBroadphaseProxy::btSimpleBroadphaseProxy
btSimpleBroadphaseProxy()
Definition: btSimpleBroadphase.h:27
btSimpleBroadphaseProxy::SetNextFree
void SetNextFree(int next)
Definition: btSimpleBroadphase.h:35
btSimpleBroadphase::aabbTest
virtual void aabbTest(const btVector3 &aabbMin, const btVector3 &aabbMax, btBroadphaseAabbCallback &callback)
Definition: btSimpleBroadphase.cpp:161
btSimpleBroadphase::m_pHandles
btSimpleBroadphaseProxy * m_pHandles
Definition: btSimpleBroadphase.h:48
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:83
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:135
btSimpleBroadphase::m_pHandlesRawPtr
void * m_pHandlesRawPtr
Definition: btSimpleBroadphase.h:50
btBroadphaseInterface
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs.
Definition: btBroadphaseInterface.h:49
btSimpleBroadphase::printStats
virtual void printStats()
Definition: btSimpleBroadphase.h:141
btSimpleBroadphase::createProxy
virtual btBroadphaseProxy * createProxy(const btVector3 &aabbMin, const btVector3 &aabbMax, int shapeType, void *userPtr, int collisionFilterGroup, int collisionFilterMask, btDispatcher *dispatcher)
Definition: btSimpleBroadphase.cpp:79
btSimpleBroadphase::m_numHandles
int m_numHandles
Definition: btSimpleBroadphase.h:44
btSimpleBroadphase::setAabb
virtual void setAabb(btBroadphaseProxy *proxy, const btVector3 &aabbMin, const btVector3 &aabbMax, btDispatcher *dispatcher)
Definition: btSimpleBroadphase.cpp:141
btSimpleBroadphaseProxy
Definition: btSimpleBroadphase.h:21
btSimpleBroadphase
The SimpleBroadphase is just a unit-test for btAxisSweep3, bt32BitAxisSweep3, or btDbvtBroadphase,...
Definition: btSimpleBroadphase.h:41
btSimpleBroadphase::destroyProxy
virtual void destroyProxy(btBroadphaseProxy *proxy, btDispatcher *dispatcher)
Definition: btSimpleBroadphase.cpp:124
btBroadphaseRayCallback
Definition: btBroadphaseInterface.h:31