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 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
00022 #define USE_PERSISTENT_CONTACTS 1
00023 
00024 btBoxBoxCollisionAlgorithm::btBoxBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
00025 : btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
00026 m_ownManifold(false),
00027 m_manifoldPtr(mf)
00028 {
00029         if (!m_manifoldPtr && m_dispatcher->needsCollision(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject()))
00030         {
00031                 m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
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 (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
00046 {
00047         if (!m_manifoldPtr)
00048                 return;
00049 
00050         
00051         const btBoxShape* box0 = (btBoxShape*)body0Wrap->getCollisionShape();
00052         const btBoxShape* box1 = (btBoxShape*)body1Wrap->getCollisionShape();
00053 
00054 
00055 
00057         resultOut->setPersistentManifold(m_manifoldPtr);
00058 #ifndef USE_PERSISTENT_CONTACTS 
00059         m_manifoldPtr->clearManifold();
00060 #endif //USE_PERSISTENT_CONTACTS
00061 
00062         btDiscreteCollisionDetectorInterface::ClosestPointInput input;
00063         input.m_maximumDistanceSquared = BT_LARGE_FLOAT;
00064         input.m_transformA = body0Wrap->getWorldTransform();
00065         input.m_transformB = body1Wrap->getWorldTransform();
00066 
00067         btBoxBoxDetector detector(box0,box1);
00068         detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
00069 
00070 #ifdef USE_PERSISTENT_CONTACTS
00071         //  refreshContactPoints is only necessary when using persistent contact points. otherwise all points are newly added
00072         if (m_ownManifold)
00073         {
00074                 resultOut->refreshContactPoints();
00075         }
00076 #endif //USE_PERSISTENT_CONTACTS
00077 
00078 }
00079 
00080 btScalar btBoxBoxCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* /*body0*/,btCollisionObject* /*body1*/,const btDispatcherInfo& /*dispatchInfo*/,btManifoldResult* /*resultOut*/)
00081 {
00082         //not yet
00083         return 1.f;
00084 }