[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / BulletDynamics / Dynamics / btDynamicsWorld.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_DYNAMICS_WORLD_H
17 #define BT_DYNAMICS_WORLD_H
18
19 #include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
20 #include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
21
22 class btTypedConstraint;
23 class btActionInterface;
24 class btConstraintSolver;
25 class btDynamicsWorld;
26
27 /// Type for the callback for each tick
28 typedef void (*btInternalTickCallback)(btDynamicsWorld* world, btScalar timeStep);
29
30 enum btDynamicsWorldType
31 {
32         BT_SIMPLE_DYNAMICS_WORLD = 1,
33         BT_DISCRETE_DYNAMICS_WORLD = 2,
34         BT_CONTINUOUS_DYNAMICS_WORLD = 3,
35         BT_SOFT_RIGID_DYNAMICS_WORLD = 4,
36         BT_GPU_DYNAMICS_WORLD = 5,
37         BT_SOFT_MULTIBODY_DYNAMICS_WORLD = 6,
38     BT_DEFORMABLE_MULTIBODY_DYNAMICS_WORLD = 7
39 };
40
41 ///The btDynamicsWorld is the interface class for several dynamics implementation, basic, discrete, parallel, and continuous etc.
42 class btDynamicsWorld : public btCollisionWorld
43 {
44 protected:
45         btInternalTickCallback m_internalTickCallback;
46         btInternalTickCallback m_internalPreTickCallback;
47         void* m_worldUserInfo;
48
49         btContactSolverInfo m_solverInfo;
50
51 public:
52         btDynamicsWorld(btDispatcher* dispatcher, btBroadphaseInterface* broadphase, btCollisionConfiguration* collisionConfiguration)
53                 : btCollisionWorld(dispatcher, broadphase, collisionConfiguration), m_internalTickCallback(0), m_internalPreTickCallback(0), m_worldUserInfo(0)
54         {
55         }
56
57         virtual ~btDynamicsWorld()
58         {
59         }
60
61         ///stepSimulation proceeds the simulation over 'timeStep', units in preferably in seconds.
62         ///By default, Bullet will subdivide the timestep in constant substeps of each 'fixedTimeStep'.
63         ///in order to keep the simulation real-time, the maximum number of substeps can be clamped to 'maxSubSteps'.
64         ///You can disable subdividing the timestep/substepping by passing maxSubSteps=0 as second argument to stepSimulation, but in that case you have to keep the timeStep constant.
65         virtual int stepSimulation(btScalar timeStep, int maxSubSteps = 1, btScalar fixedTimeStep = btScalar(1.) / btScalar(60.)) = 0;
66
67         virtual void debugDrawWorld() = 0;
68
69         virtual void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies = false)
70         {
71                 (void)constraint;
72                 (void)disableCollisionsBetweenLinkedBodies;
73         }
74
75         virtual void removeConstraint(btTypedConstraint* constraint) { (void)constraint; }
76
77         virtual void addAction(btActionInterface* action) = 0;
78
79         virtual void removeAction(btActionInterface* action) = 0;
80
81         //once a rigidbody is added to the dynamics world, it will get this gravity assigned
82         //existing rigidbodies in the world get gravity assigned too, during this method
83         virtual void setGravity(const btVector3& gravity) = 0;
84         virtual btVector3 getGravity() const = 0;
85
86         virtual void synchronizeMotionStates() = 0;
87
88         virtual void addRigidBody(btRigidBody* body) = 0;
89
90         virtual void addRigidBody(btRigidBody* body, int group, int mask) = 0;
91
92         virtual void removeRigidBody(btRigidBody* body) = 0;
93
94         virtual void setConstraintSolver(btConstraintSolver* solver) = 0;
95
96         virtual btConstraintSolver* getConstraintSolver() = 0;
97
98         virtual int getNumConstraints() const { return 0; }
99
100         virtual btTypedConstraint* getConstraint(int index)
101         {
102                 (void)index;
103                 return 0;
104         }
105
106         virtual const btTypedConstraint* getConstraint(int index) const
107         {
108                 (void)index;
109                 return 0;
110         }
111
112         virtual btDynamicsWorldType getWorldType() const = 0;
113
114         virtual void clearForces() = 0;
115
116         /// Set the callback for when an internal tick (simulation substep) happens, optional user info
117         void setInternalTickCallback(btInternalTickCallback cb, void* worldUserInfo = 0, bool isPreTick = false)
118         {
119                 if (isPreTick)
120                 {
121                         m_internalPreTickCallback = cb;
122                 }
123                 else
124                 {
125                         m_internalTickCallback = cb;
126                 }
127                 m_worldUserInfo = worldUserInfo;
128         }
129
130         void setWorldUserInfo(void* worldUserInfo)
131         {
132                 m_worldUserInfo = worldUserInfo;
133         }
134
135         void* getWorldUserInfo() const
136         {
137                 return m_worldUserInfo;
138         }
139
140         btContactSolverInfo& getSolverInfo()
141         {
142                 return m_solverInfo;
143         }
144
145         const btContactSolverInfo& getSolverInfo() const
146         {
147                 return m_solverInfo;
148         }
149
150         ///obsolete, use addAction instead.
151         virtual void addVehicle(btActionInterface* vehicle) { (void)vehicle; }
152         ///obsolete, use removeAction instead
153         virtual void removeVehicle(btActionInterface* vehicle) { (void)vehicle; }
154         ///obsolete, use addAction instead.
155         virtual void addCharacter(btActionInterface* character) { (void)character; }
156         ///obsolete, use removeAction instead
157         virtual void removeCharacter(btActionInterface* character) { (void)character; }
158 };
159
160 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
161 struct btDynamicsWorldDoubleData
162 {
163         btContactSolverInfoDoubleData m_solverInfo;
164         btVector3DoubleData m_gravity;
165 };
166
167 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
168 struct btDynamicsWorldFloatData
169 {
170         btContactSolverInfoFloatData m_solverInfo;
171         btVector3FloatData m_gravity;
172 };
173
174 #endif  //BT_DYNAMICS_WORLD_H