Blender V2.61 - r43446
|
00001 /* 00002 Bullet Continuous Collision Detection and Physics Library 00003 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ 00004 00005 This software is provided 'as-is', without any express or implied warranty. 00006 In no event will the authors be held liable for any damages arising from the use of this software. 00007 Permission is granted to anyone to use this software for any purpose, 00008 including commercial applications, and to alter it and redistribute it freely, 00009 subject to the following restrictions: 00010 00011 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. 00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 00013 3. This notice may not be removed or altered from any source distribution. 00014 */ 00015 00016 #include "btDefaultCollisionConfiguration.h" 00017 00018 #include "BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h" 00019 #include "BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h" 00020 #include "BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h" 00021 #include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h" 00022 #include "BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h" 00023 #include "BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h" 00024 #include "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h" 00025 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM 00026 #include "BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h" 00027 #endif //USE_BUGGY_SPHERE_BOX_ALGORITHM 00028 #include "BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h" 00029 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h" 00030 #include "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h" 00031 #include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" 00032 00033 00034 00035 #include "LinearMath/btStackAlloc.h" 00036 #include "LinearMath/btPoolAllocator.h" 00037 00038 00039 00040 00041 00042 btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo) 00043 //btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(btStackAlloc* stackAlloc,btPoolAllocator* persistentManifoldPool,btPoolAllocator* collisionAlgorithmPool) 00044 { 00045 00046 void* mem = btAlignedAlloc(sizeof(btVoronoiSimplexSolver),16); 00047 m_simplexSolver = new (mem)btVoronoiSimplexSolver(); 00048 00049 if (constructionInfo.m_useEpaPenetrationAlgorithm) 00050 { 00051 mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16); 00052 m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver; 00053 }else 00054 { 00055 mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16); 00056 m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver; 00057 } 00058 00059 //default CreationFunctions, filling the m_doubleDispatch table 00060 mem = btAlignedAlloc(sizeof(btConvexConvexAlgorithm::CreateFunc),16); 00061 m_convexConvexCreateFunc = new(mem) btConvexConvexAlgorithm::CreateFunc(m_simplexSolver,m_pdSolver); 00062 mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16); 00063 m_convexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::CreateFunc; 00064 mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16); 00065 m_swappedConvexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::SwappedCreateFunc; 00066 mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::CreateFunc),16); 00067 m_compoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::CreateFunc; 00068 mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::SwappedCreateFunc),16); 00069 m_swappedCompoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::SwappedCreateFunc; 00070 mem = btAlignedAlloc(sizeof(btEmptyAlgorithm::CreateFunc),16); 00071 m_emptyCreateFunc = new(mem) btEmptyAlgorithm::CreateFunc; 00072 00073 mem = btAlignedAlloc(sizeof(btSphereSphereCollisionAlgorithm::CreateFunc),16); 00074 m_sphereSphereCF = new(mem) btSphereSphereCollisionAlgorithm::CreateFunc; 00075 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM 00076 mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc),16); 00077 m_sphereBoxCF = new(mem) btSphereBoxCollisionAlgorithm::CreateFunc; 00078 mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc),16); 00079 m_boxSphereCF = new (mem)btSphereBoxCollisionAlgorithm::CreateFunc; 00080 m_boxSphereCF->m_swapped = true; 00081 #endif //USE_BUGGY_SPHERE_BOX_ALGORITHM 00082 00083 mem = btAlignedAlloc(sizeof(btSphereTriangleCollisionAlgorithm::CreateFunc),16); 00084 m_sphereTriangleCF = new (mem)btSphereTriangleCollisionAlgorithm::CreateFunc; 00085 mem = btAlignedAlloc(sizeof(btSphereTriangleCollisionAlgorithm::CreateFunc),16); 00086 m_triangleSphereCF = new (mem)btSphereTriangleCollisionAlgorithm::CreateFunc; 00087 m_triangleSphereCF->m_swapped = true; 00088 00089 mem = btAlignedAlloc(sizeof(btBoxBoxCollisionAlgorithm::CreateFunc),16); 00090 m_boxBoxCF = new(mem)btBoxBoxCollisionAlgorithm::CreateFunc; 00091 00092 //convex versus plane 00093 mem = btAlignedAlloc (sizeof(btConvexPlaneCollisionAlgorithm::CreateFunc),16); 00094 m_convexPlaneCF = new (mem) btConvexPlaneCollisionAlgorithm::CreateFunc; 00095 mem = btAlignedAlloc (sizeof(btConvexPlaneCollisionAlgorithm::CreateFunc),16); 00096 m_planeConvexCF = new (mem) btConvexPlaneCollisionAlgorithm::CreateFunc; 00097 m_planeConvexCF->m_swapped = true; 00098 00100 int maxSize = sizeof(btConvexConvexAlgorithm); 00101 int maxSize2 = sizeof(btConvexConcaveCollisionAlgorithm); 00102 int maxSize3 = sizeof(btCompoundCollisionAlgorithm); 00103 int sl = sizeof(btConvexSeparatingDistanceUtil); 00104 sl = sizeof(btGjkPairDetector); 00105 int collisionAlgorithmMaxElementSize = btMax(maxSize,constructionInfo.m_customCollisionAlgorithmMaxElementSize); 00106 collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2); 00107 collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3); 00108 00109 if (constructionInfo.m_stackAlloc) 00110 { 00111 m_ownsStackAllocator = false; 00112 this->m_stackAlloc = constructionInfo.m_stackAlloc; 00113 } else 00114 { 00115 m_ownsStackAllocator = true; 00116 void* mem = btAlignedAlloc(sizeof(btStackAlloc),16); 00117 m_stackAlloc = new(mem)btStackAlloc(constructionInfo.m_defaultStackAllocatorSize); 00118 } 00119 00120 if (constructionInfo.m_persistentManifoldPool) 00121 { 00122 m_ownsPersistentManifoldPool = false; 00123 m_persistentManifoldPool = constructionInfo.m_persistentManifoldPool; 00124 } else 00125 { 00126 m_ownsPersistentManifoldPool = true; 00127 void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16); 00128 m_persistentManifoldPool = new (mem) btPoolAllocator(sizeof(btPersistentManifold),constructionInfo.m_defaultMaxPersistentManifoldPoolSize); 00129 } 00130 00131 if (constructionInfo.m_collisionAlgorithmPool) 00132 { 00133 m_ownsCollisionAlgorithmPool = false; 00134 m_collisionAlgorithmPool = constructionInfo.m_collisionAlgorithmPool; 00135 } else 00136 { 00137 m_ownsCollisionAlgorithmPool = true; 00138 void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16); 00139 m_collisionAlgorithmPool = new(mem) btPoolAllocator(collisionAlgorithmMaxElementSize,constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize); 00140 } 00141 00142 00143 } 00144 00145 btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration() 00146 { 00147 if (m_ownsStackAllocator) 00148 { 00149 m_stackAlloc->destroy(); 00150 m_stackAlloc->~btStackAlloc(); 00151 btAlignedFree(m_stackAlloc); 00152 } 00153 if (m_ownsCollisionAlgorithmPool) 00154 { 00155 m_collisionAlgorithmPool->~btPoolAllocator(); 00156 btAlignedFree(m_collisionAlgorithmPool); 00157 } 00158 if (m_ownsPersistentManifoldPool) 00159 { 00160 m_persistentManifoldPool->~btPoolAllocator(); 00161 btAlignedFree(m_persistentManifoldPool); 00162 } 00163 00164 m_convexConvexCreateFunc->~btCollisionAlgorithmCreateFunc(); 00165 btAlignedFree( m_convexConvexCreateFunc); 00166 00167 m_convexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc(); 00168 btAlignedFree( m_convexConcaveCreateFunc); 00169 m_swappedConvexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc(); 00170 btAlignedFree( m_swappedConvexConcaveCreateFunc); 00171 00172 m_compoundCreateFunc->~btCollisionAlgorithmCreateFunc(); 00173 btAlignedFree( m_compoundCreateFunc); 00174 00175 m_swappedCompoundCreateFunc->~btCollisionAlgorithmCreateFunc(); 00176 btAlignedFree( m_swappedCompoundCreateFunc); 00177 00178 m_emptyCreateFunc->~btCollisionAlgorithmCreateFunc(); 00179 btAlignedFree( m_emptyCreateFunc); 00180 00181 m_sphereSphereCF->~btCollisionAlgorithmCreateFunc(); 00182 btAlignedFree( m_sphereSphereCF); 00183 00184 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM 00185 m_sphereBoxCF->~btCollisionAlgorithmCreateFunc(); 00186 btAlignedFree( m_sphereBoxCF); 00187 m_boxSphereCF->~btCollisionAlgorithmCreateFunc(); 00188 btAlignedFree( m_boxSphereCF); 00189 #endif //USE_BUGGY_SPHERE_BOX_ALGORITHM 00190 00191 m_sphereTriangleCF->~btCollisionAlgorithmCreateFunc(); 00192 btAlignedFree( m_sphereTriangleCF); 00193 m_triangleSphereCF->~btCollisionAlgorithmCreateFunc(); 00194 btAlignedFree( m_triangleSphereCF); 00195 m_boxBoxCF->~btCollisionAlgorithmCreateFunc(); 00196 btAlignedFree( m_boxBoxCF); 00197 00198 m_convexPlaneCF->~btCollisionAlgorithmCreateFunc(); 00199 btAlignedFree( m_convexPlaneCF); 00200 m_planeConvexCF->~btCollisionAlgorithmCreateFunc(); 00201 btAlignedFree( m_planeConvexCF); 00202 00203 m_simplexSolver->~btVoronoiSimplexSolver(); 00204 btAlignedFree(m_simplexSolver); 00205 00206 m_pdSolver->~btConvexPenetrationDepthSolver(); 00207 00208 btAlignedFree(m_pdSolver); 00209 00210 00211 } 00212 00213 00214 btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1) 00215 { 00216 00217 00218 00219 if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1==SPHERE_SHAPE_PROXYTYPE)) 00220 { 00221 return m_sphereSphereCF; 00222 } 00223 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM 00224 if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1==BOX_SHAPE_PROXYTYPE)) 00225 { 00226 return m_sphereBoxCF; 00227 } 00228 00229 if ((proxyType0 == BOX_SHAPE_PROXYTYPE ) && (proxyType1==SPHERE_SHAPE_PROXYTYPE)) 00230 { 00231 return m_boxSphereCF; 00232 } 00233 #endif //USE_BUGGY_SPHERE_BOX_ALGORITHM 00234 00235 00236 if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE ) && (proxyType1==TRIANGLE_SHAPE_PROXYTYPE)) 00237 { 00238 return m_sphereTriangleCF; 00239 } 00240 00241 if ((proxyType0 == TRIANGLE_SHAPE_PROXYTYPE ) && (proxyType1==SPHERE_SHAPE_PROXYTYPE)) 00242 { 00243 return m_triangleSphereCF; 00244 } 00245 00246 if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE)) 00247 { 00248 return m_boxBoxCF; 00249 } 00250 00251 if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE)) 00252 { 00253 return m_convexPlaneCF; 00254 } 00255 00256 if (btBroadphaseProxy::isConvex(proxyType1) && (proxyType0 == STATIC_PLANE_PROXYTYPE)) 00257 { 00258 return m_planeConvexCF; 00259 } 00260 00261 00262 00263 if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConvex(proxyType1)) 00264 { 00265 return m_convexConvexCreateFunc; 00266 } 00267 00268 if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConcave(proxyType1)) 00269 { 00270 return m_convexConcaveCreateFunc; 00271 } 00272 00273 if (btBroadphaseProxy::isConvex(proxyType1) && btBroadphaseProxy::isConcave(proxyType0)) 00274 { 00275 return m_swappedConvexConcaveCreateFunc; 00276 } 00277 00278 if (btBroadphaseProxy::isCompound(proxyType0)) 00279 { 00280 return m_compoundCreateFunc; 00281 } else 00282 { 00283 if (btBroadphaseProxy::isCompound(proxyType1)) 00284 { 00285 return m_swappedCompoundCreateFunc; 00286 } 00287 } 00288 00289 //failed to find an algorithm 00290 return m_emptyCreateFunc; 00291 } 00292 00293 void btDefaultCollisionConfiguration::setConvexConvexMultipointIterations(int numPerturbationIterations, int minimumPointsPerturbationThreshold) 00294 { 00295 btConvexConvexAlgorithm::CreateFunc* convexConvex = (btConvexConvexAlgorithm::CreateFunc*) m_convexConvexCreateFunc; 00296 convexConvex->m_numPerturbationIterations = numPerturbationIterations; 00297 convexConvex->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold; 00298 }