BuoyantShapeConvexCollisionAlgorithm.cpp
Go to the documentation of this file.
00001 /*
00002  BuoyantShape vs ConvexSHape collision algorithm added to Experimental Buoyancy fluid demo.
00003  */
00004 #include <stdio.h>
00005 
00006 #include <uwsim/BulletHfFluid/btHfFluidBuoyantShapeCollisionAlgorithm.h>
00007 #include <uwsim/BulletHfFluid/BuoyantShapeConvexCollisionAlgorithm.h>
00008 #include <uwsim/BulletHfFluid/btHfFluidBuoyantConvexShape.h>
00009 #include <BulletCollision/CollisionDispatch/btCollisionDispatcher.h>
00010 #include <BulletCollision/CollisionShapes/btSphereShape.h>
00011 #include <BulletCollision/CollisionShapes/btBoxShape.h>
00012 
00013 #include <BulletCollision/CollisionDispatch/btCollisionObject.h>
00014 #include <BulletDynamics/Dynamics/btRigidBody.h>
00015 #include <uwsim/BulletHfFluid/btHfFluid.h>
00016 
00017 #include <iostream>
00018 
00019 BuoyantShapeConvexCollisionAlgorithm::BuoyantShapeConvexCollisionAlgorithm(
00020     const btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* col0, btCollisionObject* col1,
00021     btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver, bool isSwapped, int proxyType) :
00022     btCollisionAlgorithm(ci), m_isSwapped(isSwapped), m_proxyType(proxyType)
00023 {
00024 
00025   if (!isSwapped)
00026   {
00027     m_collisionObject0 = col0;
00028     m_collisionObject1 = col1;
00029   }
00030   else
00031   {
00032     m_collisionObject0 = col1;
00033     m_collisionObject1 = col0;
00034   }
00035 
00036   if (proxyType == COMPOUND_SHAPE_PROXYTYPE)
00037     m_collisionAlgorithm = new btCompoundCollisionAlgorithm(ci, m_collisionObject0, m_collisionObject1, isSwapped);
00038   else if (proxyType == TRIANGLE_MESH_SHAPE_PROXYTYPE)
00039     m_collisionAlgorithm = new btConvexConcaveCollisionAlgorithm(ci, m_collisionObject1, m_collisionObject0, isSwapped);
00040   else if (proxyType == CONVEX_SHAPE_PROXYTYPE)
00041     m_collisionAlgorithm = new btConvexConvexAlgorithm(NULL, ci, m_collisionObject0, m_collisionObject1, simplexSolver,
00042                                                        pdSolver, 0, 0);
00043 }
00044 
00045 BuoyantShapeConvexCollisionAlgorithm::~BuoyantShapeConvexCollisionAlgorithm()
00046 {
00047 }
00048 
00049 void BuoyantShapeConvexCollisionAlgorithm::processCollision(btCollisionObject* body0, btCollisionObject* body1,
00050                                                             const btDispatcherInfo& dispatchInfo,
00051                                                             btManifoldResult* resultOut)
00052 {
00053 
00054   btHfFluidBuoyantConvexShape* tmpShape0 = (btHfFluidBuoyantConvexShape*)m_collisionObject0->getCollisionShape();
00055   //btHfFluidBuoyantConvexShape* tmpShape1 = (btHfFluidBuoyantConvexShape*)body1->getCollisionShape();
00056   btConvexShape* convexShape0 = tmpShape0->getConvexShape();
00057   //btConvexShape* convexShape1 = tmpShape1->getConvexShape();
00058 
00059   m_collisionObject0->setCollisionShape(convexShape0);
00060   //body1->setCollisionShape (convexShape1);
00061 
00062   if (m_proxyType == COMPOUND_SHAPE_PROXYTYPE)
00063     m_collisionAlgorithm->processCollision(m_collisionObject0, m_collisionObject1, dispatchInfo, resultOut);
00064   else if (m_proxyType == TRIANGLE_MESH_SHAPE_PROXYTYPE)
00065     m_collisionAlgorithm->processCollision(m_collisionObject1, m_collisionObject0, dispatchInfo, resultOut);
00066   else if (m_proxyType == CONVEX_SHAPE_PROXYTYPE)
00067   {
00068     m_collisionAlgorithm->processCollision(m_collisionObject0, m_collisionObject1, dispatchInfo, resultOut);
00069   }
00070 
00071   m_collisionObject0->setCollisionShape(tmpShape0);
00072   //body1->setCollisionShape (tmpShape1);
00073 
00074 }
00075 
00076 btScalar BuoyantShapeConvexCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1,
00077                                                                      const btDispatcherInfo& dispatchInfo,
00078                                                                      btManifoldResult* resultOut)
00079 {
00080   btHfFluidBuoyantConvexShape* tmpShape0 = (btHfFluidBuoyantConvexShape*)m_collisionObject0->getCollisionShape();
00081   //btHfFluidBuoyantConvexShape* tmpShape1 = (btHfFluidBuoyantConvexShape*)body1->getCollisionShape();
00082   btConvexShape* convexShape0 = tmpShape0->getConvexShape();
00083   //btConvexShape* convexShape1 = tmpShape1->getConvexShape();
00084 
00085   m_collisionObject0->setCollisionShape(convexShape0);
00086   //body1->setCollisionShape (convexShape1);
00087 
00088   btScalar toi = btScalar(0.0f);
00089 
00090   //toi = m_convexConvexAlgorithm.calculateTimeOfImpact (body0, body1, dispatchInfo, resultOut);
00091 
00092   if (m_proxyType == COMPOUND_SHAPE_PROXYTYPE)
00093     toi = m_collisionAlgorithm->calculateTimeOfImpact(m_collisionObject0, m_collisionObject1, dispatchInfo, resultOut);
00094   else if (m_proxyType == TRIANGLE_MESH_SHAPE_PROXYTYPE)
00095     toi = m_collisionAlgorithm->calculateTimeOfImpact(m_collisionObject1, m_collisionObject0, dispatchInfo, resultOut);
00096   else if (m_proxyType == CONVEX_SHAPE_PROXYTYPE)
00097     toi = m_collisionAlgorithm->calculateTimeOfImpact(m_collisionObject0, m_collisionObject1, dispatchInfo, resultOut);
00098 
00099   m_collisionObject0->setCollisionShape(tmpShape0);
00100   //body1->setCollisionShape (tmpShape1);
00101 
00102   return toi;
00103 }


uwsim
Author(s): Mario Prats
autogenerated on Mon Oct 6 2014 08:24:07