Blender V2.61 - r43446

btGhostObject.h

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2008 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 
00016 #ifndef BT_GHOST_OBJECT_H
00017 #define BT_GHOST_OBJECT_H
00018 
00019 
00020 #include "btCollisionObject.h"
00021 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h"
00022 #include "LinearMath/btAlignedAllocator.h"
00023 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
00024 #include "btCollisionWorld.h"
00025 
00026 class btConvexShape;
00027 
00028 class btDispatcher;
00029 
00034 ATTRIBUTE_ALIGNED16(class) btGhostObject : public btCollisionObject
00035 {
00036 protected:
00037 
00038     btAlignedObjectArray<btCollisionObject*> m_overlappingObjects;
00039 
00040 public:
00041 
00042     btGhostObject();
00043 
00044     virtual ~btGhostObject();
00045 
00046     void    convexSweepTest(const class btConvexShape* castShape, const btTransform& convexFromWorld, const btTransform& convexToWorld, btCollisionWorld::ConvexResultCallback& resultCallback, btScalar allowedCcdPenetration = 0.f) const;
00047 
00048     void    rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, btCollisionWorld::RayResultCallback& resultCallback) const; 
00049 
00051     virtual void    addOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btBroadphaseProxy* thisProxy=0);
00053     virtual void    removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy,btDispatcher* dispatcher,btBroadphaseProxy* thisProxy=0);
00054 
00055     int getNumOverlappingObjects() const
00056     {
00057         return m_overlappingObjects.size();
00058     }
00059 
00060     btCollisionObject*  getOverlappingObject(int index)
00061     {
00062         return m_overlappingObjects[index];
00063     }
00064 
00065     const btCollisionObject*    getOverlappingObject(int index) const
00066     {
00067         return m_overlappingObjects[index];
00068     }
00069 
00070     btAlignedObjectArray<btCollisionObject*>&   getOverlappingPairs()
00071     {
00072         return m_overlappingObjects;
00073     }
00074 
00075     const btAlignedObjectArray<btCollisionObject*>  getOverlappingPairs() const
00076     {
00077         return m_overlappingObjects;
00078     }
00079 
00080     //
00081     // internal cast
00082     //
00083 
00084     static const btGhostObject* upcast(const btCollisionObject* colObj)
00085     {
00086         if (colObj->getInternalType()==CO_GHOST_OBJECT)
00087             return (const btGhostObject*)colObj;
00088         return 0;
00089     }
00090     static btGhostObject*           upcast(btCollisionObject* colObj)
00091     {
00092         if (colObj->getInternalType()==CO_GHOST_OBJECT)
00093             return (btGhostObject*)colObj;
00094         return 0;
00095     }
00096 
00097 };
00098 
00099 class   btPairCachingGhostObject : public btGhostObject
00100 {
00101     btHashedOverlappingPairCache*   m_hashPairCache;
00102 
00103 public:
00104 
00105     btPairCachingGhostObject();
00106 
00107     virtual ~btPairCachingGhostObject();
00108 
00110     virtual void    addOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btBroadphaseProxy* thisProxy=0);
00111 
00112     virtual void    removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy,btDispatcher* dispatcher,btBroadphaseProxy* thisProxy=0);
00113 
00114     btHashedOverlappingPairCache*   getOverlappingPairCache()
00115     {
00116         return m_hashPairCache;
00117     }
00118 
00119 };
00120 
00121 
00122 
00124 class btGhostPairCallback : public btOverlappingPairCallback
00125 {
00126     
00127 public:
00128     btGhostPairCallback()
00129     {
00130     }
00131 
00132     virtual ~btGhostPairCallback()
00133     {
00134         
00135     }
00136 
00137     virtual btBroadphasePair*   addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
00138     {
00139         btCollisionObject* colObj0 = (btCollisionObject*) proxy0->m_clientObject;
00140         btCollisionObject* colObj1 = (btCollisionObject*) proxy1->m_clientObject;
00141         btGhostObject* ghost0 =         btGhostObject::upcast(colObj0);
00142         btGhostObject* ghost1 =         btGhostObject::upcast(colObj1);
00143         if (ghost0)
00144             ghost0->addOverlappingObjectInternal(proxy1, proxy0);
00145         if (ghost1)
00146             ghost1->addOverlappingObjectInternal(proxy0, proxy1);
00147         return 0;
00148     }
00149 
00150     virtual void*   removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1,btDispatcher* dispatcher)
00151     {
00152         btCollisionObject* colObj0 = (btCollisionObject*) proxy0->m_clientObject;
00153         btCollisionObject* colObj1 = (btCollisionObject*) proxy1->m_clientObject;
00154         btGhostObject* ghost0 =         btGhostObject::upcast(colObj0);
00155         btGhostObject* ghost1 =         btGhostObject::upcast(colObj1);
00156         if (ghost0)
00157             ghost0->removeOverlappingObjectInternal(proxy1,dispatcher,proxy0);
00158         if (ghost1)
00159             ghost1->removeOverlappingObjectInternal(proxy0,dispatcher,proxy1);
00160         return 0;
00161     }
00162 
00163     virtual void    removeOverlappingPairsContainingProxy(btBroadphaseProxy* /*proxy0*/,btDispatcher* /*dispatcher*/)
00164     {
00165         btAssert(0);
00166         //need to keep track of all ghost objects and call them here
00167         //m_hashPairCache->removeOverlappingPairsContainingProxy(proxy0,dispatcher);
00168     }
00169 
00170     
00171 
00172 };
00173 
00174 #endif
00175