[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / BulletSoftBody / BulletReducedDeformableBody / btReducedDeformableContactConstraint.h
1 #include "../btDeformableContactConstraint.h"
2 #include "btReducedDeformableBody.h"
3
4 // ================= static constraints ===================
5 class btReducedDeformableStaticConstraint : public btDeformableStaticConstraint
6 {
7  public:
8   btReducedDeformableBody* m_rsb;
9   btScalar m_dt;
10   btVector3 m_ri;
11   btVector3 m_targetPos;
12   btVector3 m_impulseDirection;
13   btMatrix3x3 m_impulseFactorMatrix;
14   btScalar m_impulseFactor;
15   btScalar m_rhs;
16   btScalar m_appliedImpulse;
17   btScalar m_erp;
18
19   btReducedDeformableStaticConstraint(btReducedDeformableBody* rsb, 
20                                       btSoftBody::Node* node,
21                                       const btVector3& ri,
22                                       const btVector3& x0,
23                                       const btVector3& dir,
24                                       const btContactSolverInfo& infoGlobal,
25                                       btScalar dt);
26         // btReducedDeformableStaticConstraint(const btReducedDeformableStaticConstraint& other);
27   btReducedDeformableStaticConstraint() {}
28   virtual ~btReducedDeformableStaticConstraint() {}
29
30   virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal);
31   
32   // this calls reduced deformable body's applyFullSpaceImpulse
33   virtual void applyImpulse(const btVector3& impulse);
34
35   btVector3 getDeltaVa() const;
36
37   // virtual void applySplitImpulse(const btVector3& impulse) {}
38 };
39
40 // ================= base contact constraints ===================
41 class btReducedDeformableRigidContactConstraint : public btDeformableRigidContactConstraint
42 {
43  public:
44   bool m_collideStatic;     // flag for collision with static object
45   bool m_collideMultibody;  // flag for collision with multibody
46
47   int m_nodeQueryIndex;
48   int m_solverBodyId;       // for debugging
49
50   btReducedDeformableBody* m_rsb;
51   btSolverBody* m_solverBody;
52   btScalar m_dt;
53
54   btScalar m_appliedNormalImpulse;
55   btScalar m_appliedTangentImpulse;
56   btScalar m_appliedTangentImpulse2;
57   btScalar m_normalImpulseFactor;
58   btScalar m_tangentImpulseFactor;
59   btScalar m_tangentImpulseFactor2;
60   btScalar m_tangentImpulseFactorInv;
61   btScalar m_tangentImpulseFactorInv2;
62   btScalar m_rhs;
63   btScalar m_rhs_tangent;
64   btScalar m_rhs_tangent2;
65   
66   btScalar m_cfm;
67   btScalar m_cfm_friction;
68   btScalar m_erp;
69   btScalar m_erp_friction;
70   btScalar m_friction;
71
72   btVector3 m_contactNormalA;     // surface normal for rigid body (opposite direction as impulse)
73   btVector3 m_contactNormalB;     // surface normal for reduced deformable body (opposite direction as impulse)
74   btVector3 m_contactTangent;     // tangential direction of the relative velocity
75   btVector3 m_contactTangent2;    // 2nd tangential direction of the relative velocity
76   btVector3 m_relPosA;            // relative position of the contact point for A (rigid)
77   btVector3 m_relPosB;            // relative position of the contact point for B
78   btMatrix3x3 m_impulseFactor;    // total impulse matrix
79
80   btVector3 m_bufferVelocityA;    // velocity at the beginning of the iteration
81   btVector3 m_bufferVelocityB;
82   btVector3 m_linearComponentNormal;    // linear components for the solver body
83   btVector3 m_angularComponentNormal;   // angular components for the solver body
84   // since 2nd contact direction only applies to multibody, these components will never be used
85   btVector3 m_linearComponentTangent;
86   btVector3 m_angularComponentTangent;
87
88   btReducedDeformableRigidContactConstraint(btReducedDeformableBody* rsb, 
89                                             const btSoftBody::DeformableRigidContact& c, 
90                                             const btContactSolverInfo& infoGlobal,
91                                             btScalar dt);
92         // btReducedDeformableRigidContactConstraint(const btReducedDeformableRigidContactConstraint& other);
93   btReducedDeformableRigidContactConstraint() {}
94   virtual ~btReducedDeformableRigidContactConstraint() {}
95
96   void setSolverBody(const int bodyId, btSolverBody& solver_body);
97
98   virtual void warmStarting() {}
99
100   virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal);
101
102   void calculateTangentialImpulse(btScalar& deltaImpulse_tangent, 
103                                   btScalar& appliedImpulse, 
104                                   const btScalar rhs_tangent,
105                                   const btScalar tangentImpulseFactorInv,
106                                   const btVector3& tangent,
107                                   const btScalar lower_limit,
108                                   const btScalar upper_limit,
109                                   const btVector3& deltaV_rel);
110
111   virtual void applyImpulse(const btVector3& impulse) {}
112
113   virtual void applySplitImpulse(const btVector3& impulse) {} // TODO: may need later
114
115   virtual btVector3 getVa() const;
116   virtual btVector3 getDeltaVa() const = 0;
117   virtual btVector3 getDeltaVb() const = 0;
118 };
119
120 // ================= node vs rigid constraints ===================
121 class btReducedDeformableNodeRigidContactConstraint : public btReducedDeformableRigidContactConstraint
122 {
123  public:
124   btSoftBody::Node* m_node;
125
126   btReducedDeformableNodeRigidContactConstraint(btReducedDeformableBody* rsb, 
127                                                 const btSoftBody::DeformableNodeRigidContact& contact, 
128                                                 const btContactSolverInfo& infoGlobal,
129                                                 btScalar dt);
130         // btReducedDeformableNodeRigidContactConstraint(const btReducedDeformableNodeRigidContactConstraint& other);
131   btReducedDeformableNodeRigidContactConstraint() {}
132   virtual ~btReducedDeformableNodeRigidContactConstraint() {}
133
134   virtual void warmStarting();
135
136   // get the velocity of the deformable node in contact
137         virtual btVector3 getVb() const;
138
139   // get the velocity change of the rigid body
140   virtual btVector3 getDeltaVa() const;
141
142   // get velocity change of the node in contat
143   virtual btVector3 getDeltaVb() const;
144
145         // get the split impulse velocity of the deformable face at the contact point
146         virtual btVector3 getSplitVb() const;
147
148         // get the velocity change of the input soft body node in the constraint
149         virtual btVector3 getDv(const btSoftBody::Node*) const;
150
151         // cast the contact to the desired type
152         const btSoftBody::DeformableNodeRigidContact* getContact() const
153         {
154                 return static_cast<const btSoftBody::DeformableNodeRigidContact*>(m_contact);
155         }
156   
157   // this calls reduced deformable body's applyFullSpaceImpulse
158   virtual void applyImpulse(const btVector3& impulse);
159 };
160
161 // ================= face vs rigid constraints ===================
162 class btReducedDeformableFaceRigidContactConstraint : public btReducedDeformableRigidContactConstraint
163 {
164  public:
165   btSoftBody::Face* m_face;
166         bool m_useStrainLimiting;
167
168   btReducedDeformableFaceRigidContactConstraint(btReducedDeformableBody* rsb, 
169                                                 const btSoftBody::DeformableFaceRigidContact& contact, 
170                                                 const btContactSolverInfo& infoGlobal,
171                                                 btScalar dt, 
172                                                 bool useStrainLimiting);
173         // btReducedDeformableFaceRigidContactConstraint(const btReducedDeformableFaceRigidContactConstraint& other);
174   btReducedDeformableFaceRigidContactConstraint() {}
175   virtual ~btReducedDeformableFaceRigidContactConstraint() {}
176
177   // get the velocity of the deformable face at the contact point
178         virtual btVector3 getVb() const;
179
180         // get the split impulse velocity of the deformable face at the contact point
181         virtual btVector3 getSplitVb() const;
182
183         // get the velocity change of the input soft body node in the constraint
184         virtual btVector3 getDv(const btSoftBody::Node*) const;
185
186         // cast the contact to the desired type
187         const btSoftBody::DeformableFaceRigidContact* getContact() const
188         {
189                 return static_cast<const btSoftBody::DeformableFaceRigidContact*>(m_contact);
190         }
191
192   // this calls reduced deformable body's applyFullSpaceImpulse
193   virtual void applyImpulse(const btVector3& impulse);
194 };