Bullet Collision Detection & Physics Library: btSoftBodyRigidBodyCollisionConfiguration.cpp Source File

Bullet Collision Detection & Physics Library

btSoftBodyRigidBodyCollisionConfiguration.cpp
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#include "btSoftBodyRigidBodyCollisionConfiguration.h"
17#include "btSoftRigidCollisionAlgorithm.h"
18#include "btSoftBodyConcaveCollisionAlgorithm.h"
19#include "btSoftSoftCollisionAlgorithm.h"
20
21#include "LinearMath/btPoolAllocator.h"
22
23#define ENABLE_SOFTBODY_CONCAVE_COLLISIONS 1
24
25btSoftBodyRigidBodyCollisionConfiguration::btSoftBodyRigidBodyCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo)
26 : btDefaultCollisionConfiguration(constructionInfo)
27{
28 void* mem;
29
30 mem = btAlignedAlloc(sizeof(btSoftSoftCollisionAlgorithm::CreateFunc), 16);
31 m_softSoftCreateFunc = new (mem) btSoftSoftCollisionAlgorithm::CreateFunc;
32
33 mem = btAlignedAlloc(sizeof(btSoftRigidCollisionAlgorithm::CreateFunc), 16);
34 m_softRigidConvexCreateFunc = new (mem) btSoftRigidCollisionAlgorithm::CreateFunc;
35
36 mem = btAlignedAlloc(sizeof(btSoftRigidCollisionAlgorithm::CreateFunc), 16);
37 m_swappedSoftRigidConvexCreateFunc = new (mem) btSoftRigidCollisionAlgorithm::CreateFunc;
38 m_swappedSoftRigidConvexCreateFunc->m_swapped = true;
39
40#ifdef ENABLE_SOFTBODY_CONCAVE_COLLISIONS
41 mem = btAlignedAlloc(sizeof(btSoftBodyConcaveCollisionAlgorithm::CreateFunc), 16);
42 m_softRigidConcaveCreateFunc = new (mem) btSoftBodyConcaveCollisionAlgorithm::CreateFunc;
43
44 mem = btAlignedAlloc(sizeof(btSoftBodyConcaveCollisionAlgorithm::CreateFunc), 16);
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
51 if (m_ownsCollisionAlgorithmPool && m_collisionAlgorithmPool)
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 {
65 m_collisionAlgorithmPool->~btPoolAllocator();
66 btAlignedFree(m_collisionAlgorithmPool);
67 void* mem = btAlignedAlloc(sizeof(btPoolAllocator), 16);
68 m_collisionAlgorithmPool = new (mem) btPoolAllocator(collisionAlgorithmMaxElementSize, constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize);
69 }
70 }
71}
72
73btSoftBodyRigidBodyCollisionConfiguration::~btSoftBodyRigidBodyCollisionConfiguration()
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
94 btCollisionAlgorithmCreateFunc* btSoftBodyRigidBodyCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1)
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
130 return btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(proxyType0, proxyType1);
131}
btAlignedFree
#define btAlignedFree(ptr)
Definition: btAlignedAllocator.h:47
btAlignedAlloc
#define btAlignedAlloc(size, alignment)
Definition: btAlignedAllocator.h:46
SOFTBODY_SHAPE_PROXYTYPE
@ SOFTBODY_SHAPE_PROXYTYPE
Definition: btBroadphaseProxy.h:73
btMax
const T & btMax(const T &a, const T &b)
Definition: btMinMax.h:27
btPoolAllocator.h
btSoftBodyConcaveCollisionAlgorithm.h
btSoftBodyRigidBodyCollisionConfiguration.h
btSoftRigidCollisionAlgorithm.h
btSoftSoftCollisionAlgorithm.h
btDefaultCollisionConfiguration
btCollisionConfiguration allows to configure Bullet collision detection stack allocator,...
Definition: btDefaultCollisionConfiguration.h:47
btDefaultCollisionConfiguration::m_collisionAlgorithmPool
btPoolAllocator * m_collisionAlgorithmPool
Definition: btDefaultCollisionConfiguration.h:54
btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc
virtual btCollisionAlgorithmCreateFunc * getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1)
Definition: btDefaultCollisionConfiguration.cpp:267
btDefaultCollisionConfiguration::m_ownsCollisionAlgorithmPool
bool m_ownsCollisionAlgorithmPool
Definition: btDefaultCollisionConfiguration.h:55
btPoolAllocator
The btPoolAllocator class allows to efficiently allocate a large pool of objects, instead of dynamica...
Definition: btPoolAllocator.h:24
btPoolAllocator::getElementSize
int getElementSize() const
Definition: btPoolAllocator.h:114
btPoolAllocator::~btPoolAllocator
~btPoolAllocator()
Definition: btPoolAllocator.h:51
btSoftBodyConcaveCollisionAlgorithm
btSoftBodyConcaveCollisionAlgorithm supports collision between soft body shapes and (concave) triange...
Definition: btSoftBodyConcaveCollisionAlgorithm.h:107
btSoftBodyRigidBodyCollisionConfiguration::m_swappedSoftRigidConvexCreateFunc
btCollisionAlgorithmCreateFunc * m_swappedSoftRigidConvexCreateFunc
Definition: btSoftBodyRigidBodyCollisionConfiguration.h:30
btSoftBodyRigidBodyCollisionConfiguration::~btSoftBodyRigidBodyCollisionConfiguration
virtual ~btSoftBodyRigidBodyCollisionConfiguration()
Definition: btSoftBodyRigidBodyCollisionConfiguration.cpp:73
btSoftBodyRigidBodyCollisionConfiguration::getCollisionAlgorithmCreateFunc
virtual btCollisionAlgorithmCreateFunc * getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1)
creation of soft-soft and soft-rigid, and otherwise fallback to base class implementation
Definition: btSoftBodyRigidBodyCollisionConfiguration.cpp:94
btSoftBodyRigidBodyCollisionConfiguration::m_softRigidConcaveCreateFunc
btCollisionAlgorithmCreateFunc * m_softRigidConcaveCreateFunc
Definition: btSoftBodyRigidBodyCollisionConfiguration.h:31
btSoftBodyRigidBodyCollisionConfiguration::m_softSoftCreateFunc
btCollisionAlgorithmCreateFunc * m_softSoftCreateFunc
Definition: btSoftBodyRigidBodyCollisionConfiguration.h:28
btSoftBodyRigidBodyCollisionConfiguration::m_swappedSoftRigidConcaveCreateFunc
btCollisionAlgorithmCreateFunc * m_swappedSoftRigidConcaveCreateFunc
Definition: btSoftBodyRigidBodyCollisionConfiguration.h:32
btSoftBodyRigidBodyCollisionConfiguration::btSoftBodyRigidBodyCollisionConfiguration
btSoftBodyRigidBodyCollisionConfiguration(const btDefaultCollisionConstructionInfo &constructionInfo=btDefaultCollisionConstructionInfo())
Definition: btSoftBodyRigidBodyCollisionConfiguration.cpp:25
btSoftBodyRigidBodyCollisionConfiguration::m_softRigidConvexCreateFunc
btCollisionAlgorithmCreateFunc * m_softRigidConvexCreateFunc
Definition: btSoftBodyRigidBodyCollisionConfiguration.h:29
btSoftRigidCollisionAlgorithm
btSoftRigidCollisionAlgorithm provides collision detection between btSoftBody and btRigidBody
Definition: btSoftRigidCollisionAlgorithm.h:30
btSoftSoftCollisionAlgorithm
collision detection between two btSoftBody shapes
Definition: btSoftSoftCollisionAlgorithm.h:29
btBroadphaseProxy::isConcave
static bool isConcave(int proxyType)
Definition: btBroadphaseProxy.h:145
btBroadphaseProxy::isConvex
static bool isConvex(int proxyType)
Definition: btBroadphaseProxy.h:135
btCollisionAlgorithmCreateFunc
Used by the btCollisionDispatcher to register and create instances for btCollisionAlgorithm.
Definition: btCollisionCreateFunc.h:27
btCollisionAlgorithmCreateFunc::~btCollisionAlgorithmCreateFunc
virtual ~btCollisionAlgorithmCreateFunc()
Definition: btCollisionCreateFunc.h:34
btCollisionAlgorithmCreateFunc::m_swapped
bool m_swapped
Definition: btCollisionCreateFunc.h:28
btDefaultCollisionConstructionInfo
Definition: btDefaultCollisionConfiguration.h:24
btDefaultCollisionConstructionInfo::m_defaultMaxCollisionAlgorithmPoolSize
int m_defaultMaxCollisionAlgorithmPoolSize
Definition: btDefaultCollisionConfiguration.h:28
btSoftBodyConcaveCollisionAlgorithm::CreateFunc
Definition: btSoftBodyConcaveCollisionAlgorithm.h:129
btSoftBodyConcaveCollisionAlgorithm::SwappedCreateFunc
Definition: btSoftBodyConcaveCollisionAlgorithm.h:138
btSoftRigidCollisionAlgorithm::CreateFunc
Definition: btSoftRigidCollisionAlgorithm.h:55
btSoftSoftCollisionAlgorithm::CreateFunc
Definition: btSoftSoftCollisionAlgorithm.h:55