2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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:
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.
16
#ifndef BT_SIMPLE_BROADPHASE_H
17
#define BT_SIMPLE_BROADPHASE_H
20
#include "btOverlappingPairCache.h"
23
struct btSimpleBroadphaseProxy : public btBroadphaseProxy
30
btSimpleBroadphaseProxy() {};
32
btSimpleBroadphaseProxy(const btVector3& minpt,const btVector3& maxpt,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,void* multiSapProxy)
33
:btBroadphaseProxy(minpt,maxpt,userPtr,collisionFilterGroup,collisionFilterMask,multiSapProxy)
39
SIMD_FORCE_INLINE void SetNextFree(int next) {m_nextFree = next;}
40
SIMD_FORCE_INLINE int GetNextFree() const {return m_nextFree;}
47
///The SimpleBroadphase is just a unit-test for btAxisSweep3, bt32BitAxisSweep3, or btDbvtBroadphase, so use those classes instead.
48
///It is a brute force aabb culling broadphase based on O(n^2) aabb checks
49
class btSimpleBroadphase : public btBroadphaseInterface
54
int m_numHandles; // number of active handles
55
int m_maxHandles; // max number of handles
56
int m_LastHandleIndex;
58
btSimpleBroadphaseProxy* m_pHandles; // handles pool
60
void* m_pHandlesRawPtr;
61
int m_firstFreeHandle; // free handles list
65
btAssert(m_numHandles < m_maxHandles);
66
int freeHandle = m_firstFreeHandle;
67
m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree();
69
if(freeHandle > m_LastHandleIndex)
71
m_LastHandleIndex = freeHandle;
76
void freeHandle(btSimpleBroadphaseProxy* proxy)
78
int handle = int(proxy-m_pHandles);
79
btAssert(handle >= 0 && handle < m_maxHandles);
80
if(handle == m_LastHandleIndex)
84
proxy->SetNextFree(m_firstFreeHandle);
85
m_firstFreeHandle = handle;
87
proxy->m_clientObject = 0;
92
btOverlappingPairCache* m_pairCache;
99
inline btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy)
101
btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy);
105
inline const btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy) const
107
const btSimpleBroadphaseProxy* proxy0 = static_cast<const btSimpleBroadphaseProxy*>(proxy);
111
///reset broadphase internal structures, to ensure determinism/reproducability
112
virtual void resetPool(btDispatcher* dispatcher);
123
btSimpleBroadphase(int maxProxies=16384,btOverlappingPairCache* overlappingPairCache=0);
124
virtual ~btSimpleBroadphase();
127
static bool aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1);
130
virtual btBroadphaseProxy* createProxy( const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy);
132
virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
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;
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);
141
btOverlappingPairCache* getOverlappingPairCache()
145
const btOverlappingPairCache* getOverlappingPairCache() const
150
bool testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
153
///getAabb returns the axis aligned bounding box in the 'global' coordinate frame
154
///will add some transform later
155
virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
157
aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
158
aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
161
virtual void printStats()
163
// printf("btSimpleBroadphase.h\n");
164
// printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles);
170
#endif //BT_SIMPLE_BROADPHASE_H