Bullet Collision Detection & Physics Library: btBroadphaseProxy.h Source File

Bullet Collision Detection & Physics Library

btBroadphaseProxy.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
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 BT_BROADPHASE_PROXY_H
17#define BT_BROADPHASE_PROXY_H
18
19#include "LinearMath/btScalar.h" //for SIMD_FORCE_INLINE
20#include "LinearMath/btVector3.h"
21#include "LinearMath/btAlignedAllocator.h"
22
27 enum 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 CUSTOM_POLYHEDRAL_SHAPE_TYPE,
37 //implicit convex shapes
38 IMPLICIT_CONVEX_SHAPES_START_HERE,
39 SPHERE_SHAPE_PROXYTYPE,
40 MULTI_SPHERE_SHAPE_PROXYTYPE,
41 CAPSULE_SHAPE_PROXYTYPE,
42 CONE_SHAPE_PROXYTYPE,
43 CONVEX_SHAPE_PROXYTYPE,
44 CYLINDER_SHAPE_PROXYTYPE,
45 UNIFORM_SCALING_SHAPE_PROXYTYPE,
46 MINKOWSKI_SUM_SHAPE_PROXYTYPE,
47 MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE,
48 BOX_2D_SHAPE_PROXYTYPE,
49 CONVEX_2D_SHAPE_PROXYTYPE,
50 CUSTOM_CONVEX_SHAPE_TYPE,
51 //concave shapes
52 CONCAVE_SHAPES_START_HERE,
53 //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
54 TRIANGLE_MESH_SHAPE_PROXYTYPE,
55 SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE,
57 FAST_CONCAVE_MESH_PROXYTYPE,
58 //terrain
59 TERRAIN_SHAPE_PROXYTYPE,
61 GIMPACT_SHAPE_PROXYTYPE,
63 MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE,
64
65 EMPTY_SHAPE_PROXYTYPE,
66 STATIC_PLANE_PROXYTYPE,
67 CUSTOM_CONCAVE_SHAPE_TYPE,
68 SDF_SHAPE_PROXYTYPE = CUSTOM_CONCAVE_SHAPE_TYPE,
69 CONCAVE_SHAPES_END_HERE,
70
71 COMPOUND_SHAPE_PROXYTYPE,
72
73 SOFTBODY_SHAPE_PROXYTYPE,
74 HFFLUID_SHAPE_PROXYTYPE,
75 HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE,
76 INVALID_SHAPE_PROXYTYPE,
77
78 MAX_BROADPHASE_COLLISION_TYPES
79
80};
81
84 ATTRIBUTE_ALIGNED16(struct)
85 btBroadphaseProxy
86{
87 BT_DECLARE_ALIGNED_ALLOCATOR();
88
90 enum CollisionFilterGroups
91 {
92 DefaultFilter = 1,
93 StaticFilter = 2,
94 KinematicFilter = 4,
95 DebrisFilter = 8,
96 SensorTrigger = 16,
97 CharacterFilter = 32,
98 AllFilter = -1 //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
99 };
100
101 //Usually the client btCollisionObject or Rigidbody class
102 void* m_clientObject;
103 int m_collisionFilterGroup;
104 int m_collisionFilterMask;
105
106 int m_uniqueId; //m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
107
108 btVector3 m_aabbMin;
109 btVector3 m_aabbMax;
110
111 SIMD_FORCE_INLINE int getUid() const
112 {
113 return m_uniqueId;
114 }
115
116 //used for memory pools
117 btBroadphaseProxy() : m_clientObject(0)
118 {
119 }
120
121 btBroadphaseProxy(const btVector3& aabbMin, const btVector3& aabbMax, void* userPtr, int collisionFilterGroup, int collisionFilterMask)
122 : m_clientObject(userPtr),
123 m_collisionFilterGroup(collisionFilterGroup),
124 m_collisionFilterMask(collisionFilterMask),
125 m_aabbMin(aabbMin),
126 m_aabbMax(aabbMax)
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 isNonMoving(int proxyType)
141 {
142 return (isConcave(proxyType) && !(proxyType == GIMPACT_SHAPE_PROXYTYPE));
143 }
144
145 static SIMD_FORCE_INLINE bool isConcave(int proxyType)
146 {
147 return ((proxyType > CONCAVE_SHAPES_START_HERE) &&
148 (proxyType < CONCAVE_SHAPES_END_HERE));
149 }
150 static SIMD_FORCE_INLINE bool isCompound(int proxyType)
151 {
152 return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
153 }
154
155 static SIMD_FORCE_INLINE bool isSoftBody(int proxyType)
156 {
157 return (proxyType == SOFTBODY_SHAPE_PROXYTYPE);
158 }
159
160 static SIMD_FORCE_INLINE bool isInfinite(int proxyType)
161 {
162 return (proxyType == STATIC_PLANE_PROXYTYPE);
163 }
164
165 static SIMD_FORCE_INLINE bool isConvex2d(int proxyType)
166 {
167 return (proxyType == BOX_2D_SHAPE_PROXYTYPE) || (proxyType == CONVEX_2D_SHAPE_PROXYTYPE);
168 }
169};
170
171class btCollisionAlgorithm;
172
173struct btBroadphaseProxy;
174
177 ATTRIBUTE_ALIGNED16(struct)
178 btBroadphasePair
179{
180 btBroadphasePair()
181 : m_pProxy0(0),
182 m_pProxy1(0),
183 m_algorithm(0),
184 m_internalInfo1(0)
185 {
186 }
187
188 BT_DECLARE_ALIGNED_ALLOCATOR();
189
190 btBroadphasePair(btBroadphaseProxy & proxy0, btBroadphaseProxy & proxy1)
191 {
192 //keep them sorted, so the std::set operations work
193 if (proxy0.m_uniqueId < proxy1.m_uniqueId)
194 {
195 m_pProxy0 = &proxy0;
196 m_pProxy1 = &proxy1;
197 }
198 else
199 {
200 m_pProxy0 = &proxy1;
201 m_pProxy1 = &proxy0;
202 }
203
204 m_algorithm = 0;
205 m_internalInfo1 = 0;
206 }
207
208 btBroadphaseProxy* m_pProxy0;
209 btBroadphaseProxy* m_pProxy1;
210
211 mutable btCollisionAlgorithm* m_algorithm;
212 union {
213 void* m_internalInfo1;
214 int m_internalTmpValue;
215 }; //don't use this data, it will be removed in future version.
216};
217
218/*
219//comparison for set operation, see Solid DT_Encounter
220SIMD_FORCE_INLINE bool operator<(const btBroadphasePair& a, const btBroadphasePair& b)
221{
222 return a.m_pProxy0 < b.m_pProxy0 ||
223 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 < b.m_pProxy1);
224}
225*/
226
227 class btBroadphasePairSortPredicate
228{
229public:
230 bool operator()(const btBroadphasePair& a, const btBroadphasePair& b) const
231 {
232 const int uidA0 = a.m_pProxy0 ? a.m_pProxy0->m_uniqueId : -1;
233 const int uidB0 = b.m_pProxy0 ? b.m_pProxy0->m_uniqueId : -1;
234 const int uidA1 = a.m_pProxy1 ? a.m_pProxy1->m_uniqueId : -1;
235 const int uidB1 = b.m_pProxy1 ? b.m_pProxy1->m_uniqueId : -1;
236
237 return uidA0 > uidB0 ||
238 (a.m_pProxy0 == b.m_pProxy0 && uidA1 > uidB1) ||
239 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm);
240 }
241};
242
243 SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphasePair& b)
244{
245 return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1);
246}
247
248#endif //BT_BROADPHASE_PROXY_H
btAlignedAllocator.h
BroadphaseNativeTypes
BroadphaseNativeTypes
btDispatcher uses these types IMPORTANT NOTE:The types are ordered polyhedral, implicit convex and co...
Definition btBroadphaseProxy.h:28
CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE
@ CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:35
MINKOWSKI_SUM_SHAPE_PROXYTYPE
@ MINKOWSKI_SUM_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:46
CUSTOM_POLYHEDRAL_SHAPE_TYPE
@ CUSTOM_POLYHEDRAL_SHAPE_TYPE
Definition btBroadphaseProxy.h:36
CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE
@ CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:33
COMPOUND_SHAPE_PROXYTYPE
@ COMPOUND_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:71
CONCAVE_SHAPES_START_HERE
@ CONCAVE_SHAPES_START_HERE
Definition btBroadphaseProxy.h:52
IMPLICIT_CONVEX_SHAPES_START_HERE
@ IMPLICIT_CONVEX_SHAPES_START_HERE
Definition btBroadphaseProxy.h:38
HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE
@ HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:75
GIMPACT_SHAPE_PROXYTYPE
@ GIMPACT_SHAPE_PROXYTYPE
Used for GIMPACT Trimesh integration.
Definition btBroadphaseProxy.h:61
SOFTBODY_SHAPE_PROXYTYPE
@ SOFTBODY_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:73
CONVEX_2D_SHAPE_PROXYTYPE
@ CONVEX_2D_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:49
SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE
@ SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:55
TRIANGLE_SHAPE_PROXYTYPE
@ TRIANGLE_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:31
TRIANGLE_MESH_SHAPE_PROXYTYPE
@ TRIANGLE_MESH_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:54
CONVEX_SHAPE_PROXYTYPE
@ CONVEX_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:43
TERRAIN_SHAPE_PROXYTYPE
@ TERRAIN_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:59
MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE
@ MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE
Multimaterial mesh.
Definition btBroadphaseProxy.h:63
STATIC_PLANE_PROXYTYPE
@ STATIC_PLANE_PROXYTYPE
Definition btBroadphaseProxy.h:66
CUSTOM_CONCAVE_SHAPE_TYPE
@ CUSTOM_CONCAVE_SHAPE_TYPE
Definition btBroadphaseProxy.h:67
SDF_SHAPE_PROXYTYPE
@ SDF_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:68
INVALID_SHAPE_PROXYTYPE
@ INVALID_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:76
UNIFORM_SCALING_SHAPE_PROXYTYPE
@ UNIFORM_SCALING_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:45
MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE
@ MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:47
CUSTOM_CONVEX_SHAPE_TYPE
@ CUSTOM_CONVEX_SHAPE_TYPE
Definition btBroadphaseProxy.h:50
SPHERE_SHAPE_PROXYTYPE
@ SPHERE_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:39
BOX_SHAPE_PROXYTYPE
@ BOX_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:30
MULTI_SPHERE_SHAPE_PROXYTYPE
@ MULTI_SPHERE_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:40
CYLINDER_SHAPE_PROXYTYPE
@ CYLINDER_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:44
FAST_CONCAVE_MESH_PROXYTYPE
@ FAST_CONCAVE_MESH_PROXYTYPE
used for demo integration FAST/Swift collision library and Bullet
Definition btBroadphaseProxy.h:57
CONE_SHAPE_PROXYTYPE
@ CONE_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:42
BOX_2D_SHAPE_PROXYTYPE
@ BOX_2D_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:48
EMPTY_SHAPE_PROXYTYPE
@ EMPTY_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:65
MAX_BROADPHASE_COLLISION_TYPES
@ MAX_BROADPHASE_COLLISION_TYPES
Definition btBroadphaseProxy.h:78
CAPSULE_SHAPE_PROXYTYPE
@ CAPSULE_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:41
TETRAHEDRAL_SHAPE_PROXYTYPE
@ TETRAHEDRAL_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:32
HFFLUID_SHAPE_PROXYTYPE
@ HFFLUID_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:74
CONCAVE_SHAPES_END_HERE
@ CONCAVE_SHAPES_END_HERE
Definition btBroadphaseProxy.h:69
CONVEX_HULL_SHAPE_PROXYTYPE
@ CONVEX_HULL_SHAPE_PROXYTYPE
Definition btBroadphaseProxy.h:34
operator==
bool operator==(const btBroadphasePair &a, const btBroadphasePair &b)
Definition btBroadphaseProxy.h:243
btScalar.h
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition btScalar.h:99
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition btScalar.h:98
btVector3.h
btBroadphasePairSortPredicate
Definition btBroadphaseProxy.h:228
btBroadphasePairSortPredicate::operator()
bool operator()(const btBroadphasePair &a, const btBroadphasePair &b) const
Definition btBroadphaseProxy.h:230
btCollisionAlgorithm
btCollisionAlgorithm is an collision interface that is compatible with the Broadphase and btDispatche...
Definition btCollisionAlgorithm.h:54
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btBroadphasePair
The btBroadphasePair class contains a pair of aabb-overlapping objects.
Definition btBroadphaseProxy.h:179
btBroadphasePair::btBroadphasePair
btBroadphasePair(btBroadphaseProxy &proxy0, btBroadphaseProxy &proxy1)
Definition btBroadphaseProxy.h:190
btBroadphasePair::m_pProxy1
btBroadphaseProxy * m_pProxy1
Definition btBroadphaseProxy.h:209
btBroadphasePair::btBroadphasePair
btBroadphasePair()
Definition btBroadphaseProxy.h:180
btBroadphasePair::m_internalTmpValue
int m_internalTmpValue
Definition btBroadphaseProxy.h:214
btBroadphasePair::m_pProxy0
btBroadphaseProxy * m_pProxy0
Definition btBroadphaseProxy.h:208
btBroadphasePair::m_algorithm
btCollisionAlgorithm * m_algorithm
Definition btBroadphaseProxy.h:211
btBroadphasePair::m_internalInfo1
void * m_internalInfo1
Definition btBroadphaseProxy.h:213
btBroadphasePair::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btBroadphaseProxy
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
Definition btBroadphaseProxy.h:86
btBroadphaseProxy::CollisionFilterGroups
CollisionFilterGroups
optional filtering to cull potential collisions
Definition btBroadphaseProxy.h:91
btBroadphaseProxy::DebrisFilter
@ DebrisFilter
Definition btBroadphaseProxy.h:95
btBroadphaseProxy::CharacterFilter
@ CharacterFilter
Definition btBroadphaseProxy.h:97
btBroadphaseProxy::KinematicFilter
@ KinematicFilter
Definition btBroadphaseProxy.h:94
btBroadphaseProxy::AllFilter
@ AllFilter
Definition btBroadphaseProxy.h:98
btBroadphaseProxy::DefaultFilter
@ DefaultFilter
Definition btBroadphaseProxy.h:92
btBroadphaseProxy::StaticFilter
@ StaticFilter
Definition btBroadphaseProxy.h:93
btBroadphaseProxy::SensorTrigger
@ SensorTrigger
Definition btBroadphaseProxy.h:96
btBroadphaseProxy::m_collisionFilterMask
int m_collisionFilterMask
Definition btBroadphaseProxy.h:104
btBroadphaseProxy::isInfinite
static bool isInfinite(int proxyType)
Definition btBroadphaseProxy.h:160
btBroadphaseProxy::isCompound
static bool isCompound(int proxyType)
Definition btBroadphaseProxy.h:150
btBroadphaseProxy::m_aabbMin
btVector3 m_aabbMin
Definition btBroadphaseProxy.h:108
btBroadphaseProxy::btBroadphaseProxy
btBroadphaseProxy()
Definition btBroadphaseProxy.h:117
btBroadphaseProxy::isSoftBody
static bool isSoftBody(int proxyType)
Definition btBroadphaseProxy.h:155
btBroadphaseProxy::m_clientObject
void * m_clientObject
Definition btBroadphaseProxy.h:102
btBroadphaseProxy::isConvex2d
static bool isConvex2d(int proxyType)
Definition btBroadphaseProxy.h:165
btBroadphaseProxy::m_aabbMax
btVector3 m_aabbMax
Definition btBroadphaseProxy.h:109
btBroadphaseProxy::m_collisionFilterGroup
int m_collisionFilterGroup
Definition btBroadphaseProxy.h:103
btBroadphaseProxy::getUid
int getUid() const
Definition btBroadphaseProxy.h:111
btBroadphaseProxy::isPolyhedral
static bool isPolyhedral(int proxyType)
Definition btBroadphaseProxy.h:130
btBroadphaseProxy::isNonMoving
static bool isNonMoving(int proxyType)
Definition btBroadphaseProxy.h:140
btBroadphaseProxy::m_uniqueId
int m_uniqueId
Definition btBroadphaseProxy.h:106
btBroadphaseProxy::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btBroadphaseProxy::isConcave
static bool isConcave(int proxyType)
Definition btBroadphaseProxy.h:145
btBroadphaseProxy::isConvex
static bool isConvex(int proxyType)
Definition btBroadphaseProxy.h:135
btBroadphaseProxy::btBroadphaseProxy
btBroadphaseProxy(const btVector3 &aabbMin, const btVector3 &aabbMax, void *userPtr, int collisionFilterGroup, int collisionFilterMask)
Definition btBroadphaseProxy.h:121