btSphereSphereCollisionAlgorithm.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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();
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
00104 return btScalar(1.);
00105 }