[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / BulletSoftBody / btSoftBodySolvers.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_BODY_SOLVERS_H
17 #define BT_SOFT_BODY_SOLVERS_H
18
19 #include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
20
21 class btSoftBodyTriangleData;
22 class btSoftBodyLinkData;
23 class btSoftBodyVertexData;
24 class btVertexBufferDescriptor;
25 class btCollisionObject;
26 class btSoftBody;
27
28 class btSoftBodySolver
29 {
30 public:
31         enum SolverTypes
32         {
33                 DEFAULT_SOLVER,
34                 CPU_SOLVER,
35                 CL_SOLVER,
36                 CL_SIMD_SOLVER,
37                 DX_SOLVER,
38                 DX_SIMD_SOLVER,
39                 DEFORMABLE_SOLVER,
40                 REDUCED_DEFORMABLE_SOLVER
41         };
42
43 protected:
44         int m_numberOfPositionIterations;
45         int m_numberOfVelocityIterations;
46         // Simulation timescale
47         float m_timeScale;
48
49 public:
50         btSoftBodySolver() : m_numberOfPositionIterations(10),
51                                                  m_timeScale(1)
52         {
53                 m_numberOfVelocityIterations = 0;
54                 m_numberOfPositionIterations = 5;
55         }
56
57         virtual ~btSoftBodySolver()
58         {
59         }
60
61         /**
62          * Return the type of the solver.
63          */
64         virtual SolverTypes getSolverType() const = 0;
65
66         /** Ensure that this solver is initialized. */
67         virtual bool checkInitialized() = 0;
68
69         /** Optimize soft bodies in this solver. */
70         virtual void optimize(btAlignedObjectArray<btSoftBody *> &softBodies, bool forceUpdate = false) = 0;
71
72         /** Copy necessary data back to the original soft body source objects. */
73         virtual void copyBackToSoftBodies(bool bMove = true) = 0;
74
75         /** Predict motion of soft bodies into next timestep */
76         virtual void predictMotion(btScalar solverdt) = 0;
77
78         /** Solve constraints for a set of soft bodies */
79         virtual void solveConstraints(btScalar solverdt) = 0;
80
81         /** Perform necessary per-step updates of soft bodies such as recomputing normals and bounding boxes */
82         virtual void updateSoftBodies() = 0;
83
84         /** Process a collision between one of the world's soft bodies and another collision object */
85         virtual void processCollision(btSoftBody *, const struct btCollisionObjectWrapper *) = 0;
86
87         /** Process a collision between two soft bodies */
88         virtual void processCollision(btSoftBody *, btSoftBody *) = 0;
89
90         /** Set the number of velocity constraint solver iterations this solver uses. */
91         virtual void setNumberOfPositionIterations(int iterations)
92         {
93                 m_numberOfPositionIterations = iterations;
94         }
95
96         /** Get the number of velocity constraint solver iterations this solver uses. */
97         virtual int getNumberOfPositionIterations()
98         {
99                 return m_numberOfPositionIterations;
100         }
101
102         /** Set the number of velocity constraint solver iterations this solver uses. */
103         virtual void setNumberOfVelocityIterations(int iterations)
104         {
105                 m_numberOfVelocityIterations = iterations;
106         }
107
108         /** Get the number of velocity constraint solver iterations this solver uses. */
109         virtual int getNumberOfVelocityIterations()
110         {
111                 return m_numberOfVelocityIterations;
112         }
113
114         /** Return the timescale that the simulation is using */
115         float getTimeScale()
116         {
117                 return m_timeScale;
118         }
119
120 #if 0
121         /**
122          * Add a collision object to be used by the indicated softbody.
123          */
124         virtual void addCollisionObjectForSoftBody( int clothIdentifier, btCollisionObject *collisionObject ) = 0;
125 #endif
126 };
127
128 /** 
129  * Class to manage movement of data from a solver to a given target.
130  * This version is abstract. Subclasses will have custom pairings for different combinations.
131  */
132 class btSoftBodySolverOutput
133 {
134 protected:
135 public:
136         btSoftBodySolverOutput()
137         {
138         }
139
140         virtual ~btSoftBodySolverOutput()
141         {
142         }
143
144         /** Output current computed vertex data to the vertex buffers for all cloths in the solver. */
145         virtual void copySoftBodyToVertexBuffer(const btSoftBody *const softBody, btVertexBufferDescriptor *vertexBuffer) = 0;
146 };
147
148 #endif  // #ifndef BT_SOFT_BODY_SOLVERS_H