Back to index

supertuxkart  0.5+dfsg1
btSphereTriangleCollisionAlgorithm.cpp
Go to the documentation of this file.
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 : btCollisionAlgorithm(ci),
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);
00060        
00061        btDiscreteCollisionDetectorInterface::ClosestPointInput input;
00062        input.m_maximumDistanceSquared = btScalar(1e30);//todo: tighter bounds
00063        input.m_transformA = col0->getWorldTransform();
00064        input.m_transformB = col1->getWorldTransform();
00065 
00066        detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
00067 
00068        if (m_ownManifold)
00069               resultOut->refreshContactPoints();
00070        
00071 }
00072 
00073 btScalar btSphereTriangleCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
00074 {
00075        (void)resultOut;
00076        (void)dispatchInfo;
00077        (void)col0;
00078        (void)col1;
00079 
00080        //not yet
00081        return btScalar(1.);
00082 }