Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weaponsystem/src/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h @ 3015

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

Merged presentation branch back to trunk.

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