Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h @ 3607

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

Update from Bullet 2.73 to 2.74.

  • Property svn:eol-style set to native
File size: 5.1 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
16#ifndef SIMPLE_BROADPHASE_H
17#define SIMPLE_BROADPHASE_H
18
19
20#include "btOverlappingPairCache.h"
21
22
23struct btSimpleBroadphaseProxy : public btBroadphaseProxy
24{
25        int                     m_nextFree;
26       
27//      int                     m_handleId;
28
29       
30        btSimpleBroadphaseProxy() {};
31
32        btSimpleBroadphaseProxy(const btVector3& minpt,const btVector3& maxpt,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,void* multiSapProxy)
33        :btBroadphaseProxy(minpt,maxpt,userPtr,collisionFilterGroup,collisionFilterMask,multiSapProxy)
34        {
35                (void)shapeType;
36        }
37       
38       
39        SIMD_FORCE_INLINE void SetNextFree(int next) {m_nextFree = next;}
40        SIMD_FORCE_INLINE int GetNextFree() const {return m_nextFree;}
41
42       
43
44
45};
46
47///The SimpleBroadphase is just a unit-test for btAxisSweep3, bt32BitAxisSweep3, or btDbvtBroadphase, so use those classes instead.
48///It is a brute force aabb culling broadphase based on O(n^2) aabb checks
49class btSimpleBroadphase : public btBroadphaseInterface
50{
51
52protected:
53
54        int             m_numHandles;                                           // number of active handles
55        int             m_maxHandles;                                           // max number of handles
56        int             m_LastHandleIndex;                                                     
57       
58        btSimpleBroadphaseProxy* m_pHandles;                                            // handles pool
59
60        void* m_pHandlesRawPtr;
61        int             m_firstFreeHandle;              // free handles list
62       
63        int allocHandle()
64        {
65                btAssert(m_numHandles < m_maxHandles);
66                int freeHandle = m_firstFreeHandle;
67                m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree();
68                m_numHandles++;
69                if(freeHandle > m_LastHandleIndex)
70                {
71                        m_LastHandleIndex = freeHandle;
72                }
73                return freeHandle;
74        }
75
76        void freeHandle(btSimpleBroadphaseProxy* proxy)
77        {
78                int handle = int(proxy-m_pHandles);
79                btAssert(handle >= 0 && handle < m_maxHandles);
80                if(handle == m_LastHandleIndex)
81                {
82                        m_LastHandleIndex--;
83                }
84                proxy->SetNextFree(m_firstFreeHandle);
85                m_firstFreeHandle = handle;
86
87                proxy->m_clientObject = 0;
88
89                m_numHandles--;
90        }
91
92        btOverlappingPairCache* m_pairCache;
93        bool    m_ownsPairCache;
94
95        int     m_invalidPair;
96
97       
98       
99        inline btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy)
100        {
101                btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy);
102                return proxy0;
103        }
104
105        inline const btSimpleBroadphaseProxy*   getSimpleProxyFromProxy(btBroadphaseProxy* proxy) const
106        {
107                const btSimpleBroadphaseProxy* proxy0 = static_cast<const btSimpleBroadphaseProxy*>(proxy);
108                return proxy0;
109        }
110
111        ///reset broadphase internal structures, to ensure determinism/reproducability
112        virtual void resetPool(btDispatcher* dispatcher);
113
114
115        void    validate();
116
117protected:
118
119
120       
121
122public:
123        btSimpleBroadphase(int maxProxies=16384,btOverlappingPairCache* overlappingPairCache=0);
124        virtual ~btSimpleBroadphase();
125
126
127                static bool     aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1);
128
129
130        virtual btBroadphaseProxy*      createProxy(  const btVector3& aabbMin,  const btVector3& aabbMax,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy);
131
132        virtual void    calculateOverlappingPairs(btDispatcher* dispatcher);
133
134        virtual void    destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
135        virtual void    setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher);
136        virtual void    getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
137
138        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));
139               
140        btOverlappingPairCache* getOverlappingPairCache()
141        {
142                return m_pairCache;
143        }
144        const btOverlappingPairCache*   getOverlappingPairCache() const
145        {
146                return m_pairCache;
147        }
148
149        bool    testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
150
151
152        ///getAabb returns the axis aligned bounding box in the 'global' coordinate frame
153        ///will add some transform later
154        virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
155        {
156                aabbMin.setValue(-1e30f,-1e30f,-1e30f);
157                aabbMax.setValue(1e30f,1e30f,1e30f);
158        }
159
160        virtual void    printStats()
161        {
162//              printf("btSimpleBroadphase.h\n");
163//              printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles);
164        }
165};
166
167
168
169#endif //SIMPLE_BROADPHASE_H
170
Note: See TracBrowser for help on using the repository browser.