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 00017 #include "btSphereTriangleCollisionAlgorithm.h" 00018 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h" 00019 #include "BulletCollision/CollisionShapes/btSphereShape.h" 00020 #include "BulletCollision/CollisionDispatch/btCollisionObject.h" 00021 #include "SphereTriangleDetector.h" 00022 00023 00024 btSphereTriangleCollisionAlgorithm::btSphereTriangleCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1,bool swapped) 00025 : btActivatingCollisionAlgorithm(ci,col0,col1), 00026 m_ownManifold(false), 00027 m_manifoldPtr(mf), 00028 m_swapped(swapped) 00029 { 00030 if (!m_manifoldPtr) 00031 { 00032 m_manifoldPtr = m_dispatcher->getNewManifold(col0,col1); 00033 m_ownManifold = true; 00034 } 00035 } 00036 00037 btSphereTriangleCollisionAlgorithm::~btSphereTriangleCollisionAlgorithm() 00038 { 00039 if (m_ownManifold) 00040 { 00041 if (m_manifoldPtr) 00042 m_dispatcher->releaseManifold(m_manifoldPtr); 00043 } 00044 } 00045 00046 void btSphereTriangleCollisionAlgorithm::processCollision (btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) 00047 { 00048 if (!m_manifoldPtr) 00049 return; 00050 00051 btCollisionObject* sphereObj = m_swapped? col1 : col0; 00052 btCollisionObject* triObj = m_swapped? col0 : col1; 00053 00054 btSphereShape* sphere = (btSphereShape*)sphereObj->getCollisionShape(); 00055 btTriangleShape* triangle = (btTriangleShape*)triObj->getCollisionShape(); 00056 00058 resultOut->setPersistentManifold(m_manifoldPtr); 00059 SphereTriangleDetector detector(sphere,triangle, m_manifoldPtr->getContactBreakingThreshold()); 00060 00061 btDiscreteCollisionDetectorInterface::ClosestPointInput input; 00062 input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT); 00063 input.m_transformA = sphereObj->getWorldTransform(); 00064 input.m_transformB = triObj->getWorldTransform(); 00065 00066 bool swapResults = m_swapped; 00067 00068 detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw,swapResults); 00069 00070 if (m_ownManifold) 00071 resultOut->refreshContactPoints(); 00072 00073 } 00074 00075 btScalar btSphereTriangleCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) 00076 { 00077 (void)resultOut; 00078 (void)dispatchInfo; 00079 (void)col0; 00080 (void)col1; 00081 00082 //not yet 00083 return btScalar(1.); 00084 }