Bullet Collision Detection & Physics Library: btSimpleBroadphase.h Source File

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
23 struct btSimpleBroadphaseProxy : public btBroadphaseProxy
24 {
25 int m_nextFree;
26
27 // int m_handleId;
28
29
30 btSimpleBroadphaseProxy() {};
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;}
40 SIMD_FORCE_INLINE int GetNextFree() const {return m_nextFree;}
41
42
43
44
45 };
46
49 class btSimpleBroadphase : public btBroadphaseInterface
50 {
51
52 protected:
53
54 int m_numHandles; // number of active handles
55 int m_maxHandles; // max number of handles
56 int m_LastHandleIndex;
57
58 btSimpleBroadphaseProxy* m_pHandles; // handles pool
59
60 void* m_pHandlesRawPtr;
61 int m_firstFreeHandle; // free handles list
62
63 int allocHandle()
64 {
65 btAssert(m_numHandles < m_maxHandles);
66 int freeHandle = m_firstFreeHandle;
67 m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree();
68 m_numHandles++;
69 if(freeHandle > m_LastHandleIndex)
70 {
71 m_LastHandleIndex = freeHandle;
72 }
73 return freeHandle;
74 }
75
76 void freeHandle(btSimpleBroadphaseProxy* proxy)
77 {
78 int handle = int(proxy-m_pHandles);
79 btAssert(handle >= 0 && handle < m_maxHandles);
80 if(handle == m_LastHandleIndex)
81 {
82 m_LastHandleIndex--;
83 }
84 proxy->SetNextFree(m_firstFreeHandle);
85 m_firstFreeHandle = handle;
86
87 proxy->m_clientObject = 0;
88
89 m_numHandles--;
90 }
91
92 btOverlappingPairCache* m_pairCache;
93 bool m_ownsPairCache;
94
95 int m_invalidPair;
96
97
98
99 inline btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy)
100 {
101 btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy);
102 return proxy0;
103 }
104
105 inline const btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy) const
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
141 btOverlappingPairCache* getOverlappingPairCache()
142 {
143 return m_pairCache;
144 }
145 const btOverlappingPairCache* getOverlappingPairCache() const
146 {
147 return m_pairCache;
148 }
149
150 bool testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
151
152
155 virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
156 {
157 aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
158 aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
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
btSimpleBroadphase::m_pHandles
btSimpleBroadphaseProxy * m_pHandles
Definition: btSimpleBroadphase.h:58
btSimpleBroadphaseProxy::btSimpleBroadphaseProxy
btSimpleBroadphaseProxy()
Definition: btSimpleBroadphase.h:30
btSimpleBroadphase::allocHandle
int allocHandle()
Definition: btSimpleBroadphase.h:63
btSimpleBroadphase::m_maxHandles
int m_maxHandles
Definition: btSimpleBroadphase.h:55
BT_LARGE_FLOAT
#define BT_LARGE_FLOAT
Definition: btScalar.h:294
btSimpleBroadphase::m_invalidPair
int m_invalidPair
Definition: btSimpleBroadphase.h:95
btVector3::setValue
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:652
btSimpleBroadphase::freeHandle
void freeHandle(btSimpleBroadphaseProxy *proxy)
Definition: btSimpleBroadphase.h:76
btSimpleBroadphaseProxy::m_nextFree
int m_nextFree
Definition: btSimpleBroadphase.h:25
btSimpleBroadphase::m_firstFreeHandle
int m_firstFreeHandle
Definition: btSimpleBroadphase.h:61
btSimpleBroadphase::m_ownsPairCache
bool m_ownsPairCache
Definition: btSimpleBroadphase.h:93
btSimpleBroadphase::getSimpleProxyFromProxy
btSimpleBroadphaseProxy * getSimpleProxyFromProxy(btBroadphaseProxy *proxy)
Definition: btSimpleBroadphase.h:99
btAssert
#define btAssert(x)
Definition: btScalar.h:131
btSimpleBroadphase::aabbOverlap
static bool aabbOverlap(btSimpleBroadphaseProxy *proxy0, btSimpleBroadphaseProxy *proxy1)
Definition: btSimpleBroadphase.cpp:193
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:81
btSimpleBroadphase::m_LastHandleIndex
int m_LastHandleIndex
Definition: btSimpleBroadphase.h:56
btSimpleBroadphase::destroyProxy
virtual void destroyProxy(btBroadphaseProxy *proxy, btDispatcher *dispatcher)
Definition: btSimpleBroadphase.cpp:131
btSimpleBroadphaseProxy::SetNextFree
void SetNextFree(int next)
Definition: btSimpleBroadphase.h:39
btSimpleBroadphase::resetPool
virtual void resetPool(btDispatcher *dispatcher)
reset broadphase internal structures, to ensure determinism/reproducability
Definition: btSimpleBroadphase.cpp:346
btOverlappingPairCache.h
btOverlappingPairCache
The btOverlappingPairCache provides an interface for overlapping pair management (add, remove, storage), used by the btBroadphaseInterface broadphases.
Definition: btOverlappingPairCache.h:60
btSimpleBroadphase::getAabb
virtual void getAabb(btBroadphaseProxy *proxy, btVector3 &aabbMin, btVector3 &aabbMax) const
Definition: btSimpleBroadphase.cpp:143
btSimpleBroadphase::m_pairCache
btOverlappingPairCache * m_pairCache
Definition: btSimpleBroadphase.h:92
btSimpleBroadphase::getBroadphaseAabb
virtual void getBroadphaseAabb(btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb returns the axis aligned bounding box in the &#39;global&#39; coordinate frame will add some transfor...
Definition: btSimpleBroadphase.h:155
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
btSimpleBroadphaseProxy
Definition: btSimpleBroadphase.h:23
btBroadphaseRayCallback
Definition: btBroadphaseInterface.h:36
btBroadphaseProxy::m_clientObject
void * m_clientObject
Definition: btBroadphaseProxy.h:103
btSimpleBroadphase::~btSimpleBroadphase
virtual ~btSimpleBroadphase()
Definition: btSimpleBroadphase.cpp:75
btBroadphaseInterface
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs...
Definition: btBroadphaseInterface.h:55
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
btBroadphaseProxy
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
Definition: btBroadphaseProxy.h:85
btSimpleBroadphase::getSimpleProxyFromProxy
const btSimpleBroadphaseProxy * getSimpleProxyFromProxy(btBroadphaseProxy *proxy) const
Definition: btSimpleBroadphase.h:105
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btSimpleBroadphase::getOverlappingPairCache
const btOverlappingPairCache * getOverlappingPairCache() const
Definition: btSimpleBroadphase.h:145
btSimpleBroadphase::testAabbOverlap
bool testAabbOverlap(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1)
Definition: btSimpleBroadphase.cpp:339
btSimpleBroadphase::printStats
virtual void printStats()
Definition: btSimpleBroadphase.h:161
btSimpleBroadphase
The SimpleBroadphase is just a unit-test for btAxisSweep3, bt32BitAxisSweep3, or btDbvtBroadphase, so use those classes instead.
Definition: btSimpleBroadphase.h:49
btSimpleBroadphase::aabbTest
virtual void aabbTest(const btVector3 &aabbMin, const btVector3 &aabbMax, btBroadphaseAabbCallback &callback)
Definition: btSimpleBroadphase.cpp:171
btSimpleBroadphase::calculateOverlappingPairs
virtual void calculateOverlappingPairs(btDispatcher *dispatcher)
calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during th...
Definition: btSimpleBroadphase.cpp:213
btSimpleBroadphase::getOverlappingPairCache
btOverlappingPairCache * getOverlappingPairCache()
Definition: btSimpleBroadphase.h:141
btSimpleBroadphase::m_pHandlesRawPtr
void * m_pHandlesRawPtr
Definition: btSimpleBroadphase.h:60
btSimpleBroadphase::btSimpleBroadphase
btSimpleBroadphase(int maxProxies=16384, btOverlappingPairCache *overlappingPairCache=0)
Definition: btSimpleBroadphase.cpp:41
btSimpleBroadphase::validate
void validate()
Definition: btSimpleBroadphase.cpp:29
btSimpleBroadphase::setAabb
virtual void setAabb(btBroadphaseProxy *proxy, const btVector3 &aabbMin, const btVector3 &aabbMax, btDispatcher *dispatcher)
Definition: btSimpleBroadphase.cpp:150
btBroadphaseAabbCallback
Definition: btBroadphaseInterface.h:29
btSimpleBroadphase::m_numHandles
int m_numHandles
Definition: btSimpleBroadphase.h:54
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:75
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