[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / BulletSoftBody / btSoftRigidDynamicsWorld.h
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans  https://bulletphysics.org
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_SOFT_RIGID_DYNAMICS_WORLD_H
17 #define BT_SOFT_RIGID_DYNAMICS_WORLD_H
18
19 #include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
20 #include "btSoftBody.h"
21
22 typedef btAlignedObjectArray<btSoftBody*> btSoftBodyArray;
23
24 class btSoftBodySolver;
25
26 class btSoftRigidDynamicsWorld : public btDiscreteDynamicsWorld
27 {
28         btSoftBodyArray m_softBodies;
29         int m_drawFlags;
30         bool m_drawNodeTree;
31         bool m_drawFaceTree;
32         bool m_drawClusterTree;
33         btSoftBodyWorldInfo m_sbi;
34         ///Solver classes that encapsulate multiple soft bodies for solving
35         btSoftBodySolver* m_softBodySolver;
36         bool m_ownsSolver;
37
38 protected:
39         virtual void predictUnconstraintMotion(btScalar timeStep);
40
41         virtual void internalSingleStepSimulation(btScalar timeStep);
42
43         void solveSoftBodiesConstraints(btScalar timeStep);
44
45         void serializeSoftBodies(btSerializer* serializer);
46
47 public:
48         btSoftRigidDynamicsWorld(btDispatcher* dispatcher, btBroadphaseInterface* pairCache, btConstraintSolver* constraintSolver, btCollisionConfiguration* collisionConfiguration, btSoftBodySolver* softBodySolver = 0);
49
50         virtual ~btSoftRigidDynamicsWorld();
51
52         virtual void debugDrawWorld();
53
54         void addSoftBody(btSoftBody* body, int collisionFilterGroup = btBroadphaseProxy::DefaultFilter, int collisionFilterMask = btBroadphaseProxy::AllFilter);
55
56         void removeSoftBody(btSoftBody* body);
57
58         ///removeCollisionObject will first check if it is a rigid body, if so call removeRigidBody otherwise call btDiscreteDynamicsWorld::removeCollisionObject
59         virtual void removeCollisionObject(btCollisionObject* collisionObject);
60
61         int getDrawFlags() const { return (m_drawFlags); }
62         void setDrawFlags(int f) { m_drawFlags = f; }
63
64         btSoftBodyWorldInfo& getWorldInfo()
65         {
66                 return m_sbi;
67         }
68         const btSoftBodyWorldInfo& getWorldInfo() const
69         {
70                 return m_sbi;
71         }
72
73         virtual btDynamicsWorldType getWorldType() const
74         {
75                 return BT_SOFT_RIGID_DYNAMICS_WORLD;
76         }
77
78         btSoftBodyArray& getSoftBodyArray()
79         {
80                 return m_softBodies;
81         }
82
83         const btSoftBodyArray& getSoftBodyArray() const
84         {
85                 return m_softBodies;
86         }
87
88         virtual void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const;
89
90         /// rayTestSingle performs a raycast call and calls the resultCallback. It is used internally by rayTest.
91         /// In a future implementation, we consider moving the ray test as a virtual method in btCollisionShape.
92         /// This allows more customization.
93         static void rayTestSingle(const btTransform& rayFromTrans, const btTransform& rayToTrans,
94                                                           btCollisionObject* collisionObject,
95                                                           const btCollisionShape* collisionShape,
96                                                           const btTransform& colObjWorldTransform,
97                                                           RayResultCallback& resultCallback);
98
99         virtual void serialize(btSerializer* serializer);
100 };
101
102 #endif  //BT_SOFT_RIGID_DYNAMICS_WORLD_H