Bullet Collision Detection & Physics Library
btBroadphaseProxy.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. 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"
22 
28 {
29  // polyhedral convex shapes
37  //implicit convex shapes
51  //concave shapes
53  //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
58  //terrain
64 
70 
72 
77 
79 
80 };
81 
86 {
88 
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
105 
106  int m_uniqueId; //m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
107 
110 
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 
172 
173 struct btBroadphaseProxy;
174 
179 {
181  : m_pProxy0(0),
182  m_pProxy1(0),
183  m_algorithm(0),
184  m_internalInfo1(0)
185  {
186  }
187 
189 
191  : m_pProxy0(other.m_pProxy0),
192  m_pProxy1(other.m_pProxy1),
193  m_algorithm(other.m_algorithm),
194  m_internalInfo1(other.m_internalInfo1)
195  {
196  }
198  {
199  //keep them sorted, so the std::set operations work
200  if (proxy0.m_uniqueId < proxy1.m_uniqueId)
201  {
202  m_pProxy0 = &proxy0;
203  m_pProxy1 = &proxy1;
204  }
205  else
206  {
207  m_pProxy0 = &proxy1;
208  m_pProxy1 = &proxy0;
209  }
210 
211  m_algorithm = 0;
212  m_internalInfo1 = 0;
213  }
214 
217 
219  union {
222  }; //don't use this data, it will be removed in future version.
223 };
224 
225 /*
226 //comparison for set operation, see Solid DT_Encounter
227 SIMD_FORCE_INLINE bool operator<(const btBroadphasePair& a, const btBroadphasePair& b)
228 {
229  return a.m_pProxy0 < b.m_pProxy0 ||
230  (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 < b.m_pProxy1);
231 }
232 */
233 
235 {
236 public:
237  bool operator()(const btBroadphasePair& a, const btBroadphasePair& b) const
238  {
239  const int uidA0 = a.m_pProxy0 ? a.m_pProxy0->m_uniqueId : -1;
240  const int uidB0 = b.m_pProxy0 ? b.m_pProxy0->m_uniqueId : -1;
241  const int uidA1 = a.m_pProxy1 ? a.m_pProxy1->m_uniqueId : -1;
242  const int uidB1 = b.m_pProxy1 ? b.m_pProxy1->m_uniqueId : -1;
243 
244  return uidA0 > uidB0 ||
245  (a.m_pProxy0 == b.m_pProxy0 && uidA1 > uidB1) ||
246  (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm);
247  }
248 };
249 
251 {
252  return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1);
253 }
254 
255 #endif //BT_BROADPHASE_PROXY_H
bool operator()(const btBroadphasePair &a, const btBroadphasePair &b) const
btBroadphasePair(const btBroadphasePair &other)
static bool isInfinite(int proxyType)
#define SIMD_FORCE_INLINE
Definition: btScalar.h:83
static bool isCompound(int proxyType)
btBroadphaseProxy(const btVector3 &aabbMin, const btVector3 &aabbMax, void *userPtr, int collisionFilterGroup, int collisionFilterMask)
Used for GIMPACT Trimesh integration.
static bool isNonMoving(int proxyType)
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
btBroadphaseProxy * m_pProxy1
btCollisionAlgorithm * m_algorithm
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:80
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:84
static bool isPolyhedral(int proxyType)
btBroadphaseProxy * m_pProxy0
static bool isSoftBody(int proxyType)
BroadphaseNativeTypes
btDispatcher uses these types IMPORTANT NOTE:The types are ordered polyhedral, implicit convex and co...
btBroadphasePair(btBroadphaseProxy &proxy0, btBroadphaseProxy &proxy1)
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:405
bool operator==(const btBroadphasePair &a, const btBroadphasePair &b)
static bool isConvex2d(int proxyType)
static bool isConcave(int proxyType)
CollisionFilterGroups
optional filtering to cull potential collisions
btCollisionAlgorithm is an collision interface that is compatible with the Broadphase and btDispatche...
static bool isConvex(int proxyType)
used for demo integration FAST/Swift collision library and Bullet
The btBroadphasePair class contains a pair of aabb-overlapping objects.