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.
15 #ifndef BT_MULTI_SAP_BROADPHASE
16 #define BT_MULTI_SAP_BROADPHASE
18 #include "btBroadphaseInterface.h"
19 #include "LinearMath/btAlignedObjectArray.h"
20 #include "btOverlappingPairCache.h"
23 class btBroadphaseInterface;
24 class btSimpleBroadphase;
27 typedef btAlignedObjectArray<btBroadphaseInterface*> btSapBroadphaseArray;
29 ///The btMultiSapBroadphase is a research project, not recommended to use in production. Use btAxisSweep3 or btDbvtBroadphase instead.
30 ///The btMultiSapBroadphase is a broadphase that contains multiple SAP broadphases.
31 ///The user can add SAP broadphases that cover the world. A btBroadphaseProxy can be in multiple child broadphases at the same time.
32 ///A btQuantizedBvh acceleration structures finds overlapping SAPs for each btBroadphaseProxy.
33 ///See http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=328
34 ///and http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1329
35 class btMultiSapBroadphase :public btBroadphaseInterface
37 btSapBroadphaseArray m_sapBroadphases;
39 btSimpleBroadphase* m_simpleBroadphase;
41 btOverlappingPairCache* m_overlappingPairs;
43 class btQuantizedBvh* m_optimizedAabbTree;
48 btOverlapFilterCallback* m_filterCallback;
54 btBroadphaseProxy* m_childProxy;
55 btBroadphaseInterface* m_childBroadphase;
61 struct btMultiSapProxy : public btBroadphaseProxy
64 ///array with all the entries that this proxy belongs to
65 btAlignedObjectArray<btBridgeProxy*> m_bridgeProxies;
72 short int m_collisionFilterGroup;
73 short int m_collisionFilterMask;
75 btMultiSapProxy(const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr, short int collisionFilterGroup,short int collisionFilterMask)
76 :btBroadphaseProxy(aabbMin,aabbMax,userPtr,collisionFilterGroup,collisionFilterMask),
79 m_shapeType(shapeType)
81 m_multiSapParentProxy =this;
90 btAlignedObjectArray<btMultiSapProxy*> m_multiSapProxies;
94 btMultiSapBroadphase(int maxProxies = 16384,btOverlappingPairCache* pairCache=0);
97 btSapBroadphaseArray& getBroadphaseArray()
99 return m_sapBroadphases;
102 const btSapBroadphaseArray& getBroadphaseArray() const
104 return m_sapBroadphases;
107 virtual ~btMultiSapBroadphase();
109 virtual btBroadphaseProxy* createProxy( const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr, short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy);
110 virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
111 virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher);
112 virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
114 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));
116 void addToChildBroadphase(btMultiSapProxy* parentMultiSapProxy, btBroadphaseProxy* childProxy, btBroadphaseInterface* childBroadphase);
118 ///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
119 virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
121 bool testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
123 virtual btOverlappingPairCache* getOverlappingPairCache()
125 return m_overlappingPairs;
127 virtual const btOverlappingPairCache* getOverlappingPairCache() const
129 return m_overlappingPairs;
132 ///getAabb returns the axis aligned bounding box in the 'global' coordinate frame
133 ///will add some transform later
134 virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
136 aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
137 aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
140 void buildTree(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax);
142 virtual void printStats();
144 void quicksort (btBroadphasePairArray& a, int lo, int hi);
146 ///reset broadphase internal structures, to ensure determinism/reproducability
147 virtual void resetPool(btDispatcher* dispatcher);
151 #endif //BT_MULTI_SAP_BROADPHASE