Blender  V3.3
btDefaultCollisionConfiguration.cpp
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 
17 
23 
27 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
29 #endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
34 
36 
38 //btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(btStackAlloc* stackAlloc,btPoolAllocator* persistentManifoldPool,btPoolAllocator* collisionAlgorithmPool)
39 {
40  void* mem = NULL;
41  if (constructionInfo.m_useEpaPenetrationAlgorithm)
42  {
45  }
46  else
47  {
50  }
51 
52  //default CreationFunctions, filling the m_doubleDispatch table
55  mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc), 16);
56  m_convexConcaveCreateFunc = new (mem) btConvexConcaveCollisionAlgorithm::CreateFunc;
57  mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc), 16);
58  m_swappedConvexConcaveCreateFunc = new (mem) btConvexConcaveCollisionAlgorithm::SwappedCreateFunc;
61 
64 
69 
72 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
77  m_boxSphereCF->m_swapped = true;
78 #endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
79 
85 
88 
89  //convex versus plane
94  m_planeConvexCF->m_swapped = true;
95 
97  int maxSize = sizeof(btConvexConvexAlgorithm);
98  int maxSize2 = sizeof(btConvexConcaveCollisionAlgorithm);
99  int maxSize3 = sizeof(btCompoundCollisionAlgorithm);
100  int maxSize4 = sizeof(btCompoundCompoundCollisionAlgorithm);
101 
102  int collisionAlgorithmMaxElementSize = btMax(maxSize, constructionInfo.m_customCollisionAlgorithmMaxElementSize);
103  collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize, maxSize2);
104  collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize, maxSize3);
105  collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize, maxSize4);
106 
107  if (constructionInfo.m_persistentManifoldPool)
108  {
111  }
112  else
113  {
115  void* mem = btAlignedAlloc(sizeof(btPoolAllocator), 16);
117  }
118 
119  collisionAlgorithmMaxElementSize = (collisionAlgorithmMaxElementSize + 16) & 0xffffffffffff0;
120  if (constructionInfo.m_collisionAlgorithmPool)
121  {
124  }
125  else
126  {
128  void* mem = btAlignedAlloc(sizeof(btPoolAllocator), 16);
129  m_collisionAlgorithmPool = new (mem) btPoolAllocator(collisionAlgorithmMaxElementSize, constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize);
130  }
131 }
132 
134 {
136  {
139  }
141  {
144  }
145 
148 
153 
156 
159 
162 
165 
168 
169 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
174 #endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
175 
182 
187 
189 
191 }
192 
194 {
195  if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
196  {
197  return m_sphereSphereCF;
198  }
199 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
200  if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
201  {
202  return m_sphereBoxCF;
203  }
204 
205  if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
206  {
207  return m_boxSphereCF;
208  }
209 #endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
210 
211  if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == TRIANGLE_SHAPE_PROXYTYPE))
212  {
213  return m_sphereTriangleCF;
214  }
215 
216  if ((proxyType0 == TRIANGLE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
217  {
218  return m_triangleSphereCF;
219  }
220 
221  if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE))
222  {
223  return m_convexPlaneCF;
224  }
225 
226  if (btBroadphaseProxy::isConvex(proxyType1) && (proxyType0 == STATIC_PLANE_PROXYTYPE))
227  {
228  return m_planeConvexCF;
229  }
230 
231  if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConvex(proxyType1))
232  {
234  }
235 
236  if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConcave(proxyType1))
237  {
239  }
240 
241  if (btBroadphaseProxy::isConvex(proxyType1) && btBroadphaseProxy::isConcave(proxyType0))
242  {
244  }
245 
246  if (btBroadphaseProxy::isCompound(proxyType0) && btBroadphaseProxy::isCompound(proxyType1))
247  {
249  }
250 
251  if (btBroadphaseProxy::isCompound(proxyType0))
252  {
253  return m_compoundCreateFunc;
254  }
255  else
256  {
257  if (btBroadphaseProxy::isCompound(proxyType1))
258  {
260  }
261  }
262 
263  //failed to find an algorithm
264  return m_emptyCreateFunc;
265 }
266 
268 {
269  if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
270  {
271  return m_sphereSphereCF;
272  }
273 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
274  if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
275  {
276  return m_sphereBoxCF;
277  }
278 
279  if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
280  {
281  return m_boxSphereCF;
282  }
283 #endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
284 
285  if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == TRIANGLE_SHAPE_PROXYTYPE))
286  {
287  return m_sphereTriangleCF;
288  }
289 
290  if ((proxyType0 == TRIANGLE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
291  {
292  return m_triangleSphereCF;
293  }
294 
295  if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
296  {
297  return m_boxBoxCF;
298  }
299 
300  if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE))
301  {
302  return m_convexPlaneCF;
303  }
304 
305  if (btBroadphaseProxy::isConvex(proxyType1) && (proxyType0 == STATIC_PLANE_PROXYTYPE))
306  {
307  return m_planeConvexCF;
308  }
309 
310  if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConvex(proxyType1))
311  {
313  }
314 
315  if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConcave(proxyType1))
316  {
318  }
319 
320  if (btBroadphaseProxy::isConvex(proxyType1) && btBroadphaseProxy::isConcave(proxyType0))
321  {
323  }
324 
325  if (btBroadphaseProxy::isCompound(proxyType0) && btBroadphaseProxy::isCompound(proxyType1))
326  {
328  }
329 
330  if (btBroadphaseProxy::isCompound(proxyType0))
331  {
332  return m_compoundCreateFunc;
333  }
334  else
335  {
336  if (btBroadphaseProxy::isCompound(proxyType1))
337  {
339  }
340  }
341 
342  //failed to find an algorithm
343  return m_emptyCreateFunc;
344 }
345 
346 void btDefaultCollisionConfiguration::setConvexConvexMultipointIterations(int numPerturbationIterations, int minimumPointsPerturbationThreshold)
347 {
349  convexConvex->m_numPerturbationIterations = numPerturbationIterations;
350  convexConvex->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
351 }
352 
353 void btDefaultCollisionConfiguration::setPlaneConvexMultipointIterations(int numPerturbationIterations, int minimumPointsPerturbationThreshold)
354 {
356  cpCF->m_numPerturbationIterations = numPerturbationIterations;
357  cpCF->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
358 
360  pcCF->m_numPerturbationIterations = numPerturbationIterations;
361  pcCF->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
362 }
#define btAlignedFree(ptr)
#define btAlignedAlloc(size, alignment)
@ TRIANGLE_SHAPE_PROXYTYPE
@ STATIC_PLANE_PROXYTYPE
@ SPHERE_SHAPE_PROXYTYPE
@ BOX_SHAPE_PROXYTYPE
SIMD_FORCE_INLINE bool isConcave() const
SIMD_FORCE_INLINE bool isConvex() const
SIMD_FORCE_INLINE bool isCompound() const
btConvexConcaveCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, bool isSwapped)
SIMD_FORCE_INLINE const T & btMax(const T &a, const T &b)
Definition: btMinMax.h:27
btPersistentManifold()
btCompoundCollisionAlgorithm supports collision between CompoundCollisionShapes and other collision s...
btCompoundCompoundCollisionAlgorithm supports collision between two btCompoundCollisionShape shapes
btCollisionAlgorithmCreateFunc * m_boxSphereCF
btCollisionAlgorithmCreateFunc * m_compoundCreateFunc
btCollisionAlgorithmCreateFunc * m_triangleSphereCF
void setConvexConvexMultipointIterations(int numPerturbationIterations=3, int minimumPointsPerturbationThreshold=3)
btCollisionAlgorithmCreateFunc * m_boxBoxCF
btCollisionAlgorithmCreateFunc * m_sphereTriangleCF
virtual btCollisionAlgorithmCreateFunc * getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1)
btCollisionAlgorithmCreateFunc * m_convexConcaveCreateFunc
btCollisionAlgorithmCreateFunc * m_planeConvexCF
void setPlaneConvexMultipointIterations(int numPerturbationIterations=3, int minimumPointsPerturbationThreshold=3)
btCollisionAlgorithmCreateFunc * m_compoundCompoundCreateFunc
btConvexPenetrationDepthSolver * m_pdSolver
btCollisionAlgorithmCreateFunc * m_convexPlaneCF
btCollisionAlgorithmCreateFunc * m_sphereSphereCF
virtual btCollisionAlgorithmCreateFunc * getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1)
btDefaultCollisionConfiguration(const btDefaultCollisionConstructionInfo &constructionInfo=btDefaultCollisionConstructionInfo())
btCollisionAlgorithmCreateFunc * m_swappedConvexConcaveCreateFunc
btCollisionAlgorithmCreateFunc * m_emptyCreateFunc
btCollisionAlgorithmCreateFunc * m_swappedCompoundCreateFunc
btCollisionAlgorithmCreateFunc * m_convexConvexCreateFunc
btCollisionAlgorithmCreateFunc * m_sphereBoxCF
The btPoolAllocator class allows to efficiently allocate a large pool of objects, instead of dynamica...
Used by the btCollisionDispatcher to register and create instances for btCollisionAlgorithm.