Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.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.6 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 btPoint3& minpt,const btPoint3& 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       
57        btSimpleBroadphaseProxy* m_pHandles;                                            // handles pool
58
59        void* m_pHandlesRawPtr;
60        int             m_firstFreeHandle;              // free handles list
61       
62        int allocHandle()
63        {
64                btAssert(m_numHandles < m_maxHandles);
65                int freeHandle = m_firstFreeHandle;
66                m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree();
67                m_numHandles++;
68                return freeHandle;
69        }
70
71        void freeHandle(btSimpleBroadphaseProxy* proxy)
72        {
73                int handle = int(proxy-m_pHandles);
74                btAssert(handle >= 0 && handle < m_maxHandles);
75
76                proxy->SetNextFree(m_firstFreeHandle);
77                m_firstFreeHandle = handle;
78
79                m_numHandles--;
80        }
81
82        btOverlappingPairCache* m_pairCache;
83        bool    m_ownsPairCache;
84
85        int     m_invalidPair;
86
87       
88       
89        inline btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy)
90        {
91                btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy);
92                return proxy0;
93        }
94
95        inline const btSimpleBroadphaseProxy*   getSimpleProxyFromProxy(btBroadphaseProxy* proxy) const
96        {
97                const btSimpleBroadphaseProxy* proxy0 = static_cast<const btSimpleBroadphaseProxy*>(proxy);
98                return proxy0;
99        }
100
101
102        void    validate();
103
104protected:
105
106
107       
108
109public:
110        btSimpleBroadphase(int maxProxies=16384,btOverlappingPairCache* overlappingPairCache=0);
111        virtual ~btSimpleBroadphase();
112
113
114                static bool     aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1);
115
116
117        virtual btBroadphaseProxy*      createProxy(  const btVector3& aabbMin,  const btVector3& aabbMax,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy);
118
119        virtual void    calculateOverlappingPairs(btDispatcher* dispatcher);
120
121        virtual void    destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
122        virtual void    setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher);
123        virtual void    getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
124
125        virtual void    rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
126               
127        btOverlappingPairCache* getOverlappingPairCache()
128        {
129                return m_pairCache;
130        }
131        const btOverlappingPairCache*   getOverlappingPairCache() const
132        {
133                return m_pairCache;
134        }
135
136        bool    testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
137
138
139        ///getAabb returns the axis aligned bounding box in the 'global' coordinate frame
140        ///will add some transform later
141        virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
142        {
143                aabbMin.setValue(-1e30f,-1e30f,-1e30f);
144                aabbMax.setValue(1e30f,1e30f,1e30f);
145        }
146
147        virtual void    printStats()
148        {
149//              printf("btSimpleBroadphase.h\n");
150//              printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles);
151        }
152};
153
154
155
156#endif //SIMPLE_BROADPHASE_H
157
Note: See TracBrowser for help on using the repository browser.