404574989ab0061c0ba8e2e868989c15df524a2e
[blender.git] / extern / bullet2 / src / BulletCollision / CollisionDispatch / btCompoundCollisionAlgorithm.h
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 #ifndef BT_COMPOUND_COLLISION_ALGORITHM_H
17 #define BT_COMPOUND_COLLISION_ALGORITHM_H
18
19 #include "btActivatingCollisionAlgorithm.h"
20 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
21 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
22
23 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
24 class btDispatcher;
25 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
26 #include "btCollisionCreateFunc.h"
27 #include "LinearMath/btAlignedObjectArray.h"
28 class btDispatcher;
29 class btCollisionObject;
30
31 /// btCompoundCollisionAlgorithm  supports collision between CompoundCollisionShapes and other collision shapes
32 class btCompoundCollisionAlgorithm  : public btActivatingCollisionAlgorithm
33 {
34         btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithms;
35         bool m_isSwapped;
36
37         class btPersistentManifold*     m_sharedManifold;
38         bool                                    m_ownsManifold;
39
40         int     m_compoundShapeRevision;//to keep track of changes, so that childAlgorithm array can be updated
41         
42         void    removeChildAlgorithms();
43         
44         void    preallocateChildAlgorithms(btCollisionObject* body0,btCollisionObject* body1);
45
46 public:
47
48         btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
49
50         virtual ~btCompoundCollisionAlgorithm();
51
52         virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
53
54         btScalar        calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
55
56         virtual void    getAllContactManifolds(btManifoldArray& manifoldArray)
57         {
58                 int i;
59                 for (i=0;i<m_childCollisionAlgorithms.size();i++)
60                 {
61                         if (m_childCollisionAlgorithms[i])
62                                 m_childCollisionAlgorithms[i]->getAllContactManifolds(manifoldArray);
63                 }
64         }
65
66         struct CreateFunc :public       btCollisionAlgorithmCreateFunc
67         {
68                 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
69                 {
70                         void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCollisionAlgorithm));
71                         return new(mem) btCompoundCollisionAlgorithm(ci,body0,body1,false);
72                 }
73         };
74
75         struct SwappedCreateFunc :public        btCollisionAlgorithmCreateFunc
76         {
77                 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
78                 {
79                         void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCollisionAlgorithm));
80                         return new(mem) btCompoundCollisionAlgorithm(ci,body0,body1,true);
81                 }
82         };
83
84 };
85
86 #endif //BT_COMPOUND_COLLISION_ALGORITHM_H