btHfFluidRigidCollisionConfiguration.cpp
Go to the documentation of this file.
00001 /*
00002  Bullet Continuous Collision Detection and Physics Library
00003  Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.com
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  Experimental Buoyancy fluid demo written by John McCutchan
00016  */
00017 
00018 #include <uwsim/BulletHfFluid/btHfFluidRigidCollisionConfiguration.h>
00019 #include <uwsim/BulletHfFluid/btHfFluidRigidCollisionAlgorithm.h>
00020 #include <uwsim/BulletHfFluid/btHfFluidBuoyantShapeCollisionAlgorithm.h>
00021 #include <uwsim/BulletHfFluid/BuoyantShapeConvexCollisionAlgorithm.h>
00022 #include <LinearMath/btPoolAllocator.h>
00023 
00024 #include <iostream>
00025 
00026 btHfFluidRigidCollisionConfiguration::btHfFluidRigidCollisionConfiguration(
00027     const btDefaultCollisionConstructionInfo& constructionInfo) :
00028     btDefaultCollisionConfiguration(constructionInfo)
00029 {
00030 
00031   void* mem;
00032 
00033   mem = btAlignedAlloc(sizeof(btHfFluidRigidCollisionAlgorithm::CreateFunc), 16);
00034   m_hfFluidRigidConvexCreateFunc = new (mem) btHfFluidRigidCollisionAlgorithm::CreateFunc;
00035 
00036   mem = btAlignedAlloc(sizeof(btHfFluidRigidCollisionAlgorithm::CreateFunc), 16);
00037   m_swappedHfFluidRigidConvexCreateFunc = new (mem) btHfFluidRigidCollisionAlgorithm::CreateFunc;
00038   m_swappedHfFluidRigidConvexCreateFunc->m_swapped = true;
00039 
00040   mem = btAlignedAlloc(sizeof(btHfFluidBuoyantShapeCollisionAlgorithm::CreateFunc), 16);
00041   m_hfFluidBuoyantShapeCollisionCreateFunc = new (mem) btHfFluidBuoyantShapeCollisionAlgorithm::CreateFunc(
00042       m_simplexSolver, m_pdSolver);
00043 
00044   //COMPOUND_SHAPE_PROXYTYPE
00045   mem = btAlignedAlloc(sizeof(BuoyantShapeConvexCollisionAlgorithm::CreateFunc), 16);
00046   m_BuoyantShapeCompoundCreateFunc = new (mem) BuoyantShapeConvexCollisionAlgorithm::CreateFunc(
00047       m_simplexSolver, m_pdSolver, COMPOUND_SHAPE_PROXYTYPE);
00048 
00049   mem = btAlignedAlloc(sizeof(BuoyantShapeConvexCollisionAlgorithm::CreateFunc), 16);
00050   m_swappedBuoyantShapeCompoundCreateFunc = new (mem) BuoyantShapeConvexCollisionAlgorithm::CreateFunc(
00051       m_simplexSolver, m_pdSolver, COMPOUND_SHAPE_PROXYTYPE);
00052   m_swappedBuoyantShapeCompoundCreateFunc->m_swapped = true;
00053 
00054   //CONCAVE_SHAPE_PROXYTYPE
00055   mem = btAlignedAlloc(sizeof(BuoyantShapeConvexCollisionAlgorithm::CreateFunc), 16);
00056   m_BuoyantShapeConcaveCreateFunc = new (mem) BuoyantShapeConvexCollisionAlgorithm::CreateFunc(
00057       m_simplexSolver, m_pdSolver, TRIANGLE_MESH_SHAPE_PROXYTYPE);
00058 
00059   mem = btAlignedAlloc(sizeof(BuoyantShapeConvexCollisionAlgorithm::CreateFunc), 16);
00060   m_swappedBuoyantShapeConcaveCreateFunc = new (mem) BuoyantShapeConvexCollisionAlgorithm::CreateFunc(
00061       m_simplexSolver, m_pdSolver, TRIANGLE_MESH_SHAPE_PROXYTYPE);
00062   m_swappedBuoyantShapeConcaveCreateFunc->m_swapped = true;
00063 
00064   //CONVEX_SHAPE_PROXYTYPE
00065   mem = btAlignedAlloc(sizeof(BuoyantShapeConvexCollisionAlgorithm::CreateFunc), 16);
00066   m_BuoyantShapeConvexCreateFunc = new (mem) BuoyantShapeConvexCollisionAlgorithm::CreateFunc(m_simplexSolver,
00067                                                                                               m_pdSolver,
00068                                                                                               CONVEX_SHAPE_PROXYTYPE);
00069 
00070   mem = btAlignedAlloc(sizeof(BuoyantShapeConvexCollisionAlgorithm::CreateFunc), 16);
00071   m_swappedBuoyantShapeConvexCreateFunc = new (mem) BuoyantShapeConvexCollisionAlgorithm::CreateFunc(
00072       m_simplexSolver, m_pdSolver, CONVEX_SHAPE_PROXYTYPE);
00073   m_swappedBuoyantShapeConvexCreateFunc->m_swapped = true;
00074 
00075   if (m_ownsCollisionAlgorithmPool && m_collisionAlgorithmPool)
00076   {
00077     int curElemSize = m_collisionAlgorithmPool->getElementSize();
00079 
00080     int maxSize0 = sizeof(btHfFluidRigidCollisionAlgorithm);
00081     int maxSize1 = sizeof(BuoyantShapeConvexCollisionAlgorithm);
00082     int maxSize2 = 0;
00083 
00084     int collisionAlgorithmMaxElementSize = btMax(maxSize0,maxSize1);
00085     collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2);
00086 
00087     if (collisionAlgorithmMaxElementSize > curElemSize)
00088     {
00089       m_collisionAlgorithmPool->~btPoolAllocator();
00090       btAlignedFree(m_collisionAlgorithmPool);
00091       void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
00092       m_collisionAlgorithmPool = new(mem) btPoolAllocator(collisionAlgorithmMaxElementSize,constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize);
00093     }
00094   }
00095 
00096 }
00097 
00098 btHfFluidRigidCollisionConfiguration::~btHfFluidRigidCollisionConfiguration()
00099 {
00100   m_hfFluidRigidConvexCreateFunc->~btCollisionAlgorithmCreateFunc();
00101   m_swappedHfFluidRigidConvexCreateFunc->~btCollisionAlgorithmCreateFunc();
00102   btAlignedFree (m_hfFluidRigidConvexCreateFunc);
00103   btAlignedFree (m_swappedHfFluidRigidConvexCreateFunc);
00104 }
00105 
00106 btCollisionAlgorithmCreateFunc* btHfFluidRigidCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0,
00107                                                                                                       int proxyType1)
00108 {
00109 
00110   if ((proxyType0 == HFFLUID_SHAPE_PROXYTYPE) && (proxyType1 == HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE))
00111   {
00112     return m_hfFluidRigidConvexCreateFunc;
00113   }
00114 
00115   if ((proxyType0 == HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE) && (proxyType1 == HFFLUID_SHAPE_PROXYTYPE))
00116   {
00117     return m_swappedHfFluidRigidConvexCreateFunc;
00118   }
00119 
00120   if ((proxyType0 == HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE) && (proxyType1 == HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE))
00121   {
00122     return m_hfFluidBuoyantShapeCollisionCreateFunc;
00123   }
00124 
00125   if ((proxyType0 == HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE) && (proxyType1 == COMPOUND_SHAPE_PROXYTYPE))
00126   {
00127     return m_BuoyantShapeCompoundCreateFunc;
00128   }
00129 
00130   if ((proxyType0 == COMPOUND_SHAPE_PROXYTYPE) && (proxyType1 == HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE))
00131   {
00132     return m_swappedBuoyantShapeCompoundCreateFunc;
00133   }
00134 
00135   if ((proxyType0 == HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE) && (proxyType1 == TRIANGLE_MESH_SHAPE_PROXYTYPE))
00136   {
00137     return m_BuoyantShapeConcaveCreateFunc;
00138   }
00139 
00140   if ((proxyType0 == TRIANGLE_MESH_SHAPE_PROXYTYPE) && (proxyType1 == HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE))
00141   {
00142     return m_swappedBuoyantShapeConcaveCreateFunc;
00143   }
00144 
00145   if ((proxyType0 == HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE))
00146   {
00147     return m_BuoyantShapeConvexCreateFunc;
00148   }
00149 
00150   if ((proxyType1 == HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE))
00151   {
00152     return m_swappedBuoyantShapeConvexCreateFunc;
00153   }
00154 
00156   return btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(proxyType0, proxyType1);
00157 }
00158 


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