Bullet Collision Detection & Physics Library: btGhostObject.h Source File

Bullet Collision Detection & Physics Library

btGhostObject.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2008 Erwin Coumans http://bulletphysics.com
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15
16 #ifndef BT_GHOST_OBJECT_H
17 #define BT_GHOST_OBJECT_H
18
19
20 #include "btCollisionObject.h"
21 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h"
22 #include "LinearMath/btAlignedAllocator.h"
23 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
24 #include "btCollisionWorld.h"
25
26 class btConvexShape;
27
28 class btDispatcher;
29
34 ATTRIBUTE_ALIGNED16(class) btGhostObject : public btCollisionObject
35 {
36 protected:
37
38 btAlignedObjectArray<btCollisionObject*> m_overlappingObjects;
39
40 public:
41
42 btGhostObject();
43
44 virtual ~btGhostObject();
45
46 void convexSweepTest(const class btConvexShape* castShape, const btTransform& convexFromWorld, const btTransform& convexToWorld, btCollisionWorld::ConvexResultCallback& resultCallback, btScalar allowedCcdPenetration = 0.f) const;
47
48 void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, btCollisionWorld::RayResultCallback& resultCallback) const;
49
51 virtual void addOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btBroadphaseProxy* thisProxy=0);
53 virtual void removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy,btDispatcher* dispatcher,btBroadphaseProxy* thisProxy=0);
54
55 int getNumOverlappingObjects() const
56 {
57 return m_overlappingObjects.size();
58 }
59
60 btCollisionObject* getOverlappingObject(int index)
61 {
62 return m_overlappingObjects[index];
63 }
64
65 const btCollisionObject* getOverlappingObject(int index) const
66 {
67 return m_overlappingObjects[index];
68 }
69
70 btAlignedObjectArray<btCollisionObject*>& getOverlappingPairs()
71 {
72 return m_overlappingObjects;
73 }
74
75 const btAlignedObjectArray<btCollisionObject*> getOverlappingPairs() const
76 {
77 return m_overlappingObjects;
78 }
79
80 //
81 // internal cast
82 //
83
84 static const btGhostObject* upcast(const btCollisionObject* colObj)
85 {
86 if (colObj->getInternalType()==CO_GHOST_OBJECT)
87 return (const btGhostObject*)colObj;
88 return 0;
89 }
90 static btGhostObject* upcast(btCollisionObject* colObj)
91 {
92 if (colObj->getInternalType()==CO_GHOST_OBJECT)
93 return (btGhostObject*)colObj;
94 return 0;
95 }
96
97 };
98
99 class btPairCachingGhostObject : public btGhostObject
100 {
101 btHashedOverlappingPairCache* m_hashPairCache;
102
103 public:
104
105 btPairCachingGhostObject();
106
107 virtual ~btPairCachingGhostObject();
108
110 virtual void addOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btBroadphaseProxy* thisProxy=0);
111
112 virtual void removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy,btDispatcher* dispatcher,btBroadphaseProxy* thisProxy=0);
113
114 btHashedOverlappingPairCache* getOverlappingPairCache()
115 {
116 return m_hashPairCache;
117 }
118
119 };
120
121
122
124 class btGhostPairCallback : public btOverlappingPairCallback
125 {
126
127 public:
128 btGhostPairCallback()
129 {
130 }
131
132 virtual ~btGhostPairCallback()
133 {
134
135 }
136
137 virtual btBroadphasePair* addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
138 {
139 btCollisionObject* colObj0 = (btCollisionObject*) proxy0->m_clientObject;
140 btCollisionObject* colObj1 = (btCollisionObject*) proxy1->m_clientObject;
141 btGhostObject* ghost0 = btGhostObject::upcast(colObj0);
142 btGhostObject* ghost1 = btGhostObject::upcast(colObj1);
143 if (ghost0)
144 ghost0->addOverlappingObjectInternal(proxy1, proxy0);
145 if (ghost1)
146 ghost1->addOverlappingObjectInternal(proxy0, proxy1);
147 return 0;
148 }
149
150 virtual void* removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1,btDispatcher* dispatcher)
151 {
152 btCollisionObject* colObj0 = (btCollisionObject*) proxy0->m_clientObject;
153 btCollisionObject* colObj1 = (btCollisionObject*) proxy1->m_clientObject;
154 btGhostObject* ghost0 = btGhostObject::upcast(colObj0);
155 btGhostObject* ghost1 = btGhostObject::upcast(colObj1);
156 if (ghost0)
157 ghost0->removeOverlappingObjectInternal(proxy1,dispatcher,proxy0);
158 if (ghost1)
159 ghost1->removeOverlappingObjectInternal(proxy0,dispatcher,proxy1);
160 return 0;
161 }
162
163 virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* /*proxy0*/,btDispatcher* /*dispatcher*/)
164 {
165 btAssert(0);
166 //need to keep track of all ghost objects and call them here
167 //m_hashPairCache->removeOverlappingPairsContainingProxy(proxy0,dispatcher);
168 }
169
170
171
172 };
173
174 #endif
175
btGhostPairCallback::addOverlappingPair
virtual btBroadphasePair * addOverlappingPair(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1)
Definition: btGhostObject.h:137
btOverlappingPairCallback.h
btPairCachingGhostObject::~btPairCachingGhostObject
virtual ~btPairCachingGhostObject()
Definition: btGhostObject.cpp:64
btCollisionWorld.h
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:53
btPairCachingGhostObject::removeOverlappingObjectInternal
virtual void removeOverlappingObjectInternal(btBroadphaseProxy *otherProxy, btDispatcher *dispatcher, btBroadphaseProxy *thisProxy=0)
this method is mainly for expert/internal use only.
Definition: btGhostObject.cpp:85
btGhostObject::getOverlappingObject
btCollisionObject * getOverlappingObject(int index)
Definition: btGhostObject.h:60
btGhostObject::getOverlappingObject
const btCollisionObject * getOverlappingObject(int index) const
Definition: btGhostObject.h:65
btAssert
#define btAssert(x)
Definition: btScalar.h:114
btGhostObject::upcast
static btGhostObject * upcast(btCollisionObject *colObj)
Definition: btGhostObject.h:90
btCollisionWorld::RayResultCallback
RayResultCallback is used to report new raycast results.
Definition: btCollisionWorld.h:204
btGhostObject::upcast
static const btGhostObject * upcast(const btCollisionObject *colObj)
Definition: btGhostObject.h:84
btGhostPairCallback::~btGhostPairCallback
virtual ~btGhostPairCallback()
Definition: btGhostObject.h:132
btPairCachingGhostObject::btPairCachingGhostObject
btPairCachingGhostObject()
Definition: btGhostObject.cpp:59
btAlignedAllocator.h
btConvexShape
The btConvexShape is an abstract shape interface, implemented by all convex shapes such as btBoxShape...
Definition: btConvexShape.h:31
btOverlappingPairCache.h
btPairCachingGhostObject::getOverlappingPairCache
btHashedOverlappingPairCache * getOverlappingPairCache()
Definition: btGhostObject.h:114
btGhostPairCallback::removeOverlappingPairsContainingProxy
virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy *, btDispatcher *)
Definition: btGhostObject.h:163
btGhostObject::getOverlappingPairs
btAlignedObjectArray< btCollisionObject * > & getOverlappingPairs()
Definition: btGhostObject.h:70
btGhostPairCallback
The btGhostPairCallback interfaces and forwards adding and removal of overlapping pairs from the btBr...
Definition: btGhostObject.h:124
btGhostObject::getNumOverlappingObjects
int getNumOverlappingObjects() const
Definition: btGhostObject.h:55
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:49
btBroadphaseProxy::m_clientObject
void * m_clientObject
Definition: btBroadphaseProxy.h:103
btPairCachingGhostObject::addOverlappingObjectInternal
virtual void addOverlappingObjectInternal(btBroadphaseProxy *otherProxy, btBroadphaseProxy *thisProxy=0)
this method is mainly for expert/internal use only.
Definition: btGhostObject.cpp:70
btGhostObject::getOverlappingPairs
const btAlignedObjectArray< btCollisionObject * > getOverlappingPairs() const
Definition: btGhostObject.h:75
btBroadphaseProxy
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
Definition: btBroadphaseProxy.h:85
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:65
btAlignedObjectArray::size
int size() const
return the number of elements in the array
Definition: btAlignedObjectArray.h:155
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btGhostObject::removeOverlappingObjectInternal
virtual void removeOverlappingObjectInternal(btBroadphaseProxy *otherProxy, btDispatcher *dispatcher, btBroadphaseProxy *thisProxy=0)
this method is mainly for expert/internal use only.
Definition: btGhostObject.cpp:46
btPairCachingGhostObject::m_hashPairCache
btHashedOverlappingPairCache * m_hashPairCache
Definition: btGhostObject.h:101
btGhostPairCallback::btGhostPairCallback
btGhostPairCallback()
Definition: btGhostObject.h:128
btCollisionObject::getInternalType
int getInternalType() const
reserved for Bullet internal usage
Definition: btCollisionObject.h:365
btCollisionObject.h
btGhostObject
The btGhostObject can keep track of all objects that are overlapping By default, this overlap is base...
Definition: btGhostObject.h:34
btGhostPairCallback::removeOverlappingPair
virtual void * removeOverlappingPair(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1, btDispatcher *dispatcher)
Definition: btGhostObject.h:150
btCollisionWorld::ConvexResultCallback
RayResultCallback is used to report new raycast results.
Definition: btCollisionWorld.h:340
btGhostObject::addOverlappingObjectInternal
virtual void addOverlappingObjectInternal(btBroadphaseProxy *otherProxy, btBroadphaseProxy *thisProxy=0)
this method is mainly for expert/internal use only.
Definition: btGhostObject.cpp:33
btGhostObject::m_overlappingObjects
btAlignedObjectArray< btCollisionObject * > m_overlappingObjects
Definition: btGhostObject.h:38
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:75
btHashedOverlappingPairCache
Hash-space based Pair Cache, thanks to Erin Catto, Box2D, http://www.box2d.org, and Pierre Terdiman...
Definition: btOverlappingPairCache.h:94
btOverlappingPairCallback
The btOverlappingPairCallback class is an additional optional broadphase user callback for adding/rem...
Definition: btOverlappingPairCallback.h:24
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:279
btPairCachingGhostObject
Definition: btGhostObject.h:99
btBroadphasePair
The btBroadphasePair class contains a pair of aabb-overlapping objects.
Definition: btBroadphaseProxy.h:185