Back to index

supertuxkart  0.5+dfsg1
btSphereSphereCollisionAlgorithm.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 #include "btSphereSphereCollisionAlgorithm.h"
00017 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
00018 #include "BulletCollision/CollisionShapes/btSphereShape.h"
00019 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
00020 
00021 btSphereSphereCollisionAlgorithm::btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1)
00022 : btCollisionAlgorithm(ci),
00023 m_ownManifold(false),
00024 m_manifoldPtr(mf)
00025 {
00026        if (!m_manifoldPtr)
00027        {
00028               m_manifoldPtr = m_dispatcher->getNewManifold(col0,col1);
00029               m_ownManifold = true;
00030        }
00031 }
00032 
00033 btSphereSphereCollisionAlgorithm::~btSphereSphereCollisionAlgorithm()
00034 {
00035        if (m_ownManifold)
00036        {
00037               if (m_manifoldPtr)
00038                      m_dispatcher->releaseManifold(m_manifoldPtr);
00039        }
00040 }
00041 
00042 void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
00043 {
00044        (void)dispatchInfo;
00045 
00046        if (!m_manifoldPtr)
00047               return;
00048 
00049        resultOut->setPersistentManifold(m_manifoldPtr);
00050 
00051        btSphereShape* sphere0 = (btSphereShape*)col0->getCollisionShape();
00052        btSphereShape* sphere1 = (btSphereShape*)col1->getCollisionShape();
00053 
00054        btVector3 diff = col0->getWorldTransform().getOrigin()-  col1->getWorldTransform().getOrigin();
00055        btScalar len = diff.length();
00056        btScalar radius0 = sphere0->getRadius();
00057        btScalar radius1 = sphere1->getRadius();
00058 
00059        m_manifoldPtr->clearManifold();
00060 
00062        if ( len > (radius0+radius1))
00063        {
00064               return;
00065        }
00067        btScalar dist = len - (radius0+radius1);
00068 
00069        btVector3 normalOnSurfaceB(1,0,0);
00070        if (len > SIMD_EPSILON)
00071        {
00072               normalOnSurfaceB = diff / len;
00073        }
00074 
00076        btVector3 pos0 = col0->getWorldTransform().getOrigin() - radius0 * normalOnSurfaceB;
00078        btVector3 pos1 = col1->getWorldTransform().getOrigin() + radius1* normalOnSurfaceB;
00079 
00081        
00082        
00083        resultOut->addContactPoint(normalOnSurfaceB,pos1,dist);
00084 
00085        //no resultOut->refreshContactPoints(); needed, because of clearManifold (all points are new)
00086 
00087 }
00088 
00089 btScalar btSphereSphereCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
00090 {
00091        (void)col0;
00092        (void)col1;
00093        (void)dispatchInfo;
00094        (void)resultOut;
00095 
00096        //not yet
00097        return btScalar(1.);
00098 }