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

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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