1 #include "../btDeformableContactConstraint.h"
2 #include "btReducedDeformableBody.h"
4 // ================= static constraints ===================
5 class btReducedDeformableStaticConstraint : public btDeformableStaticConstraint
8 btReducedDeformableBody* m_rsb;
11 btVector3 m_targetPos;
12 btVector3 m_impulseDirection;
13 btMatrix3x3 m_impulseFactorMatrix;
14 btScalar m_impulseFactor;
16 btScalar m_appliedImpulse;
19 btReducedDeformableStaticConstraint(btReducedDeformableBody* rsb,
20 btSoftBody::Node* node,
24 const btContactSolverInfo& infoGlobal,
26 // btReducedDeformableStaticConstraint(const btReducedDeformableStaticConstraint& other);
27 btReducedDeformableStaticConstraint() {}
28 virtual ~btReducedDeformableStaticConstraint() {}
30 virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal);
32 // this calls reduced deformable body's applyFullSpaceImpulse
33 virtual void applyImpulse(const btVector3& impulse);
35 btVector3 getDeltaVa() const;
37 // virtual void applySplitImpulse(const btVector3& impulse) {}
40 // ================= base contact constraints ===================
41 class btReducedDeformableRigidContactConstraint : public btDeformableRigidContactConstraint
44 bool m_collideStatic; // flag for collision with static object
45 bool m_collideMultibody; // flag for collision with multibody
48 int m_solverBodyId; // for debugging
50 btReducedDeformableBody* m_rsb;
51 btSolverBody* m_solverBody;
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;
63 btScalar m_rhs_tangent;
64 btScalar m_rhs_tangent2;
67 btScalar m_cfm_friction;
69 btScalar m_erp_friction;
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
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;
88 btReducedDeformableRigidContactConstraint(btReducedDeformableBody* rsb,
89 const btSoftBody::DeformableRigidContact& c,
90 const btContactSolverInfo& infoGlobal,
92 // btReducedDeformableRigidContactConstraint(const btReducedDeformableRigidContactConstraint& other);
93 btReducedDeformableRigidContactConstraint() {}
94 virtual ~btReducedDeformableRigidContactConstraint() {}
96 void setSolverBody(const int bodyId, btSolverBody& solver_body);
98 virtual void warmStarting() {}
100 virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal);
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);
111 virtual void applyImpulse(const btVector3& impulse) {}
113 virtual void applySplitImpulse(const btVector3& impulse) {} // TODO: may need later
115 virtual btVector3 getVa() const;
116 virtual btVector3 getDeltaVa() const = 0;
117 virtual btVector3 getDeltaVb() const = 0;
120 // ================= node vs rigid constraints ===================
121 class btReducedDeformableNodeRigidContactConstraint : public btReducedDeformableRigidContactConstraint
124 btSoftBody::Node* m_node;
126 btReducedDeformableNodeRigidContactConstraint(btReducedDeformableBody* rsb,
127 const btSoftBody::DeformableNodeRigidContact& contact,
128 const btContactSolverInfo& infoGlobal,
130 // btReducedDeformableNodeRigidContactConstraint(const btReducedDeformableNodeRigidContactConstraint& other);
131 btReducedDeformableNodeRigidContactConstraint() {}
132 virtual ~btReducedDeformableNodeRigidContactConstraint() {}
134 virtual void warmStarting();
136 // get the velocity of the deformable node in contact
137 virtual btVector3 getVb() const;
139 // get the velocity change of the rigid body
140 virtual btVector3 getDeltaVa() const;
142 // get velocity change of the node in contat
143 virtual btVector3 getDeltaVb() const;
145 // get the split impulse velocity of the deformable face at the contact point
146 virtual btVector3 getSplitVb() const;
148 // get the velocity change of the input soft body node in the constraint
149 virtual btVector3 getDv(const btSoftBody::Node*) const;
151 // cast the contact to the desired type
152 const btSoftBody::DeformableNodeRigidContact* getContact() const
154 return static_cast<const btSoftBody::DeformableNodeRigidContact*>(m_contact);
157 // this calls reduced deformable body's applyFullSpaceImpulse
158 virtual void applyImpulse(const btVector3& impulse);
161 // ================= face vs rigid constraints ===================
162 class btReducedDeformableFaceRigidContactConstraint : public btReducedDeformableRigidContactConstraint
165 btSoftBody::Face* m_face;
166 bool m_useStrainLimiting;
168 btReducedDeformableFaceRigidContactConstraint(btReducedDeformableBody* rsb,
169 const btSoftBody::DeformableFaceRigidContact& contact,
170 const btContactSolverInfo& infoGlobal,
172 bool useStrainLimiting);
173 // btReducedDeformableFaceRigidContactConstraint(const btReducedDeformableFaceRigidContactConstraint& other);
174 btReducedDeformableFaceRigidContactConstraint() {}
175 virtual ~btReducedDeformableFaceRigidContactConstraint() {}
177 // get the velocity of the deformable face at the contact point
178 virtual btVector3 getVb() const;
180 // get the split impulse velocity of the deformable face at the contact point
181 virtual btVector3 getSplitVb() const;
183 // get the velocity change of the input soft body node in the constraint
184 virtual btVector3 getDv(const btSoftBody::Node*) const;
186 // cast the contact to the desired type
187 const btSoftBody::DeformableFaceRigidContact* getContact() const
189 return static_cast<const btSoftBody::DeformableFaceRigidContact*>(m_contact);
192 // this calls reduced deformable body's applyFullSpaceImpulse
193 virtual void applyImpulse(const btVector3& impulse);