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 | #ifndef BT_MULTI_SAP_BROADPHASE |
---|
16 | #define BT_MULTI_SAP_BROADPHASE |
---|
17 | |
---|
18 | #include "btBroadphaseInterface.h" |
---|
19 | #include "LinearMath/btAlignedObjectArray.h" |
---|
20 | #include "btOverlappingPairCache.h" |
---|
21 | |
---|
22 | |
---|
23 | class btBroadphaseInterface; |
---|
24 | class btSimpleBroadphase; |
---|
25 | |
---|
26 | |
---|
27 | typedef btAlignedObjectArray<btBroadphaseInterface*> btSapBroadphaseArray; |
---|
28 | |
---|
29 | ///The btMultiSapBroadphase is a broadphase that contains multiple SAP broadphases. |
---|
30 | ///The user can add SAP broadphases that cover the world. A btBroadphaseProxy can be in multiple child broadphases at the same time. |
---|
31 | ///A btQuantizedBvh acceleration structures finds overlapping SAPs for each btBroadphaseProxy. |
---|
32 | ///See http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=328 |
---|
33 | ///and http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1329 |
---|
34 | class btMultiSapBroadphase :public btBroadphaseInterface |
---|
35 | { |
---|
36 | btSapBroadphaseArray m_sapBroadphases; |
---|
37 | |
---|
38 | btSimpleBroadphase* m_simpleBroadphase; |
---|
39 | |
---|
40 | btOverlappingPairCache* m_overlappingPairs; |
---|
41 | |
---|
42 | class btQuantizedBvh* m_optimizedAabbTree; |
---|
43 | |
---|
44 | |
---|
45 | bool m_ownsPairCache; |
---|
46 | |
---|
47 | btOverlapFilterCallback* m_filterCallback; |
---|
48 | |
---|
49 | int m_invalidPair; |
---|
50 | |
---|
51 | struct btBridgeProxy |
---|
52 | { |
---|
53 | btBroadphaseProxy* m_childProxy; |
---|
54 | btBroadphaseInterface* m_childBroadphase; |
---|
55 | }; |
---|
56 | |
---|
57 | |
---|
58 | public: |
---|
59 | |
---|
60 | struct btMultiSapProxy : public btBroadphaseProxy |
---|
61 | { |
---|
62 | |
---|
63 | ///array with all the entries that this proxy belongs to |
---|
64 | btAlignedObjectArray<btBridgeProxy*> m_bridgeProxies; |
---|
65 | btVector3 m_aabbMin; |
---|
66 | btVector3 m_aabbMax; |
---|
67 | |
---|
68 | int m_shapeType; |
---|
69 | |
---|
70 | /* void* m_userPtr; |
---|
71 | short int m_collisionFilterGroup; |
---|
72 | short int m_collisionFilterMask; |
---|
73 | */ |
---|
74 | btMultiSapProxy(const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr, short int collisionFilterGroup,short int collisionFilterMask) |
---|
75 | :btBroadphaseProxy(userPtr,collisionFilterGroup,collisionFilterMask), |
---|
76 | m_aabbMin(aabbMin), |
---|
77 | m_aabbMax(aabbMax), |
---|
78 | m_shapeType(shapeType) |
---|
79 | { |
---|
80 | m_multiSapParentProxy =this; |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | }; |
---|
85 | |
---|
86 | protected: |
---|
87 | |
---|
88 | |
---|
89 | btAlignedObjectArray<btMultiSapProxy*> m_multiSapProxies; |
---|
90 | |
---|
91 | public: |
---|
92 | |
---|
93 | btMultiSapBroadphase(int maxProxies = 16384,btOverlappingPairCache* pairCache=0); |
---|
94 | |
---|
95 | |
---|
96 | btSapBroadphaseArray& getBroadphaseArray() |
---|
97 | { |
---|
98 | return m_sapBroadphases; |
---|
99 | } |
---|
100 | |
---|
101 | const btSapBroadphaseArray& getBroadphaseArray() const |
---|
102 | { |
---|
103 | return m_sapBroadphases; |
---|
104 | } |
---|
105 | |
---|
106 | virtual ~btMultiSapBroadphase(); |
---|
107 | |
---|
108 | virtual btBroadphaseProxy* createProxy( const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr, short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy); |
---|
109 | virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher); |
---|
110 | virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher); |
---|
111 | |
---|
112 | void addToChildBroadphase(btMultiSapProxy* parentMultiSapProxy, btBroadphaseProxy* childProxy, btBroadphaseInterface* childBroadphase); |
---|
113 | |
---|
114 | ///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb |
---|
115 | virtual void calculateOverlappingPairs(btDispatcher* dispatcher); |
---|
116 | |
---|
117 | bool testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1); |
---|
118 | |
---|
119 | virtual btOverlappingPairCache* getOverlappingPairCache() |
---|
120 | { |
---|
121 | return m_overlappingPairs; |
---|
122 | } |
---|
123 | virtual const btOverlappingPairCache* getOverlappingPairCache() const |
---|
124 | { |
---|
125 | return m_overlappingPairs; |
---|
126 | } |
---|
127 | |
---|
128 | ///getAabb returns the axis aligned bounding box in the 'global' coordinate frame |
---|
129 | ///will add some transform later |
---|
130 | virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const |
---|
131 | { |
---|
132 | aabbMin.setValue(-1e30f,-1e30f,-1e30f); |
---|
133 | aabbMax.setValue(1e30f,1e30f,1e30f); |
---|
134 | } |
---|
135 | |
---|
136 | void buildTree(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax); |
---|
137 | |
---|
138 | virtual void printStats(); |
---|
139 | |
---|
140 | void quicksort (btBroadphasePairArray& a, int lo, int hi); |
---|
141 | |
---|
142 | }; |
---|
143 | |
---|
144 | #endif //BT_MULTI_SAP_BROADPHASE |
---|