Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h @ 1963

Last change on this file since 1963 was 1963, checked in by rgrieder, 16 years ago

Added Bullet physics engine.

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. 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
23class btBroadphaseInterface;
24class btSimpleBroadphase;
25
26
27typedef 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
34class 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
58public:
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(aabbMin,aabbMax,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
86protected:
87
88
89        btAlignedObjectArray<btMultiSapProxy*> m_multiSapProxies;
90
91public:
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        virtual void    getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
112
113        virtual void    rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
114
115        void    addToChildBroadphase(btMultiSapProxy* parentMultiSapProxy, btBroadphaseProxy* childProxy, btBroadphaseInterface*        childBroadphase);
116
117        ///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
118        virtual void    calculateOverlappingPairs(btDispatcher* dispatcher);
119
120        bool    testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
121
122        virtual btOverlappingPairCache* getOverlappingPairCache()
123        {
124                return m_overlappingPairs;
125        }
126        virtual const btOverlappingPairCache*   getOverlappingPairCache() const
127        {
128                return m_overlappingPairs;
129        }
130
131        ///getAabb returns the axis aligned bounding box in the 'global' coordinate frame
132        ///will add some transform later
133        virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
134        {
135                aabbMin.setValue(-1e30f,-1e30f,-1e30f);
136                aabbMax.setValue(1e30f,1e30f,1e30f);
137        }
138
139        void    buildTree(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax);
140
141        virtual void    printStats();
142
143        void quicksort (btBroadphasePairArray& a, int lo, int hi);
144
145};
146
147#endif //BT_MULTI_SAP_BROADPHASE
Note: See TracBrowser for help on using the repository browser.