[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / BulletSoftBody / btDeformableContactProjection.h
1 /*
2  Written by Xuchen Han <xuchenhan2015@u.northwestern.edu>
3  
4  Bullet Continuous Collision Detection and Physics Library
5  Copyright (c) 2019 Google Inc. http://bulletphysics.org
6  This software is provided 'as-is', without any express or implied warranty.
7  In no event will the authors be held liable for any damages arising from the use of this software.
8  Permission is granted to anyone to use this software for any purpose,
9  including commercial applications, and to alter it and redistribute it freely,
10  subject to the following restrictions:
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_CONTACT_PROJECTION_H
17 #define BT_CONTACT_PROJECTION_H
18 #include "btCGProjection.h"
19 #include "btSoftBody.h"
20 #include "BulletDynamics/Featherstone/btMultiBodyLinkCollider.h"
21 #include "BulletDynamics/Featherstone/btMultiBodyConstraint.h"
22 #include "btDeformableContactConstraint.h"
23 #include "LinearMath/btHashMap.h"
24 #include "LinearMath/btReducedVector.h"
25 #include "LinearMath/btModifiedGramSchmidt.h"
26 #include <vector>
27
28 struct LagrangeMultiplier
29 {
30         int m_num_constraints;  // Number of constraints
31         int m_num_nodes;        // Number of nodes in these constraints
32         btScalar m_weights[3];  // weights of the nodes involved, same size as m_num_nodes
33         btVector3 m_dirs[3];    // Constraint directions, same size of m_num_constraints;
34         int m_indices[3];       // indices of the nodes involved, same size as m_num_nodes;
35 };
36
37 class btDeformableContactProjection
38 {
39 public:
40         typedef btAlignedObjectArray<btVector3> TVStack;
41         btAlignedObjectArray<btSoftBody*>& m_softBodies;
42
43         // all constraints involving face
44         btAlignedObjectArray<btDeformableContactConstraint*> m_allFaceConstraints;
45 #ifndef USE_MGS
46         // map from node index to projection directions
47         btHashMap<btHashInt, btAlignedObjectArray<btVector3> > m_projectionsDict;
48 #else
49         btAlignedObjectArray<btReducedVector> m_projections;
50 #endif
51
52         btAlignedObjectArray<LagrangeMultiplier> m_lagrangeMultipliers;
53
54         // map from node index to static constraint
55         btAlignedObjectArray<btAlignedObjectArray<btDeformableStaticConstraint> > m_staticConstraints;
56         // map from node index to node rigid constraint
57         btAlignedObjectArray<btAlignedObjectArray<btDeformableNodeRigidContactConstraint> > m_nodeRigidConstraints;
58         // map from node index to face rigid constraint
59         btAlignedObjectArray<btAlignedObjectArray<btDeformableFaceRigidContactConstraint> > m_faceRigidConstraints;
60         // map from node index to deformable constraint
61         btAlignedObjectArray<btAlignedObjectArray<btDeformableFaceNodeContactConstraint> > m_deformableConstraints;
62         // map from node index to node anchor constraint
63         btAlignedObjectArray<btAlignedObjectArray<btDeformableNodeAnchorConstraint> > m_nodeAnchorConstraints;
64
65         bool m_useStrainLimiting;
66
67         btDeformableContactProjection(btAlignedObjectArray<btSoftBody*>& softBodies)
68                 : m_softBodies(softBodies)
69         {
70         }
71
72         virtual ~btDeformableContactProjection()
73         {
74         }
75
76         // apply the constraints to the rhs of the linear solve
77         virtual void project(TVStack& x);
78
79         // add friction force to the rhs of the linear solve
80         virtual void applyDynamicFriction(TVStack& f);
81
82         // update and solve the constraints
83         virtual btScalar update(btCollisionObject** deformableBodies, int numDeformableBodies, const btContactSolverInfo& infoGlobal);
84
85         // Add constraints to m_constraints. In addition, the constraints that each vertex own are recorded in m_constraintsDict.
86         virtual void setConstraints(const btContactSolverInfo& infoGlobal);
87
88         // Set up projections for each vertex by adding the projection direction to
89         virtual void setProjection();
90
91         virtual void reinitialize(bool nodeUpdated);
92
93         btScalar solveSplitImpulse(btCollisionObject** deformableBodies, int numDeformableBodies, const btContactSolverInfo& infoGlobal);
94
95         virtual void setLagrangeMultiplier();
96
97         void checkConstraints(const TVStack& x);
98 };
99 #endif /* btDeformableContactProjection_h */