2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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:
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.
16
#include "btDefaultCollisionConfiguration.h"
18
#include "BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h"
19
#include "BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h"
20
#include "BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h"
21
#include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"
22
#include "BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h"
23
#include "BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h"
24
#include "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h"
25
#ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
26
#include "BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h"
27
#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
28
#include "BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h"
29
#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
30
#include "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h"
31
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
35
#include "LinearMath/btStackAlloc.h"
36
#include "LinearMath/btPoolAllocator.h"
42
btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo)
43
//btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(btStackAlloc* stackAlloc,btPoolAllocator* persistentManifoldPool,btPoolAllocator* collisionAlgorithmPool)
46
void* mem = btAlignedAlloc(sizeof(btVoronoiSimplexSolver),16);
47
m_simplexSolver = new (mem)btVoronoiSimplexSolver();
51
mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);
52
m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver;
54
mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16);
55
m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver;
59
//default CreationFunctions, filling the m_doubleDispatch table
60
mem = btAlignedAlloc(sizeof(btConvexConvexAlgorithm::CreateFunc),16);
61
m_convexConvexCreateFunc = new(mem) btConvexConvexAlgorithm::CreateFunc(m_simplexSolver,m_pdSolver);
62
mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16);
63
m_convexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::CreateFunc;
64
mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16);
65
m_swappedConvexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::SwappedCreateFunc;
66
mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::CreateFunc),16);
67
m_compoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::CreateFunc;
68
mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::SwappedCreateFunc),16);
69
m_swappedCompoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::SwappedCreateFunc;
70
mem = btAlignedAlloc(sizeof(btEmptyAlgorithm::CreateFunc),16);
71
m_emptyCreateFunc = new(mem) btEmptyAlgorithm::CreateFunc;
73
mem = btAlignedAlloc(sizeof(btSphereSphereCollisionAlgorithm::CreateFunc),16);
74
m_sphereSphereCF = new(mem) btSphereSphereCollisionAlgorithm::CreateFunc;
75
#ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
76
mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc),16);
77
m_sphereBoxCF = new(mem) btSphereBoxCollisionAlgorithm::CreateFunc;
78
mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc),16);
79
m_boxSphereCF = new (mem)btSphereBoxCollisionAlgorithm::CreateFunc;
80
m_boxSphereCF->m_swapped = true;
81
#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
83
mem = btAlignedAlloc(sizeof(btSphereTriangleCollisionAlgorithm::CreateFunc),16);
84
m_sphereTriangleCF = new (mem)btSphereTriangleCollisionAlgorithm::CreateFunc;
85
mem = btAlignedAlloc(sizeof(btSphereTriangleCollisionAlgorithm::CreateFunc),16);
86
m_triangleSphereCF = new (mem)btSphereTriangleCollisionAlgorithm::CreateFunc;
87
m_triangleSphereCF->m_swapped = true;
89
mem = btAlignedAlloc(sizeof(btBoxBoxCollisionAlgorithm::CreateFunc),16);
90
m_boxBoxCF = new(mem)btBoxBoxCollisionAlgorithm::CreateFunc;
93
mem = btAlignedAlloc (sizeof(btConvexPlaneCollisionAlgorithm::CreateFunc),16);
94
m_convexPlaneCF = new (mem) btConvexPlaneCollisionAlgorithm::CreateFunc;
95
mem = btAlignedAlloc (sizeof(btConvexPlaneCollisionAlgorithm::CreateFunc),16);
96
m_planeConvexCF = new (mem) btConvexPlaneCollisionAlgorithm::CreateFunc;
97
m_planeConvexCF->m_swapped = true;
99
///calculate maximum element size, big enough to fit any collision algorithm in the memory pool
100
int maxSize = sizeof(btConvexConvexAlgorithm);
101
int maxSize2 = sizeof(btConvexConcaveCollisionAlgorithm);
102
int maxSize3 = sizeof(btCompoundCollisionAlgorithm);
103
int maxSize4 = sizeof(btEmptyAlgorithm);
105
int collisionAlgorithmMaxElementSize = btMax(maxSize,maxSize2);
106
collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3);
107
collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize4);
109
if (constructionInfo.m_stackAlloc)
111
m_ownsStackAllocator = false;
112
this->m_stackAlloc = constructionInfo.m_stackAlloc;
115
m_ownsStackAllocator = true;
116
void* mem = btAlignedAlloc(sizeof(btStackAlloc),16);
117
m_stackAlloc = new(mem)btStackAlloc(constructionInfo.m_defaultStackAllocatorSize);
120
if (constructionInfo.m_persistentManifoldPool)
122
m_ownsPersistentManifoldPool = false;
123
m_persistentManifoldPool = constructionInfo.m_persistentManifoldPool;
126
m_ownsPersistentManifoldPool = true;
127
void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
128
m_persistentManifoldPool = new (mem) btPoolAllocator(sizeof(btPersistentManifold),constructionInfo.m_defaultMaxPersistentManifoldPoolSize);
131
if (constructionInfo.m_collisionAlgorithmPool)
133
m_ownsCollisionAlgorithmPool = false;
134
m_collisionAlgorithmPool = constructionInfo.m_collisionAlgorithmPool;
137
m_ownsCollisionAlgorithmPool = true;
138
void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
139
m_collisionAlgorithmPool = new(mem) btPoolAllocator(collisionAlgorithmMaxElementSize,constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize);
145
btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
147
if (m_ownsStackAllocator)
149
m_stackAlloc->destroy();
150
m_stackAlloc->~btStackAlloc();
151
btAlignedFree(m_stackAlloc);
153
if (m_ownsCollisionAlgorithmPool)
155
m_collisionAlgorithmPool->~btPoolAllocator();
156
btAlignedFree(m_collisionAlgorithmPool);
158
if (m_ownsPersistentManifoldPool)
160
m_persistentManifoldPool->~btPoolAllocator();
161
btAlignedFree(m_persistentManifoldPool);
164
m_convexConvexCreateFunc->~btCollisionAlgorithmCreateFunc();
165
btAlignedFree( m_convexConvexCreateFunc);
167
m_convexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
168
btAlignedFree( m_convexConcaveCreateFunc);
169
m_swappedConvexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
170
btAlignedFree( m_swappedConvexConcaveCreateFunc);
172
m_compoundCreateFunc->~btCollisionAlgorithmCreateFunc();
173
btAlignedFree( m_compoundCreateFunc);
175
m_swappedCompoundCreateFunc->~btCollisionAlgorithmCreateFunc();
176
btAlignedFree( m_swappedCompoundCreateFunc);
178
m_emptyCreateFunc->~btCollisionAlgorithmCreateFunc();
179
btAlignedFree( m_emptyCreateFunc);
181
m_sphereSphereCF->~btCollisionAlgorithmCreateFunc();
182
btAlignedFree( m_sphereSphereCF);
184
#ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
185
m_sphereBoxCF->~btCollisionAlgorithmCreateFunc();
186
btAlignedFree( m_sphereBoxCF);
187
m_boxSphereCF->~btCollisionAlgorithmCreateFunc();
188
btAlignedFree( m_boxSphereCF);
189
#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
191
m_sphereTriangleCF->~btCollisionAlgorithmCreateFunc();
192
btAlignedFree( m_sphereTriangleCF);
193
m_triangleSphereCF->~btCollisionAlgorithmCreateFunc();
194
btAlignedFree( m_triangleSphereCF);
195
m_boxBoxCF->~btCollisionAlgorithmCreateFunc();
196
btAlignedFree( m_boxBoxCF);
198
m_convexPlaneCF->~btCollisionAlgorithmCreateFunc();
199
btAlignedFree( m_convexPlaneCF);
200
m_planeConvexCF->~btCollisionAlgorithmCreateFunc();
201
btAlignedFree( m_planeConvexCF);
203
m_simplexSolver->~btVoronoiSimplexSolver();
204
btAlignedFree(m_simplexSolver);
206
m_pdSolver->~btConvexPenetrationDepthSolver();
208
btAlignedFree(m_pdSolver);
214
btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1)
219
if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1==SPHERE_SHAPE_PROXYTYPE))
221
return m_sphereSphereCF;
223
#ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
224
if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1==BOX_SHAPE_PROXYTYPE))
226
return m_sphereBoxCF;
229
if ((proxyType0 == BOX_SHAPE_PROXYTYPE ) && (proxyType1==SPHERE_SHAPE_PROXYTYPE))
231
return m_boxSphereCF;
233
#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
236
if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE ) && (proxyType1==TRIANGLE_SHAPE_PROXYTYPE))
238
return m_sphereTriangleCF;
241
if ((proxyType0 == TRIANGLE_SHAPE_PROXYTYPE ) && (proxyType1==SPHERE_SHAPE_PROXYTYPE))
243
return m_triangleSphereCF;
246
if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
251
if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE))
253
return m_convexPlaneCF;
256
if (btBroadphaseProxy::isConvex(proxyType1) && (proxyType0 == STATIC_PLANE_PROXYTYPE))
258
return m_planeConvexCF;
263
if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConvex(proxyType1))
265
return m_convexConvexCreateFunc;
268
if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConcave(proxyType1))
270
return m_convexConcaveCreateFunc;
273
if (btBroadphaseProxy::isConvex(proxyType1) && btBroadphaseProxy::isConcave(proxyType0))
275
return m_swappedConvexConcaveCreateFunc;
278
if (btBroadphaseProxy::isCompound(proxyType0))
280
return m_compoundCreateFunc;
283
if (btBroadphaseProxy::isCompound(proxyType1))
285
return m_swappedCompoundCreateFunc;
289
//failed to find an algorithm
290
return m_emptyCreateFunc;