2 Physics Effects Copyright(C) 2011 Sony Computer Entertainment Inc.
\r
5 Physics Effects is open software; you can redistribute it and/or
\r
6 modify it under the terms of the BSD License.
\r
8 Physics Effects is distributed in the hope that it will be useful,
\r
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\r
11 See the BSD License for more details.
\r
13 A copy of the BSD License is distributed with
\r
14 Physics Effects under the filename: physics_effects_license.txt
\r
17 ///btLowLevelBroadphase implementation
\r
18 #ifndef BT_LOW_LEVEL_BROADPHASE_H
\r
19 #define BT_LOW_LEVEL_BROADPHASE_H
\r
21 #include "BulletCollision/BroadphaseCollision/btDbvt.h"
\r
22 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
\r
24 #include "physics_effects/base_level/broadphase/pfx_broadphase_pair.h"
\r
25 #include "LinearMath/btHashMap.h"
\r
27 struct btLowLevelBroadphase;
\r
28 struct btLowLevelData;
\r
32 namespace PhysicsEffects
\r
34 struct PfxSortData32;
\r
38 struct btMyClientData
\r
40 btDispatcher* m_dispatcher;
\r
41 btLowLevelBroadphase* m_bp;
\r
44 struct btLowLevelBroadphaseProxy : public btBroadphaseProxy
\r
51 btLowLevelBroadphaseProxy() {};
\r
53 btLowLevelBroadphaseProxy(const btVector3& minpt,const btVector3& maxpt,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,void* multiSapProxy)
\r
54 :btBroadphaseProxy(minpt,maxpt,userPtr,collisionFilterGroup,collisionFilterMask,multiSapProxy)
\r
60 SIMD_FORCE_INLINE void SetNextFree(int next) {m_nextFree = next;}
\r
61 SIMD_FORCE_INLINE int GetNextFree() const {return m_nextFree;}
\r
68 ///btLowLevelBroadphase is a binding between Open Physics low-level broadphase and Bullet, through the btBroadphaseInterface
\r
70 struct btLowLevelBroadphase : btBroadphaseInterface
\r
73 int m_numHandles; // number of active handles
\r
74 int m_maxHandles; // max number of handles
\r
75 int m_LastHandleIndex;
\r
77 btLowLevelBroadphaseProxy* m_pHandles; // handles pool
\r
79 void* m_pHandlesRawPtr;
\r
80 int m_firstFreeHandle; // free handles list
\r
82 btOverlappingPairCache* m_paircache; // Pair cache
\r
83 bool m_releasepaircache; // Release pair cache on delete
\r
84 int m_guidGenerator;
\r
85 btVector3 m_broadphaseAabbMin;
\r
86 btVector3 m_broadphaseAabbMax;
\r
88 btMyClientData m_clientData;
\r
90 btLowLevelData* m_lowLevelData;
\r
91 btHashMap<btHashInt,void*> m_uid2ptr;
\r
96 btAssert(m_numHandles < m_maxHandles);
\r
97 int freeHandle = m_firstFreeHandle;
\r
98 m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree();
\r
100 if(freeHandle > m_LastHandleIndex)
\r
102 m_LastHandleIndex = freeHandle;
\r
107 void freeHandle(btLowLevelBroadphaseProxy* proxy)
\r
109 int handle = int(proxy-m_pHandles);
\r
110 btAssert(handle >= 0 && handle < m_maxHandles);
\r
111 if(handle == m_LastHandleIndex)
\r
113 m_LastHandleIndex--;
\r
115 proxy->SetNextFree(m_firstFreeHandle);
\r
116 m_firstFreeHandle = handle;
\r
118 proxy->m_clientObject = 0;
\r
123 inline btLowLevelBroadphaseProxy* getLowLevelProxyFromProxy(btBroadphaseProxy* proxy)
\r
125 btLowLevelBroadphaseProxy* proxy0 = static_cast<btLowLevelBroadphaseProxy*>(proxy);
\r
129 inline const btLowLevelBroadphaseProxy* getLowLevelProxyFromProxy(btBroadphaseProxy* proxy) const
\r
131 const btLowLevelBroadphaseProxy* proxy0 = static_cast<const btLowLevelBroadphaseProxy*>(proxy);
\r
137 inline bool testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
\r
139 btLowLevelBroadphaseProxy* p0 = getLowLevelProxyFromProxy(proxy0);
\r
140 btLowLevelBroadphaseProxy* p1 = getLowLevelProxyFromProxy(proxy1);
\r
141 return aabbOverlap(p0,p1);
\r
144 static bool aabbOverlap(btLowLevelBroadphaseProxy* proxy0,btLowLevelBroadphaseProxy* proxy1);
\r
146 void broadphase(sce::PhysicsEffects::PfxSortData32* proxies, int numRigidBodies, int axis, btDispatcher* dispatcher);
\r
148 sce::PhysicsEffects::PfxBroadphasePair* getCurrentPairs();
\r
149 const sce::PhysicsEffects::PfxBroadphasePair* getCurrentPairs() const;
\r
150 int getNumCurrentPairs() const;
\r
155 btLowLevelBroadphase(btLowLevelData* lowLevelData, btOverlappingPairCache* paircache, int maxProxies = 16384);//,class PfxAllocator* allocator,class PfxStackAllocator* stackPool,void* spursInstance);
\r
156 virtual ~btLowLevelBroadphase();
\r
158 /* btBroadphaseInterface Implementation */
\r
159 btBroadphaseProxy* createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy);
\r
160 void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
\r
161 void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
\r
162 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))
\r
166 virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback)
\r
171 virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
\r
172 void calculateOverlappingPairs(btDispatcher* dispatcher);
\r
173 btOverlappingPairCache* getOverlappingPairCache();
\r
174 const btOverlappingPairCache* getOverlappingPairCache() const;
\r
175 void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const;
\r
176 virtual void printStats();
\r
178 virtual void setNumTasks(int numTasks);
\r