[1963] | 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 SIMPLE_BROADPHASE_H |
---|
| 17 | #define SIMPLE_BROADPHASE_H |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | #include "btOverlappingPairCache.h" |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | struct btSimpleBroadphaseProxy : public btBroadphaseProxy |
---|
| 24 | { |
---|
[1972] | 25 | btVector3 m_min; |
---|
| 26 | btVector3 m_max; |
---|
[1963] | 27 | int m_nextFree; |
---|
| 28 | |
---|
| 29 | // int m_handleId; |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | btSimpleBroadphaseProxy() {}; |
---|
| 33 | |
---|
| 34 | btSimpleBroadphaseProxy(const btPoint3& minpt,const btPoint3& maxpt,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,void* multiSapProxy) |
---|
[1972] | 35 | :btBroadphaseProxy(userPtr,collisionFilterGroup,collisionFilterMask,multiSapProxy), |
---|
| 36 | m_min(minpt),m_max(maxpt) |
---|
[1963] | 37 | { |
---|
| 38 | (void)shapeType; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | SIMD_FORCE_INLINE void SetNextFree(int next) {m_nextFree = next;} |
---|
| 43 | SIMD_FORCE_INLINE int GetNextFree() const {return m_nextFree;} |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | }; |
---|
| 49 | |
---|
| 50 | ///The SimpleBroadphase is just a unit-test for btAxisSweep3, bt32BitAxisSweep3, or btDbvtBroadphase, so use those classes instead. |
---|
| 51 | ///It is a brute force aabb culling broadphase based on O(n^2) aabb checks |
---|
| 52 | class btSimpleBroadphase : public btBroadphaseInterface |
---|
| 53 | { |
---|
| 54 | |
---|
| 55 | protected: |
---|
| 56 | |
---|
| 57 | int m_numHandles; // number of active handles |
---|
| 58 | int m_maxHandles; // max number of handles |
---|
| 59 | |
---|
| 60 | btSimpleBroadphaseProxy* m_pHandles; // handles pool |
---|
| 61 | |
---|
| 62 | void* m_pHandlesRawPtr; |
---|
| 63 | int m_firstFreeHandle; // free handles list |
---|
| 64 | |
---|
| 65 | int allocHandle() |
---|
| 66 | { |
---|
| 67 | btAssert(m_numHandles < m_maxHandles); |
---|
| 68 | int freeHandle = m_firstFreeHandle; |
---|
| 69 | m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree(); |
---|
| 70 | m_numHandles++; |
---|
| 71 | return freeHandle; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | void freeHandle(btSimpleBroadphaseProxy* proxy) |
---|
| 75 | { |
---|
| 76 | int handle = int(proxy-m_pHandles); |
---|
| 77 | btAssert(handle >= 0 && handle < m_maxHandles); |
---|
| 78 | |
---|
| 79 | proxy->SetNextFree(m_firstFreeHandle); |
---|
| 80 | m_firstFreeHandle = handle; |
---|
| 81 | |
---|
| 82 | m_numHandles--; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | btOverlappingPairCache* m_pairCache; |
---|
| 86 | bool m_ownsPairCache; |
---|
| 87 | |
---|
| 88 | int m_invalidPair; |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | inline btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy) |
---|
| 93 | { |
---|
| 94 | btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy); |
---|
| 95 | return proxy0; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | void validate(); |
---|
| 100 | |
---|
| 101 | protected: |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | public: |
---|
| 107 | btSimpleBroadphase(int maxProxies=16384,btOverlappingPairCache* overlappingPairCache=0); |
---|
| 108 | virtual ~btSimpleBroadphase(); |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | static bool aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1); |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | virtual btBroadphaseProxy* createProxy( const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy); |
---|
| 115 | |
---|
| 116 | virtual void calculateOverlappingPairs(btDispatcher* dispatcher); |
---|
| 117 | |
---|
| 118 | virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher); |
---|
| 119 | virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher); |
---|
| 120 | |
---|
| 121 | btOverlappingPairCache* getOverlappingPairCache() |
---|
| 122 | { |
---|
| 123 | return m_pairCache; |
---|
| 124 | } |
---|
| 125 | const btOverlappingPairCache* getOverlappingPairCache() const |
---|
| 126 | { |
---|
| 127 | return m_pairCache; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | bool testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1); |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | ///getAabb returns the axis aligned bounding box in the 'global' coordinate frame |
---|
| 134 | ///will add some transform later |
---|
| 135 | virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const |
---|
| 136 | { |
---|
| 137 | aabbMin.setValue(-1e30f,-1e30f,-1e30f); |
---|
| 138 | aabbMax.setValue(1e30f,1e30f,1e30f); |
---|
| 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 | |
---|
| 149 | |
---|
| 150 | #endif //SIMPLE_BROADPHASE_H |
---|
| 151 | |
---|