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

Bullet Collision Detection & Physics Library

btCompoundCollisionAlgorithm.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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
17 #ifndef BT_COMPOUND_COLLISION_ALGORITHM_H
18 #define BT_COMPOUND_COLLISION_ALGORITHM_H
19
20 #include "btActivatingCollisionAlgorithm.h"
21 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
22 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
23
24 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
25 class btDispatcher;
26 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
27 #include "btCollisionCreateFunc.h"
28 #include "LinearMath/btAlignedObjectArray.h"
29 #include "BulletCollision/BroadphaseCollision/btDbvt.h"
30 class btDispatcher;
31 class btCollisionObject;
32
33 class btCollisionShape;
34 typedef bool (*btShapePairCallback)(const btCollisionShape* pShape0, const btCollisionShape* pShape1);
35 extern btShapePairCallback gCompoundChildShapePairCallback;
36
38 class btCompoundCollisionAlgorithm : public btActivatingCollisionAlgorithm
39 {
40 btNodeStack stack2;
41 btManifoldArray manifoldArray;
42
43 protected:
44 btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithms;
45 bool m_isSwapped;
46
47 class btPersistentManifold* m_sharedManifold;
48 bool m_ownsManifold;
49
50 int m_compoundShapeRevision; //to keep track of changes, so that childAlgorithm array can be updated
51
52 void removeChildAlgorithms();
53
54 void preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap);
55
56 public:
57 btCompoundCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped);
58
59 virtual ~btCompoundCollisionAlgorithm();
60
61 btCollisionAlgorithm* getChildAlgorithm(int n) const
62 {
63 return m_childCollisionAlgorithms[n];
64 }
65
66 virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
67
68 btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
69
70 virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
71 {
72 int i;
73 for (i = 0; i < m_childCollisionAlgorithms.size(); i++)
74 {
75 if (m_childCollisionAlgorithms[i])
76 m_childCollisionAlgorithms[i]->getAllContactManifolds(manifoldArray);
77 }
78 }
79
80 struct CreateFunc : public btCollisionAlgorithmCreateFunc
81 {
82 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
83 {
84 void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCollisionAlgorithm));
85 return new (mem) btCompoundCollisionAlgorithm(ci, body0Wrap, body1Wrap, false);
86 }
87 };
88
89 struct SwappedCreateFunc : public btCollisionAlgorithmCreateFunc
90 {
91 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
92 {
93 void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCollisionAlgorithm));
94 return new (mem) btCompoundCollisionAlgorithm(ci, body0Wrap, body1Wrap, true);
95 }
96 };
97 };
98
99 #endif //BT_COMPOUND_COLLISION_ALGORITHM_H
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:50
btActivatingCollisionAlgorithm.h
btCompoundCollisionAlgorithm::calculateTimeOfImpact
btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
Definition: btCompoundCollisionAlgorithm.cpp:338
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btCompoundCollisionAlgorithm::removeChildAlgorithms
void removeChildAlgorithms()
Definition: btCompoundCollisionAlgorithm.cpp:75
btCollisionObjectWrapper
Definition: btCollisionObjectWrapper.h:18
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:77
btCompoundCollisionAlgorithm::getAllContactManifolds
virtual void getAllContactManifolds(btManifoldArray &manifoldArray)
Definition: btCompoundCollisionAlgorithm.h:70
btShapePairCallback
bool(* btShapePairCallback)(const btCollisionShape *pShape0, const btCollisionShape *pShape1)
Definition: btCompoundCollisionAlgorithm.h:34
btDispatcher::allocateCollisionAlgorithm
virtual void * allocateCollisionAlgorithm(int size)=0
btCompoundCollisionAlgorithm::preallocateChildAlgorithms
void preallocateChildAlgorithms(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap)
Definition: btCompoundCollisionAlgorithm.cpp:44
gCompoundChildShapePairCallback
btShapePairCallback gCompoundChildShapePairCallback
Definition: btCompoundCollisionAlgorithm.cpp:26
btCompoundCollisionAlgorithm::m_isSwapped
bool m_isSwapped
Definition: btCompoundCollisionAlgorithm.h:45
btCollisionAlgorithm
btCollisionAlgorithm is an collision interface that is compatible with the Broadphase and btDispatche...
Definition: btCollisionAlgorithm.h:54
btCompoundCollisionAlgorithm::m_compoundShapeRevision
int m_compoundShapeRevision
Definition: btCompoundCollisionAlgorithm.h:50
btCollisionShape
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
Definition: btCollisionShape.h:28
btCollisionAlgorithmCreateFunc
Used by the btCollisionDispatcher to register and create instances for btCollisionAlgorithm.
Definition: btCollisionCreateFunc.h:27
btCompoundCollisionAlgorithm::SwappedCreateFunc::CreateCollisionAlgorithm
virtual btCollisionAlgorithm * CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap)
Definition: btCompoundCollisionAlgorithm.h:91
btManifoldResult
btManifoldResult is a helper class to manage contact results.
Definition: btManifoldResult.h:48
btCompoundCollisionAlgorithm::SwappedCreateFunc
Definition: btCompoundCollisionAlgorithm.h:90
btCollisionAlgorithmConstructionInfo
Definition: btCollisionAlgorithm.h:33
btCompoundCollisionAlgorithm::~btCompoundCollisionAlgorithm
virtual ~btCompoundCollisionAlgorithm()
Definition: btCompoundCollisionAlgorithm.cpp:89
btCompoundCollisionAlgorithm::manifoldArray
btManifoldArray manifoldArray
Definition: btCompoundCollisionAlgorithm.h:41
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:65
btCompoundCollisionAlgorithm
btCompoundCollisionAlgorithm supports collision between CompoundCollisionShapes and other collision s...
Definition: btCompoundCollisionAlgorithm.h:39
btCollisionAlgorithmConstructionInfo::m_dispatcher1
btDispatcher * m_dispatcher1
Definition: btCollisionAlgorithm.h:45
btCompoundCollisionAlgorithm::m_ownsManifold
bool m_ownsManifold
Definition: btCompoundCollisionAlgorithm.h:48
btBroadphaseInterface.h
btDispatcherInfo
Definition: btDispatcher.h:31
btAlignedObjectArray< const btDbvtNode * >
btDispatcher.h
btCompoundCollisionAlgorithm::processCollision
virtual void processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
Definition: btCompoundCollisionAlgorithm.cpp:225
btCollisionCreateFunc.h
btPersistentManifold.h
btCompoundCollisionAlgorithm::CreateFunc
Definition: btCompoundCollisionAlgorithm.h:81
btBroadphaseProxy.h
btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm
btCompoundCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, bool isSwapped)
Definition: btCompoundCollisionAlgorithm.cpp:28
btCompoundCollisionAlgorithm::stack2
btNodeStack stack2
Definition: btCompoundCollisionAlgorithm.h:40
btActivatingCollisionAlgorithm
This class is not enabled yet (work-in-progress) to more aggressively activate objects.
Definition: btActivatingCollisionAlgorithm.h:23
btAlignedObjectArray.h
btCompoundCollisionAlgorithm::m_sharedManifold
class btPersistentManifold * m_sharedManifold
Definition: btCompoundCollisionAlgorithm.h:47
btCompoundCollisionAlgorithm::m_childCollisionAlgorithms
btAlignedObjectArray< btCollisionAlgorithm * > m_childCollisionAlgorithms
Definition: btCompoundCollisionAlgorithm.h:44
btCompoundCollisionAlgorithm::getChildAlgorithm
btCollisionAlgorithm * getChildAlgorithm(int n) const
Definition: btCompoundCollisionAlgorithm.h:61
btDbvt.h
btAlignedObjectArray::size
int size() const
return the number of elements in the array
Definition: btAlignedObjectArray.h:142
btCompoundCollisionAlgorithm::CreateFunc::CreateCollisionAlgorithm
virtual btCollisionAlgorithm * CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap)
Definition: btCompoundCollisionAlgorithm.h:82