2 Written by Xuchen Han <xuchenhan2015@u.northwestern.edu>
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.
16 #ifndef BT_DEFORMABLE_CONTACT_CONSTRAINT_H
17 #define BT_DEFORMABLE_CONTACT_CONSTRAINT_H
18 #include "btSoftBody.h"
20 // btDeformableContactConstraint is an abstract class specifying the method that each type of contact constraint needs to implement
21 class btDeformableContactConstraint
24 // True if the friction is static
25 // False if the friction is dynamic
27 const btContactSolverInfo* m_infoGlobal;
29 // normal of the contact
32 btDeformableContactConstraint(const btVector3& normal, const btContactSolverInfo& infoGlobal) : m_static(false), m_normal(normal), m_infoGlobal(&infoGlobal)
36 btDeformableContactConstraint(bool isStatic, const btVector3& normal, const btContactSolverInfo& infoGlobal) : m_static(isStatic), m_normal(normal), m_infoGlobal(&infoGlobal)
40 btDeformableContactConstraint() : m_static(false) {}
42 btDeformableContactConstraint(const btDeformableContactConstraint& other)
43 : m_static(other.m_static), m_normal(other.m_normal), m_infoGlobal(other.m_infoGlobal)
47 virtual ~btDeformableContactConstraint() {}
49 // solve the constraint with inelastic impulse and return the error, which is the square of normal component of velocity diffrerence
50 // the constraint is solved by calculating the impulse between object A and B in the contact and apply the impulse to both objects involved in the contact
51 virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal) = 0;
53 // get the velocity of the object A in the contact
54 virtual btVector3 getVa() const = 0;
56 // get the velocity of the object B in the contact
57 virtual btVector3 getVb() const = 0;
59 // get the velocity change of the soft body node in the constraint
60 virtual btVector3 getDv(const btSoftBody::Node*) const = 0;
62 // apply impulse to the soft body node and/or face involved
63 virtual void applyImpulse(const btVector3& impulse) = 0;
65 // scale the penetration depth by erp
66 virtual void setPenetrationScale(btScalar scale) = 0;
70 // Constraint that a certain node in the deformable objects cannot move
71 class btDeformableStaticConstraint : public btDeformableContactConstraint
74 btSoftBody::Node* m_node;
76 btDeformableStaticConstraint(btSoftBody::Node* node, const btContactSolverInfo& infoGlobal) : m_node(node), btDeformableContactConstraint(false, btVector3(0, 0, 0), infoGlobal)
79 btDeformableStaticConstraint() {}
80 btDeformableStaticConstraint(const btDeformableStaticConstraint& other)
81 : m_node(other.m_node), btDeformableContactConstraint(other)
85 virtual ~btDeformableStaticConstraint() {}
87 virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal)
92 virtual btVector3 getVa() const
94 return btVector3(0, 0, 0);
97 virtual btVector3 getVb() const
99 return btVector3(0, 0, 0);
102 virtual btVector3 getDv(const btSoftBody::Node* n) const
104 return btVector3(0, 0, 0);
107 virtual void applyImpulse(const btVector3& impulse) {}
108 virtual void setPenetrationScale(btScalar scale) {}
112 // Anchor Constraint between rigid and deformable node
113 class btDeformableNodeAnchorConstraint : public btDeformableContactConstraint
116 const btSoftBody::DeformableNodeRigidAnchor* m_anchor;
118 btDeformableNodeAnchorConstraint(const btSoftBody::DeformableNodeRigidAnchor& c, const btContactSolverInfo& infoGlobal);
119 btDeformableNodeAnchorConstraint(const btDeformableNodeAnchorConstraint& other);
120 btDeformableNodeAnchorConstraint() {}
121 virtual ~btDeformableNodeAnchorConstraint()
124 virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal);
126 // object A is the rigid/multi body, and object B is the deformable node/face
127 virtual btVector3 getVa() const;
128 // get the velocity of the deformable node in contact
129 virtual btVector3 getVb() const;
130 virtual btVector3 getDv(const btSoftBody::Node* n) const
132 return btVector3(0, 0, 0);
134 virtual void applyImpulse(const btVector3& impulse);
136 virtual void setPenetrationScale(btScalar scale) {}
140 // Constraint between rigid/multi body and deformable objects
141 class btDeformableRigidContactConstraint : public btDeformableContactConstraint
144 btVector3 m_total_normal_dv;
145 btVector3 m_total_tangent_dv;
146 btScalar m_penetration;
147 btScalar m_total_split_impulse;
149 const btSoftBody::DeformableRigidContact* m_contact;
151 btDeformableRigidContactConstraint(const btSoftBody::DeformableRigidContact& c, const btContactSolverInfo& infoGlobal);
152 btDeformableRigidContactConstraint(const btDeformableRigidContactConstraint& other);
153 btDeformableRigidContactConstraint() : m_binding(false) {}
154 virtual ~btDeformableRigidContactConstraint()
158 // object A is the rigid/multi body, and object B is the deformable node/face
159 virtual btVector3 getVa() const;
161 // get the split impulse velocity of the deformable face at the contact point
162 virtual btVector3 getSplitVb() const = 0;
164 // get the split impulse velocity of the rigid/multibdoy at the contaft
165 virtual btVector3 getSplitVa() const;
167 virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal);
169 virtual void setPenetrationScale(btScalar scale)
171 m_penetration *= scale;
174 btScalar solveSplitImpulse(const btContactSolverInfo& infoGlobal);
176 virtual void applySplitImpulse(const btVector3& impulse) = 0;
180 // Constraint between rigid/multi body and deformable objects nodes
181 class btDeformableNodeRigidContactConstraint : public btDeformableRigidContactConstraint
184 // the deformable node in contact
185 btSoftBody::Node* m_node;
187 btDeformableNodeRigidContactConstraint(const btSoftBody::DeformableNodeRigidContact& contact, const btContactSolverInfo& infoGlobal);
188 btDeformableNodeRigidContactConstraint(const btDeformableNodeRigidContactConstraint& other);
189 btDeformableNodeRigidContactConstraint() {}
190 virtual ~btDeformableNodeRigidContactConstraint()
194 // get the velocity of the deformable node in contact
195 virtual btVector3 getVb() const;
197 // get the split impulse velocity of the deformable face at the contact point
198 virtual btVector3 getSplitVb() const;
200 // get the velocity change of the input soft body node in the constraint
201 virtual btVector3 getDv(const btSoftBody::Node*) const;
203 // cast the contact to the desired type
204 const btSoftBody::DeformableNodeRigidContact* getContact() const
206 return static_cast<const btSoftBody::DeformableNodeRigidContact*>(m_contact);
209 virtual void applyImpulse(const btVector3& impulse);
211 virtual void applySplitImpulse(const btVector3& impulse);
215 // Constraint between rigid/multi body and deformable objects faces
216 class btDeformableFaceRigidContactConstraint : public btDeformableRigidContactConstraint
219 btSoftBody::Face* m_face;
220 bool m_useStrainLimiting;
221 btDeformableFaceRigidContactConstraint(const btSoftBody::DeformableFaceRigidContact& contact, const btContactSolverInfo& infoGlobal, bool useStrainLimiting);
222 btDeformableFaceRigidContactConstraint(const btDeformableFaceRigidContactConstraint& other);
223 btDeformableFaceRigidContactConstraint() : m_useStrainLimiting(false) {}
224 virtual ~btDeformableFaceRigidContactConstraint()
228 // get the velocity of the deformable face at the contact point
229 virtual btVector3 getVb() const;
231 // get the split impulse velocity of the deformable face at the contact point
232 virtual btVector3 getSplitVb() const;
234 // get the velocity change of the input soft body node in the constraint
235 virtual btVector3 getDv(const btSoftBody::Node*) const;
237 // cast the contact to the desired type
238 const btSoftBody::DeformableFaceRigidContact* getContact() const
240 return static_cast<const btSoftBody::DeformableFaceRigidContact*>(m_contact);
243 virtual void applyImpulse(const btVector3& impulse);
245 virtual void applySplitImpulse(const btVector3& impulse);
249 // Constraint between deformable objects faces and deformable objects nodes
250 class btDeformableFaceNodeContactConstraint : public btDeformableContactConstraint
253 btSoftBody::Node* m_node;
254 btSoftBody::Face* m_face;
255 const btSoftBody::DeformableFaceNodeContact* m_contact;
256 btVector3 m_total_normal_dv;
257 btVector3 m_total_tangent_dv;
259 btDeformableFaceNodeContactConstraint(const btSoftBody::DeformableFaceNodeContact& contact, const btContactSolverInfo& infoGlobal);
260 btDeformableFaceNodeContactConstraint() {}
261 virtual ~btDeformableFaceNodeContactConstraint() {}
263 virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal);
265 // get the velocity of the object A in the contact
266 virtual btVector3 getVa() const;
268 // get the velocity of the object B in the contact
269 virtual btVector3 getVb() const;
271 // get the velocity change of the input soft body node in the constraint
272 virtual btVector3 getDv(const btSoftBody::Node*) const;
274 // cast the contact to the desired type
275 const btSoftBody::DeformableFaceNodeContact* getContact() const
277 return static_cast<const btSoftBody::DeformableFaceNodeContact*>(m_contact);
280 virtual void applyImpulse(const btVector3& impulse);
282 virtual void setPenetrationScale(btScalar scale) {}
284 #endif /* BT_DEFORMABLE_CONTACT_CONSTRAINT_H */