svn merge -r 16231:16536 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / extern / bullet2 / src / BulletSoftBody / btSoftBodyConcaveCollisionAlgorithm.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 SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H
17 #define SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H
18
19 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
20 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
21 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
22 #include "BulletCollision/CollisionShapes/btTriangleCallback.h"
23 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
24 class btDispatcher;
25 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
26 #include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
27 class btSoftBody;
28
29 ///For each triangle in the concave mesh that overlaps with the AABB of a soft body (m_softBody), processTriangle is called.
30 class btSoftBodyTriangleCallback : public btTriangleCallback
31 {
32         btSoftBody* m_softBody;
33         btCollisionObject* m_triBody;
34
35         btVector3       m_aabbMin;
36         btVector3       m_aabbMax ;
37
38         btManifoldResult* m_resultOut;
39
40         btDispatcher*   m_dispatcher;
41         const btDispatcherInfo* m_dispatchInfoPtr;
42         btScalar m_collisionMarginTriangle;
43         
44 public:
45 int     m_triangleCount;
46         
47 //      btPersistentManifold*   m_manifoldPtr;
48
49         btSoftBodyTriangleCallback(btDispatcher* dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
50
51         void    setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
52
53         virtual ~btSoftBodyTriangleCallback();
54
55         virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex);
56         
57         void clearCache();
58
59         SIMD_FORCE_INLINE const btVector3& getAabbMin() const
60         {
61                 return m_aabbMin;
62         }
63         SIMD_FORCE_INLINE const btVector3& getAabbMax() const
64         {
65                 return m_aabbMax;
66         }
67
68 };
69
70
71
72
73 /// btSoftBodyConcaveCollisionAlgorithm  supports collision between soft body shapes and (concave) trianges meshes.
74 class btSoftBodyConcaveCollisionAlgorithm  : public btCollisionAlgorithm
75 {
76
77         bool    m_isSwapped;
78
79         btSoftBodyTriangleCallback m_btSoftBodyTriangleCallback;
80
81 public:
82
83         btSoftBodyConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
84
85         virtual ~btSoftBodyConcaveCollisionAlgorithm();
86
87         virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
88
89         btScalar        calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
90
91         virtual void    getAllContactManifolds(btManifoldArray& manifoldArray)
92         {
93                 //we don't add any manifolds
94         }
95
96         void    clearCache();
97
98         struct CreateFunc :public       btCollisionAlgorithmCreateFunc
99         {
100                 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
101                 {
102                         void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSoftBodyConcaveCollisionAlgorithm));
103                         return new(mem) btSoftBodyConcaveCollisionAlgorithm(ci,body0,body1,false);
104                 }
105         };
106
107         struct SwappedCreateFunc :public        btCollisionAlgorithmCreateFunc
108         {
109                 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
110                 {
111                         void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSoftBodyConcaveCollisionAlgorithm));
112                         return new(mem) btSoftBodyConcaveCollisionAlgorithm(ci,body0,body1,true);
113                 }
114         };
115
116 };
117
118 #endif //SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H