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 : btActivatingCollisionAlgorithm(ci,col0,col1),
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 #ifdef CLEAR_MANIFOLD
00060         m_manifoldPtr->clearManifold(); //don't do this, it disables warmstarting
00061 #endif
00062 
00064         if ( len > (radius0+radius1))
00065         {
00066 #ifndef CLEAR_MANIFOLD
00067                 resultOut->refreshContactPoints();
00068 #endif //CLEAR_MANIFOLD
00069                 return;
00070         }
00072         btScalar dist = len - (radius0+radius1);
00073 
00074         btVector3 normalOnSurfaceB(1,0,0);
00075         if (len > SIMD_EPSILON)
00076         {
00077                 normalOnSurfaceB = diff / len;
00078         }
00079 
00083         btVector3 pos1 = col1->getWorldTransform().getOrigin() + radius1* normalOnSurfaceB;
00084 
00086         
00087         
00088         resultOut->addContactPoint(normalOnSurfaceB,pos1,dist);
00089 
00090 #ifndef CLEAR_MANIFOLD
00091         resultOut->refreshContactPoints();
00092 #endif //CLEAR_MANIFOLD
00093 
00094 }
00095 
00096 btScalar btSphereSphereCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
00097 {
00098         (void)col0;
00099         (void)col1;
00100         (void)dispatchInfo;
00101         (void)resultOut;
00102 
00103         //not yet
00104         return btScalar(1.);
00105 }

Generated on Mon Feb 15 22:17:06 2010 for Bullet Collision Detection & Physics Library by  doxygen 1.6.1