Blender V2.61 - r43446

btBoxBoxCollisionAlgorithm.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 "btBoxBoxCollisionAlgorithm.h"
00017 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
00018 #include "BulletCollision/CollisionShapes/btBoxShape.h"
00019 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
00020 #include "btBoxBoxDetector.h"
00021 
00022 #define USE_PERSISTENT_CONTACTS 1
00023 
00024 btBoxBoxCollisionAlgorithm::btBoxBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* obj0,btCollisionObject* obj1)
00025 : btActivatingCollisionAlgorithm(ci,obj0,obj1),
00026 m_ownManifold(false),
00027 m_manifoldPtr(mf)
00028 {
00029     if (!m_manifoldPtr && m_dispatcher->needsCollision(obj0,obj1))
00030     {
00031         m_manifoldPtr = m_dispatcher->getNewManifold(obj0,obj1);
00032         m_ownManifold = true;
00033     }
00034 }
00035 
00036 btBoxBoxCollisionAlgorithm::~btBoxBoxCollisionAlgorithm()
00037 {
00038     if (m_ownManifold)
00039     {
00040         if (m_manifoldPtr)
00041             m_dispatcher->releaseManifold(m_manifoldPtr);
00042     }
00043 }
00044 
00045 void btBoxBoxCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
00046 {
00047     if (!m_manifoldPtr)
00048         return;
00049 
00050     btCollisionObject*  col0 = body0;
00051     btCollisionObject*  col1 = body1;
00052     btBoxShape* box0 = (btBoxShape*)col0->getCollisionShape();
00053     btBoxShape* box1 = (btBoxShape*)col1->getCollisionShape();
00054 
00055 
00056 
00058     resultOut->setPersistentManifold(m_manifoldPtr);
00059 #ifndef USE_PERSISTENT_CONTACTS 
00060     m_manifoldPtr->clearManifold();
00061 #endif //USE_PERSISTENT_CONTACTS
00062 
00063     btDiscreteCollisionDetectorInterface::ClosestPointInput input;
00064     input.m_maximumDistanceSquared = BT_LARGE_FLOAT;
00065     input.m_transformA = body0->getWorldTransform();
00066     input.m_transformB = body1->getWorldTransform();
00067 
00068     btBoxBoxDetector detector(box0,box1);
00069     detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
00070 
00071 #ifdef USE_PERSISTENT_CONTACTS
00072     //  refreshContactPoints is only necessary when using persistent contact points. otherwise all points are newly added
00073     if (m_ownManifold)
00074     {
00075         resultOut->refreshContactPoints();
00076     }
00077 #endif //USE_PERSISTENT_CONTACTS
00078 
00079 }
00080 
00081 btScalar btBoxBoxCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* /*body0*/,btCollisionObject* /*body1*/,const btDispatcherInfo& /*dispatchInfo*/,btManifoldResult* /*resultOut*/)
00082 {
00083     //not yet
00084     return 1.f;
00085 }