Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp @ 2877

Last change on this file since 2877 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

  • Property svn:eol-style set to native
File size: 10.5 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
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 "btDefaultCollisionConfiguration.h"
17
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"
32
33
34
35#include "LinearMath/btStackAlloc.h"
36#include "LinearMath/btPoolAllocator.h"
37
38
39
40
41
42btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo)
43//btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(btStackAlloc*        stackAlloc,btPoolAllocator*     persistentManifoldPool,btPoolAllocator* collisionAlgorithmPool)
44{
45
46        void* mem = btAlignedAlloc(sizeof(btVoronoiSimplexSolver),16);
47        m_simplexSolver = new (mem)btVoronoiSimplexSolver();
48       
49#define USE_EPA 1
50#ifdef USE_EPA
51        mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);
52        m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver;
53#else
54        mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16);
55        m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver;
56#endif//USE_EPA
57       
58
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;
72       
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
82
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;
88       
89        mem = btAlignedAlloc(sizeof(btBoxBoxCollisionAlgorithm::CreateFunc),16);
90        m_boxBoxCF = new(mem)btBoxBoxCollisionAlgorithm::CreateFunc;
91
92        //convex versus plane
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;
98       
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 sl = sizeof(btConvexSeparatingDistanceUtil);
104        sl = sizeof(btGjkPairDetector);
105        int     collisionAlgorithmMaxElementSize = btMax(maxSize,maxSize2);
106        collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3);
107
108        if (constructionInfo.m_stackAlloc)
109        {
110                m_ownsStackAllocator = false;
111                this->m_stackAlloc = constructionInfo.m_stackAlloc;
112        } else
113        {
114                m_ownsStackAllocator = true;
115                void* mem = btAlignedAlloc(sizeof(btStackAlloc),16);
116                m_stackAlloc = new(mem)btStackAlloc(constructionInfo.m_defaultStackAllocatorSize);
117        }
118               
119        if (constructionInfo.m_persistentManifoldPool)
120        {
121                m_ownsPersistentManifoldPool = false;
122                m_persistentManifoldPool = constructionInfo.m_persistentManifoldPool;
123        } else
124        {
125                m_ownsPersistentManifoldPool = true;
126                void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
127                m_persistentManifoldPool = new (mem) btPoolAllocator(sizeof(btPersistentManifold),constructionInfo.m_defaultMaxPersistentManifoldPoolSize);
128        }
129       
130        if (constructionInfo.m_collisionAlgorithmPool)
131        {
132                m_ownsCollisionAlgorithmPool = false;
133                m_collisionAlgorithmPool = constructionInfo.m_collisionAlgorithmPool;
134        } else
135        {
136                m_ownsCollisionAlgorithmPool = true;
137                void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
138                m_collisionAlgorithmPool = new(mem) btPoolAllocator(collisionAlgorithmMaxElementSize,constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize);
139        }
140
141
142}
143
144btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
145{
146        if (m_ownsStackAllocator)
147        {
148                m_stackAlloc->destroy();
149                m_stackAlloc->~btStackAlloc();
150                btAlignedFree(m_stackAlloc);
151        }
152        if (m_ownsCollisionAlgorithmPool)
153        {
154                m_collisionAlgorithmPool->~btPoolAllocator();
155                btAlignedFree(m_collisionAlgorithmPool);
156        }
157        if (m_ownsPersistentManifoldPool)
158        {
159                m_persistentManifoldPool->~btPoolAllocator();
160                btAlignedFree(m_persistentManifoldPool);
161        }
162
163        m_convexConvexCreateFunc->~btCollisionAlgorithmCreateFunc();
164        btAlignedFree(  m_convexConvexCreateFunc);
165
166        m_convexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
167        btAlignedFree( m_convexConcaveCreateFunc);
168        m_swappedConvexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
169        btAlignedFree( m_swappedConvexConcaveCreateFunc);
170
171        m_compoundCreateFunc->~btCollisionAlgorithmCreateFunc();
172        btAlignedFree( m_compoundCreateFunc);
173
174        m_swappedCompoundCreateFunc->~btCollisionAlgorithmCreateFunc();
175        btAlignedFree( m_swappedCompoundCreateFunc);
176
177        m_emptyCreateFunc->~btCollisionAlgorithmCreateFunc();
178        btAlignedFree( m_emptyCreateFunc);
179
180        m_sphereSphereCF->~btCollisionAlgorithmCreateFunc();
181        btAlignedFree( m_sphereSphereCF);
182
183#ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
184        m_sphereBoxCF->~btCollisionAlgorithmCreateFunc();
185        btAlignedFree( m_sphereBoxCF);
186        m_boxSphereCF->~btCollisionAlgorithmCreateFunc();
187        btAlignedFree( m_boxSphereCF);
188#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
189
190        m_sphereTriangleCF->~btCollisionAlgorithmCreateFunc();
191        btAlignedFree( m_sphereTriangleCF);
192        m_triangleSphereCF->~btCollisionAlgorithmCreateFunc();
193        btAlignedFree( m_triangleSphereCF);
194        m_boxBoxCF->~btCollisionAlgorithmCreateFunc();
195        btAlignedFree( m_boxBoxCF);
196
197        m_convexPlaneCF->~btCollisionAlgorithmCreateFunc();
198        btAlignedFree( m_convexPlaneCF);
199        m_planeConvexCF->~btCollisionAlgorithmCreateFunc();
200        btAlignedFree( m_planeConvexCF);
201
202        m_simplexSolver->~btVoronoiSimplexSolver();
203        btAlignedFree(m_simplexSolver);
204
205        m_pdSolver->~btConvexPenetrationDepthSolver();
206       
207        btAlignedFree(m_pdSolver);
208
209
210}
211
212
213btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1)
214{
215
216
217
218        if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1==SPHERE_SHAPE_PROXYTYPE))
219        {
220                return  m_sphereSphereCF;
221        }
222#ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
223        if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1==BOX_SHAPE_PROXYTYPE))
224        {
225                return  m_sphereBoxCF;
226        }
227
228        if ((proxyType0 == BOX_SHAPE_PROXYTYPE ) && (proxyType1==SPHERE_SHAPE_PROXYTYPE))
229        {
230                return  m_boxSphereCF;
231        }
232#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
233
234
235        if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE ) && (proxyType1==TRIANGLE_SHAPE_PROXYTYPE))
236        {
237                return  m_sphereTriangleCF;
238        }
239
240        if ((proxyType0 == TRIANGLE_SHAPE_PROXYTYPE  ) && (proxyType1==SPHERE_SHAPE_PROXYTYPE))
241        {
242                return  m_triangleSphereCF;
243        } 
244
245        if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
246        {
247                return m_boxBoxCF;
248        }
249       
250        if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE))
251        {
252                return m_convexPlaneCF;
253        }
254
255        if (btBroadphaseProxy::isConvex(proxyType1) && (proxyType0 == STATIC_PLANE_PROXYTYPE))
256        {
257                return m_planeConvexCF;
258        }
259       
260
261
262        if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConvex(proxyType1))
263        {
264                return m_convexConvexCreateFunc;
265        }
266
267        if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConcave(proxyType1))
268        {
269                return m_convexConcaveCreateFunc;
270        }
271
272        if (btBroadphaseProxy::isConvex(proxyType1) && btBroadphaseProxy::isConcave(proxyType0))
273        {
274                return m_swappedConvexConcaveCreateFunc;
275        }
276
277        if (btBroadphaseProxy::isCompound(proxyType0))
278        {
279                return m_compoundCreateFunc;
280        } else
281        {
282                if (btBroadphaseProxy::isCompound(proxyType1))
283                {
284                        return m_swappedCompoundCreateFunc;
285                }
286        }
287
288        //failed to find an algorithm
289        return m_emptyCreateFunc;
290}
Note: See TracBrowser for help on using the repository browser.