Blender V2.61 - r43446
|
00001 /* 00002 Bullet Continuous Collision Detection and Physics Library 00003 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ 00004 00005 This software is provided 'as-is', without any express or implied warranty. 00006 In no event will the authors be held liable for any damages arising from the use of this software. 00007 Permission is granted to anyone to use this software for any purpose, 00008 including commercial applications, and to alter it and redistribute it freely, 00009 subject to the following restrictions: 00010 00011 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. 00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 00013 3. This notice may not be removed or altered from any source distribution. 00014 */ 00015 00016 #ifndef SIMPLE_BROADPHASE_H 00017 #define SIMPLE_BROADPHASE_H 00018 00019 00020 #include "btOverlappingPairCache.h" 00021 00022 00023 struct btSimpleBroadphaseProxy : public btBroadphaseProxy 00024 { 00025 int m_nextFree; 00026 00027 // int m_handleId; 00028 00029 00030 btSimpleBroadphaseProxy() {}; 00031 00032 btSimpleBroadphaseProxy(const btVector3& minpt,const btVector3& maxpt,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,void* multiSapProxy) 00033 :btBroadphaseProxy(minpt,maxpt,userPtr,collisionFilterGroup,collisionFilterMask,multiSapProxy) 00034 { 00035 (void)shapeType; 00036 } 00037 00038 00039 SIMD_FORCE_INLINE void SetNextFree(int next) {m_nextFree = next;} 00040 SIMD_FORCE_INLINE int GetNextFree() const {return m_nextFree;} 00041 00042 00043 00044 00045 }; 00046 00049 class btSimpleBroadphase : public btBroadphaseInterface 00050 { 00051 00052 protected: 00053 00054 int m_numHandles; // number of active handles 00055 int m_maxHandles; // max number of handles 00056 int m_LastHandleIndex; 00057 00058 btSimpleBroadphaseProxy* m_pHandles; // handles pool 00059 00060 void* m_pHandlesRawPtr; 00061 int m_firstFreeHandle; // free handles list 00062 00063 int allocHandle() 00064 { 00065 btAssert(m_numHandles < m_maxHandles); 00066 int freeHandle = m_firstFreeHandle; 00067 m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree(); 00068 m_numHandles++; 00069 if(freeHandle > m_LastHandleIndex) 00070 { 00071 m_LastHandleIndex = freeHandle; 00072 } 00073 return freeHandle; 00074 } 00075 00076 void freeHandle(btSimpleBroadphaseProxy* proxy) 00077 { 00078 int handle = int(proxy-m_pHandles); 00079 btAssert(handle >= 0 && handle < m_maxHandles); 00080 if(handle == m_LastHandleIndex) 00081 { 00082 m_LastHandleIndex--; 00083 } 00084 proxy->SetNextFree(m_firstFreeHandle); 00085 m_firstFreeHandle = handle; 00086 00087 proxy->m_clientObject = 0; 00088 00089 m_numHandles--; 00090 } 00091 00092 btOverlappingPairCache* m_pairCache; 00093 bool m_ownsPairCache; 00094 00095 int m_invalidPair; 00096 00097 00098 00099 inline btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy) 00100 { 00101 btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy); 00102 return proxy0; 00103 } 00104 00105 inline const btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy) const 00106 { 00107 const btSimpleBroadphaseProxy* proxy0 = static_cast<const btSimpleBroadphaseProxy*>(proxy); 00108 return proxy0; 00109 } 00110 00112 virtual void resetPool(btDispatcher* dispatcher); 00113 00114 00115 void validate(); 00116 00117 protected: 00118 00119 00120 00121 00122 public: 00123 btSimpleBroadphase(int maxProxies=16384,btOverlappingPairCache* overlappingPairCache=0); 00124 virtual ~btSimpleBroadphase(); 00125 00126 00127 static bool aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1); 00128 00129 00130 virtual btBroadphaseProxy* createProxy( const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy); 00131 00132 virtual void calculateOverlappingPairs(btDispatcher* dispatcher); 00133 00134 virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher); 00135 virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher); 00136 virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const; 00137 00138 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)); 00139 virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback); 00140 00141 btOverlappingPairCache* getOverlappingPairCache() 00142 { 00143 return m_pairCache; 00144 } 00145 const btOverlappingPairCache* getOverlappingPairCache() const 00146 { 00147 return m_pairCache; 00148 } 00149 00150 bool testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1); 00151 00152 00155 virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const 00156 { 00157 aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT); 00158 aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT); 00159 } 00160 00161 virtual void printStats() 00162 { 00163 // printf("btSimpleBroadphase.h\n"); 00164 // printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles); 00165 } 00166 }; 00167 00168 00169 00170 #endif //SIMPLE_BROADPHASE_H 00171