Blender  V3.3
btSoftBodyRigidBodyCollisionConfiguration.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 
20 
22 
23 #define ENABLE_SOFTBODY_CONCAVE_COLLISIONS 1
24 
26  : btDefaultCollisionConfiguration(constructionInfo)
27 {
28  void* mem;
29 
31  m_softSoftCreateFunc = new (mem) btSoftSoftCollisionAlgorithm::CreateFunc;
32 
34  m_softRigidConvexCreateFunc = new (mem) btSoftRigidCollisionAlgorithm::CreateFunc;
35 
37  m_swappedSoftRigidConvexCreateFunc = new (mem) btSoftRigidCollisionAlgorithm::CreateFunc;
38  m_swappedSoftRigidConvexCreateFunc->m_swapped = true;
39 
40 #ifdef ENABLE_SOFTBODY_CONCAVE_COLLISIONS
42  m_softRigidConcaveCreateFunc = new (mem) btSoftBodyConcaveCollisionAlgorithm::CreateFunc;
43 
45  m_swappedSoftRigidConcaveCreateFunc = new (mem) btSoftBodyConcaveCollisionAlgorithm::SwappedCreateFunc;
46  m_swappedSoftRigidConcaveCreateFunc->m_swapped = true;
47 #endif
48 
49  //replace pool by a new one, with potential larger size
50 
52  {
53  int curElemSize = m_collisionAlgorithmPool->getElementSize();
55 
56  int maxSize0 = sizeof(btSoftSoftCollisionAlgorithm);
57  int maxSize1 = sizeof(btSoftRigidCollisionAlgorithm);
58  int maxSize2 = sizeof(btSoftBodyConcaveCollisionAlgorithm);
59 
60  int collisionAlgorithmMaxElementSize = btMax(maxSize0, maxSize1);
61  collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize, maxSize2);
62 
63  if (collisionAlgorithmMaxElementSize > curElemSize)
64  {
67  void* mem = btAlignedAlloc(sizeof(btPoolAllocator), 16);
68  m_collisionAlgorithmPool = new (mem) btPoolAllocator(collisionAlgorithmMaxElementSize, constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize);
69  }
70  }
71 }
72 
74 {
75  m_softSoftCreateFunc->~btCollisionAlgorithmCreateFunc();
76  btAlignedFree(m_softSoftCreateFunc);
77 
78  m_softRigidConvexCreateFunc->~btCollisionAlgorithmCreateFunc();
79  btAlignedFree(m_softRigidConvexCreateFunc);
80 
81  m_swappedSoftRigidConvexCreateFunc->~btCollisionAlgorithmCreateFunc();
82  btAlignedFree(m_swappedSoftRigidConvexCreateFunc);
83 
84 #ifdef ENABLE_SOFTBODY_CONCAVE_COLLISIONS
85  m_softRigidConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
86  btAlignedFree(m_softRigidConcaveCreateFunc);
87 
88  m_swappedSoftRigidConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
89  btAlignedFree(m_swappedSoftRigidConcaveCreateFunc);
90 #endif
91 }
92 
95 {
97 
98  if ((proxyType0 == SOFTBODY_SHAPE_PROXYTYPE) && (proxyType1 == SOFTBODY_SHAPE_PROXYTYPE))
99  {
100  return m_softSoftCreateFunc;
101  }
102 
104  if (proxyType0 == SOFTBODY_SHAPE_PROXYTYPE && btBroadphaseProxy::isConvex(proxyType1))
105  {
106  return m_softRigidConvexCreateFunc;
107  }
108 
110  if (btBroadphaseProxy::isConvex(proxyType0) && proxyType1 == SOFTBODY_SHAPE_PROXYTYPE)
111  {
112  return m_swappedSoftRigidConvexCreateFunc;
113  }
114 
115 #ifdef ENABLE_SOFTBODY_CONCAVE_COLLISIONS
117  if (proxyType0 == SOFTBODY_SHAPE_PROXYTYPE && btBroadphaseProxy::isConcave(proxyType1))
118  {
119  return m_softRigidConcaveCreateFunc;
120  }
121 
123  if (btBroadphaseProxy::isConcave(proxyType0) && proxyType1 == SOFTBODY_SHAPE_PROXYTYPE)
124  {
125  return m_swappedSoftRigidConcaveCreateFunc;
126  }
127 #endif
128 
131 }
#define btAlignedFree(ptr)
#define btAlignedAlloc(size, alignment)
@ SOFTBODY_SHAPE_PROXYTYPE
SIMD_FORCE_INLINE bool isConcave() const
SIMD_FORCE_INLINE bool isConvex() const
SIMD_FORCE_INLINE const T & btMax(const T &a, const T &b)
Definition: btMinMax.h:27
virtual btCollisionAlgorithmCreateFunc * getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1)
The btPoolAllocator class allows to efficiently allocate a large pool of objects, instead of dynamica...
int getElementSize() const
btSoftBodyConcaveCollisionAlgorithm supports collision between soft body shapes and (concave) triange...
virtual btCollisionAlgorithmCreateFunc * getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1)
creation of soft-soft and soft-rigid, and otherwise fallback to base class implementation
btSoftBodyRigidBodyCollisionConfiguration(const btDefaultCollisionConstructionInfo &constructionInfo=btDefaultCollisionConstructionInfo())
btSoftRigidCollisionAlgorithm provides collision detection between btSoftBody and btRigidBody
collision detection between two btSoftBody shapes
Used by the btCollisionDispatcher to register and create instances for btCollisionAlgorithm.