Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef BT_SIMPLE_BROADPHASE_H
00017 #define BT_SIMPLE_BROADPHASE_H
00018
00019
00020 #include "btOverlappingPairCache.h"
00021
00022
00023 struct btSimpleBroadphaseProxy : public btBroadphaseProxy
00024 {
00025 int m_nextFree;
00026
00027
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;
00055 int m_maxHandles;
00056 int m_LastHandleIndex;
00057
00058 btSimpleBroadphaseProxy* m_pHandles;
00059
00060 void* m_pHandlesRawPtr;
00061 int m_firstFreeHandle;
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
00164
00165 }
00166 };
00167
00168
00169
00170 #endif //BT_SIMPLE_BROADPHASE_H
00171