Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.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: 6.5 KB
RevLine 
[1963]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 BROADPHASE_PROXY_H
17#define BROADPHASE_PROXY_H
18
19#include "LinearMath/btScalar.h" //for SIMD_FORCE_INLINE
20#include "LinearMath/btVector3.h"
21#include "LinearMath/btAlignedAllocator.h"
22
23
24/// btDispatcher uses these types
25/// IMPORTANT NOTE:The types are ordered polyhedral, implicit convex and concave
26/// to facilitate type checking
27enum BroadphaseNativeTypes
28{
29        // polyhedral convex shapes
30        BOX_SHAPE_PROXYTYPE,
31        TRIANGLE_SHAPE_PROXYTYPE,
32        TETRAHEDRAL_SHAPE_PROXYTYPE,
33        CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE,
34        CONVEX_HULL_SHAPE_PROXYTYPE,
35        CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE,
36//implicit convex shapes
37IMPLICIT_CONVEX_SHAPES_START_HERE,
38        SPHERE_SHAPE_PROXYTYPE,
39        MULTI_SPHERE_SHAPE_PROXYTYPE,
40        CAPSULE_SHAPE_PROXYTYPE,
41        CONE_SHAPE_PROXYTYPE,
42        CONVEX_SHAPE_PROXYTYPE,
43        CYLINDER_SHAPE_PROXYTYPE,
44        UNIFORM_SCALING_SHAPE_PROXYTYPE,
45        MINKOWSKI_SUM_SHAPE_PROXYTYPE,
46        MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE,
47//concave shapes
48CONCAVE_SHAPES_START_HERE,
49        //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
50        TRIANGLE_MESH_SHAPE_PROXYTYPE,
51        SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE,
52        ///used for demo integration FAST/Swift collision library and Bullet
53        FAST_CONCAVE_MESH_PROXYTYPE,
54        //terrain
55        TERRAIN_SHAPE_PROXYTYPE,
56///Used for GIMPACT Trimesh integration
57        GIMPACT_SHAPE_PROXYTYPE,
58///Multimaterial mesh
59    MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE,
60       
61        EMPTY_SHAPE_PROXYTYPE,
62        STATIC_PLANE_PROXYTYPE,
63CONCAVE_SHAPES_END_HERE,
64
65        COMPOUND_SHAPE_PROXYTYPE,
66
67        SOFTBODY_SHAPE_PROXYTYPE,
68
69        INVALID_SHAPE_PROXYTYPE,
70
71        MAX_BROADPHASE_COLLISION_TYPES
72       
73};
74
75
76///The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
77///It stores collision shape type information, collision filter information and a client object, typically a btCollisionObject or btRigidBody.
78ATTRIBUTE_ALIGNED16(struct) btBroadphaseProxy
79{
80
81BT_DECLARE_ALIGNED_ALLOCATOR();
82       
83        ///optional filtering to cull potential collisions
84        enum CollisionFilterGroups
85        {
86                DefaultFilter = 1,
87                StaticFilter = 2,
88                KinematicFilter = 4,
89                DebrisFilter = 8,
90                        SensorTrigger = 16,
91                AllFilter = -1 //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
92        };
93
94        btVector3       m_aabbMin;
95        btVector3       m_aabbMax;
96
97        //Usually the client btCollisionObject or Rigidbody class
98        void*   m_clientObject;
99
100        short int m_collisionFilterGroup;
101        short int m_collisionFilterMask;
102
103        void*   m_multiSapParentProxy;         
104
105
106        int                     m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
107
108        SIMD_FORCE_INLINE int getUid() const
109        {
110                return m_uniqueId;
111        }
112
113        //used for memory pools
114        btBroadphaseProxy() :m_clientObject(0),m_multiSapParentProxy(0)
115        {
116        }
117
118        btBroadphaseProxy(const btVector3& aabbMin,const btVector3& aabbMax,void* userPtr,short int collisionFilterGroup, short int collisionFilterMask,void* multiSapParentProxy=0)
119                :m_aabbMin(aabbMin),
120                m_aabbMax(aabbMax),
121                m_clientObject(userPtr),
122                m_collisionFilterGroup(collisionFilterGroup),
123                m_collisionFilterMask(collisionFilterMask)
124        {
125                m_multiSapParentProxy = multiSapParentProxy;
126        }
127
128       
129
130        static SIMD_FORCE_INLINE bool isPolyhedral(int proxyType)
131        {
132                return (proxyType  < IMPLICIT_CONVEX_SHAPES_START_HERE);
133        }
134
135        static SIMD_FORCE_INLINE bool   isConvex(int proxyType)
136        {
137                return (proxyType < CONCAVE_SHAPES_START_HERE);
138        }
139
140        static SIMD_FORCE_INLINE bool   isConcave(int proxyType)
141        {
142                return ((proxyType > CONCAVE_SHAPES_START_HERE) &&
143                        (proxyType < CONCAVE_SHAPES_END_HERE));
144        }
145        static SIMD_FORCE_INLINE bool   isCompound(int proxyType)
146        {
147                return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
148        }
149        static SIMD_FORCE_INLINE bool isInfinite(int proxyType)
150        {
151                return (proxyType == STATIC_PLANE_PROXYTYPE);
152        }
153       
154}
155;
156
157class btCollisionAlgorithm;
158
159struct btBroadphaseProxy;
160
161
162
163///The btBroadphasePair class contains a pair of aabb-overlapping objects.
164///A btDispatcher can search a btCollisionAlgorithm that performs exact/narrowphase collision detection on the actual collision shapes.
165ATTRIBUTE_ALIGNED16(struct) btBroadphasePair
166{
167        btBroadphasePair ()
168                :
169        m_pProxy0(0),
170                m_pProxy1(0),
171                m_algorithm(0),
172                m_userInfo(0)
173        {
174        }
175
176BT_DECLARE_ALIGNED_ALLOCATOR();
177
178        btBroadphasePair(const btBroadphasePair& other)
179                :               m_pProxy0(other.m_pProxy0),
180                                m_pProxy1(other.m_pProxy1),
181                                m_algorithm(other.m_algorithm),
182                                m_userInfo(other.m_userInfo)
183        {
184        }
185        btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1)
186        {
187
188                //keep them sorted, so the std::set operations work
189                if (&proxy0 < &proxy1)
190        { 
191            m_pProxy0 = &proxy0; 
192            m_pProxy1 = &proxy1; 
193        }
194        else 
195        { 
196                        m_pProxy0 = &proxy1; 
197            m_pProxy1 = &proxy0; 
198        }
199
200                m_algorithm = 0;
201                m_userInfo = 0;
202
203        }
204       
205        btBroadphaseProxy* m_pProxy0;
206        btBroadphaseProxy* m_pProxy1;
207       
208        mutable btCollisionAlgorithm* m_algorithm;
209        mutable void* m_userInfo;
210
211};
212
213/*
214//comparison for set operation, see Solid DT_Encounter
215SIMD_FORCE_INLINE bool operator<(const btBroadphasePair& a, const btBroadphasePair& b)
216{
217    return a.m_pProxy0 < b.m_pProxy0 ||
218        (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 < b.m_pProxy1);
219}
220*/
221
222
223
224class btBroadphasePairSortPredicate
225{
226        public:
227
228                bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b )
229                {
230                         return a.m_pProxy0 > b.m_pProxy0 || 
231                                (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 > b.m_pProxy1) ||
232                                (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm); 
233                }
234};
235
236
237SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphasePair& b) 
238{
239         return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1);
240}
241
242
243#endif //BROADPHASE_PROXY_H
244
Note: See TracBrowser for help on using the repository browser.