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 "btSoftBodyRigidBodyCollisionConfiguration.h" 00017 #include "btSoftRigidCollisionAlgorithm.h" 00018 #include "btSoftBodyConcaveCollisionAlgorithm.h" 00019 #include "btSoftSoftCollisionAlgorithm.h" 00020 00021 #include "LinearMath/btPoolAllocator.h" 00022 00023 #define ENABLE_SOFTBODY_CONCAVE_COLLISIONS 1 00024 00025 btSoftBodyRigidBodyCollisionConfiguration::btSoftBodyRigidBodyCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo) 00026 :btDefaultCollisionConfiguration(constructionInfo) 00027 { 00028 void* mem; 00029 00030 mem = btAlignedAlloc(sizeof(btSoftSoftCollisionAlgorithm::CreateFunc),16); 00031 m_softSoftCreateFunc = new(mem) btSoftSoftCollisionAlgorithm::CreateFunc; 00032 00033 mem = btAlignedAlloc(sizeof(btSoftRigidCollisionAlgorithm::CreateFunc),16); 00034 m_softRigidConvexCreateFunc = new(mem) btSoftRigidCollisionAlgorithm::CreateFunc; 00035 00036 mem = btAlignedAlloc(sizeof(btSoftRigidCollisionAlgorithm::CreateFunc),16); 00037 m_swappedSoftRigidConvexCreateFunc = new(mem) btSoftRigidCollisionAlgorithm::CreateFunc; 00038 m_swappedSoftRigidConvexCreateFunc->m_swapped=true; 00039 00040 #ifdef ENABLE_SOFTBODY_CONCAVE_COLLISIONS 00041 mem = btAlignedAlloc(sizeof(btSoftBodyConcaveCollisionAlgorithm::CreateFunc),16); 00042 m_softRigidConcaveCreateFunc = new(mem) btSoftBodyConcaveCollisionAlgorithm::CreateFunc; 00043 00044 mem = btAlignedAlloc(sizeof(btSoftBodyConcaveCollisionAlgorithm::CreateFunc),16); 00045 m_swappedSoftRigidConcaveCreateFunc = new(mem) btSoftBodyConcaveCollisionAlgorithm::SwappedCreateFunc; 00046 m_swappedSoftRigidConcaveCreateFunc->m_swapped=true; 00047 #endif 00048 00049 //replace pool by a new one, with potential larger size 00050 00051 if (m_ownsCollisionAlgorithmPool && m_collisionAlgorithmPool) 00052 { 00053 int curElemSize = m_collisionAlgorithmPool->getElementSize(); 00055 00056 00057 int maxSize0 = sizeof(btSoftSoftCollisionAlgorithm); 00058 int maxSize1 = sizeof(btSoftRigidCollisionAlgorithm); 00059 int maxSize2 = sizeof(btSoftBodyConcaveCollisionAlgorithm); 00060 00061 int collisionAlgorithmMaxElementSize = btMax(maxSize0,maxSize1); 00062 collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2); 00063 00064 if (collisionAlgorithmMaxElementSize > curElemSize) 00065 { 00066 m_collisionAlgorithmPool->~btPoolAllocator(); 00067 btAlignedFree(m_collisionAlgorithmPool); 00068 void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16); 00069 m_collisionAlgorithmPool = new(mem) btPoolAllocator(collisionAlgorithmMaxElementSize,constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize); 00070 } 00071 } 00072 00073 } 00074 00075 btSoftBodyRigidBodyCollisionConfiguration::~btSoftBodyRigidBodyCollisionConfiguration() 00076 { 00077 m_softSoftCreateFunc->~btCollisionAlgorithmCreateFunc(); 00078 btAlignedFree( m_softSoftCreateFunc); 00079 00080 m_softRigidConvexCreateFunc->~btCollisionAlgorithmCreateFunc(); 00081 btAlignedFree( m_softRigidConvexCreateFunc); 00082 00083 m_swappedSoftRigidConvexCreateFunc->~btCollisionAlgorithmCreateFunc(); 00084 btAlignedFree( m_swappedSoftRigidConvexCreateFunc); 00085 00086 #ifdef ENABLE_SOFTBODY_CONCAVE_COLLISIONS 00087 m_softRigidConcaveCreateFunc->~btCollisionAlgorithmCreateFunc(); 00088 btAlignedFree( m_softRigidConcaveCreateFunc); 00089 00090 m_swappedSoftRigidConcaveCreateFunc->~btCollisionAlgorithmCreateFunc(); 00091 btAlignedFree( m_swappedSoftRigidConcaveCreateFunc); 00092 #endif 00093 } 00094 00096 btCollisionAlgorithmCreateFunc* btSoftBodyRigidBodyCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1) 00097 { 00098 00100 00101 if ((proxyType0 == SOFTBODY_SHAPE_PROXYTYPE ) && (proxyType1==SOFTBODY_SHAPE_PROXYTYPE)) 00102 { 00103 return m_softSoftCreateFunc; 00104 } 00105 00107 if (proxyType0 == SOFTBODY_SHAPE_PROXYTYPE && btBroadphaseProxy::isConvex(proxyType1)) 00108 { 00109 return m_softRigidConvexCreateFunc; 00110 } 00111 00113 if (btBroadphaseProxy::isConvex(proxyType0) && proxyType1 == SOFTBODY_SHAPE_PROXYTYPE ) 00114 { 00115 return m_swappedSoftRigidConvexCreateFunc; 00116 } 00117 00118 #ifdef ENABLE_SOFTBODY_CONCAVE_COLLISIONS 00119 00120 if (proxyType0 == SOFTBODY_SHAPE_PROXYTYPE && btBroadphaseProxy::isConcave(proxyType1)) 00121 { 00122 return m_softRigidConcaveCreateFunc; 00123 } 00124 00126 if (btBroadphaseProxy::isConcave(proxyType0) && proxyType1 == SOFTBODY_SHAPE_PROXYTYPE ) 00127 { 00128 return m_swappedSoftRigidConcaveCreateFunc; 00129 } 00130 #endif 00131 00133 return btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(proxyType0,proxyType1); 00134 }