Bullet Collision Detection & Physics Library
btDeformableContactConstraint.h
Go to the documentation of this file.
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_DEFORMABLE_CONTACT_CONSTRAINT_H
17 #define BT_DEFORMABLE_CONTACT_CONSTRAINT_H
18 #include "btSoftBody.h"
19 
20 // btDeformableContactConstraint is an abstract class specifying the method that each type of contact constraint needs to implement
22 {
23 public:
24  // True if the friction is static
25  // False if the friction is dynamic
26  bool m_static;
28 
29  // normal of the contact
31 
32  btDeformableContactConstraint(const btVector3& normal, const btContactSolverInfo& infoGlobal) : m_static(false), m_normal(normal), m_infoGlobal(&infoGlobal)
33  {
34  }
35 
36  btDeformableContactConstraint(bool isStatic, const btVector3& normal, const btContactSolverInfo& infoGlobal) : m_static(isStatic), m_normal(normal), m_infoGlobal(&infoGlobal)
37  {
38  }
39 
41 
44  {
45  }
46 
48 
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;
52 
53  // get the velocity of the object A in the contact
54  virtual btVector3 getVa() const = 0;
55 
56  // get the velocity of the object B in the contact
57  virtual btVector3 getVb() const = 0;
58 
59  // get the velocity change of the soft body node in the constraint
60  virtual btVector3 getDv(const btSoftBody::Node*) const = 0;
61 
62  // apply impulse to the soft body node and/or face involved
63  virtual void applyImpulse(const btVector3& impulse) = 0;
64 
65  // scale the penetration depth by erp
66  virtual void setPenetrationScale(btScalar scale) = 0;
67 };
68 
69 //
70 // Constraint that a certain node in the deformable objects cannot move
72 {
73 public:
75 
77  {
78  }
82  {
83  }
84 
86 
87  virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal)
88  {
89  return 0;
90  }
91 
92  virtual btVector3 getVa() const
93  {
94  return btVector3(0, 0, 0);
95  }
96 
97  virtual btVector3 getVb() const
98  {
99  return btVector3(0, 0, 0);
100  }
101 
102  virtual btVector3 getDv(const btSoftBody::Node* n) const
103  {
104  return btVector3(0, 0, 0);
105  }
106 
107  virtual void applyImpulse(const btVector3& impulse) {}
108  virtual void setPenetrationScale(btScalar scale) {}
109 };
110 
111 //
112 // Anchor Constraint between rigid and deformable node
114 {
115 public:
117 
122  {
123  }
124  virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal);
125 
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
131  {
132  return btVector3(0, 0, 0);
133  }
134  virtual void applyImpulse(const btVector3& impulse);
135 
136  virtual void setPenetrationScale(btScalar scale) {}
137 };
138 
139 //
140 // Constraint between rigid/multi body and deformable objects
142 {
143 public:
148  bool m_binding;
150 
155  {
156  }
157 
158  // object A is the rigid/multi body, and object B is the deformable node/face
159  virtual btVector3 getVa() const;
160 
161  // get the split impulse velocity of the deformable face at the contact point
162  virtual btVector3 getSplitVb() const = 0;
163 
164  // get the split impulse velocity of the rigid/multibdoy at the contaft
165  virtual btVector3 getSplitVa() const;
166 
167  virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal);
168 
169  virtual void setPenetrationScale(btScalar scale)
170  {
171  m_penetration *= scale;
172  }
173 
175 
176  virtual void applySplitImpulse(const btVector3& impulse) = 0;
177 };
178 
179 //
180 // Constraint between rigid/multi body and deformable objects nodes
182 {
183 public:
184  // the deformable node in contact
186 
191  {
192  }
193 
194  // get the velocity of the deformable node in contact
195  virtual btVector3 getVb() const;
196 
197  // get the split impulse velocity of the deformable face at the contact point
198  virtual btVector3 getSplitVb() const;
199 
200  // get the velocity change of the input soft body node in the constraint
201  virtual btVector3 getDv(const btSoftBody::Node*) const;
202 
203  // cast the contact to the desired type
205  {
206  return static_cast<const btSoftBody::DeformableNodeRigidContact*>(m_contact);
207  }
208 
209  virtual void applyImpulse(const btVector3& impulse);
210 
211  virtual void applySplitImpulse(const btVector3& impulse);
212 };
213 
214 //
215 // Constraint between rigid/multi body and deformable objects faces
217 {
218 public:
221  btDeformableFaceRigidContactConstraint(const btSoftBody::DeformableFaceRigidContact& contact, const btContactSolverInfo& infoGlobal, bool useStrainLimiting);
225  {
226  }
227 
228  // get the velocity of the deformable face at the contact point
229  virtual btVector3 getVb() const;
230 
231  // get the split impulse velocity of the deformable face at the contact point
232  virtual btVector3 getSplitVb() const;
233 
234  // get the velocity change of the input soft body node in the constraint
235  virtual btVector3 getDv(const btSoftBody::Node*) const;
236 
237  // cast the contact to the desired type
239  {
240  return static_cast<const btSoftBody::DeformableFaceRigidContact*>(m_contact);
241  }
242 
243  virtual void applyImpulse(const btVector3& impulse);
244 
245  virtual void applySplitImpulse(const btVector3& impulse);
246 };
247 
248 //
249 // Constraint between deformable objects faces and deformable objects nodes
251 {
252 public:
258 
262 
263  virtual btScalar solveConstraint(const btContactSolverInfo& infoGlobal);
264 
265  // get the velocity of the object A in the contact
266  virtual btVector3 getVa() const;
267 
268  // get the velocity of the object B in the contact
269  virtual btVector3 getVb() const;
270 
271  // get the velocity change of the input soft body node in the constraint
272  virtual btVector3 getDv(const btSoftBody::Node*) const;
273 
274  // cast the contact to the desired type
276  {
277  return static_cast<const btSoftBody::DeformableFaceNodeContact*>(m_contact);
278  }
279 
280  virtual void applyImpulse(const btVector3& impulse);
281 
282  virtual void setPenetrationScale(btScalar scale) {}
283 };
284 #endif /* BT_DEFORMABLE_CONTACT_CONSTRAINT_H */
btDeformableContactConstraint::m_normal
btVector3 m_normal
Definition: btDeformableContactConstraint.h:30
btDeformableStaticConstraint::btDeformableStaticConstraint
btDeformableStaticConstraint(const btDeformableStaticConstraint &other)
Definition: btDeformableContactConstraint.h:80
btDeformableFaceNodeContactConstraint::getVa
virtual btVector3 getVa() const
Definition: btDeformableContactConstraint.cpp:600
btDeformableFaceNodeContactConstraint::m_node
btSoftBody::Node * m_node
Definition: btDeformableContactConstraint.h:253
btDeformableRigidContactConstraint::~btDeformableRigidContactConstraint
virtual ~btDeformableRigidContactConstraint()
Definition: btDeformableContactConstraint.h:154
btDeformableNodeRigidContactConstraint::getSplitVb
virtual btVector3 getSplitVb() const
Definition: btDeformableContactConstraint.cpp:426
btDeformableFaceRigidContactConstraint
Definition: btDeformableContactConstraint.h:217
btDeformableStaticConstraint::btDeformableStaticConstraint
btDeformableStaticConstraint(btSoftBody::Node *node, const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.h:76
btDeformableRigidContactConstraint::getVa
virtual btVector3 getVa() const
Definition: btDeformableContactConstraint.cpp:153
btDeformableContactConstraint
Definition: btDeformableContactConstraint.h:22
btDeformableNodeRigidContactConstraint::getVb
virtual btVector3 getVb() const
Definition: btDeformableContactConstraint.cpp:421
btContactSolverInfo
Definition: btContactSolverInfo.h:76
btDeformableFaceRigidContactConstraint::getContact
const btSoftBody::DeformableFaceRigidContact * getContact() const
Definition: btDeformableContactConstraint.h:238
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btDeformableContactConstraint::m_infoGlobal
const btContactSolverInfo * m_infoGlobal
Definition: btDeformableContactConstraint.h:27
btDeformableContactConstraint::btDeformableContactConstraint
btDeformableContactConstraint()
Definition: btDeformableContactConstraint.h:40
btDeformableRigidContactConstraint::btDeformableRigidContactConstraint
btDeformableRigidContactConstraint()
Definition: btDeformableContactConstraint.h:153
btDeformableFaceRigidContactConstraint::btDeformableFaceRigidContactConstraint
btDeformableFaceRigidContactConstraint()
Definition: btDeformableContactConstraint.h:223
btDeformableFaceRigidContactConstraint::getSplitVb
virtual btVector3 getSplitVb() const
Definition: btDeformableContactConstraint.cpp:560
btSoftBody::DeformableNodeRigidContact
Definition: btSoftBody.h:379
btDeformableNodeAnchorConstraint
Definition: btDeformableContactConstraint.h:114
btDeformableNodeRigidContactConstraint
Definition: btDeformableContactConstraint.h:182
btDeformableStaticConstraint::m_node
btSoftBody::Node * m_node
Definition: btDeformableContactConstraint.h:74
btDeformableFaceNodeContactConstraint
Definition: btDeformableContactConstraint.h:251
btDeformableRigidContactConstraint::m_penetration
btScalar m_penetration
Definition: btDeformableContactConstraint.h:146
btDeformableStaticConstraint
Definition: btDeformableContactConstraint.h:72
btDeformableContactConstraint::getVa
virtual btVector3 getVa() const =0
btDeformableStaticConstraint::setPenetrationScale
virtual void setPenetrationScale(btScalar scale)
Definition: btDeformableContactConstraint.h:108
btDeformableFaceNodeContactConstraint::getContact
const btSoftBody::DeformableFaceNodeContact * getContact() const
Definition: btDeformableContactConstraint.h:275
btDeformableContactConstraint::btDeformableContactConstraint
btDeformableContactConstraint(bool isStatic, const btVector3 &normal, const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.h:36
btDeformableNodeAnchorConstraint::btDeformableNodeAnchorConstraint
btDeformableNodeAnchorConstraint()
Definition: btDeformableContactConstraint.h:120
btDeformableContactConstraint::btDeformableContactConstraint
btDeformableContactConstraint(const btDeformableContactConstraint &other)
Definition: btDeformableContactConstraint.h:42
btDeformableNodeRigidContactConstraint::m_node
btSoftBody::Node * m_node
Definition: btDeformableContactConstraint.h:185
btDeformableNodeRigidContactConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *) const
Definition: btDeformableContactConstraint.cpp:431
btDeformableFaceNodeContactConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *) const
Definition: btDeformableContactConstraint.cpp:612
btSoftBody::Node
Definition: btSoftBody.h:268
btDeformableNodeAnchorConstraint::getVa
virtual btVector3 getVa() const
Definition: btDeformableContactConstraint.cpp:28
btDeformableStaticConstraint::getVa
virtual btVector3 getVa() const
Definition: btDeformableContactConstraint.h:92
btDeformableNodeRigidContactConstraint::btDeformableNodeRigidContactConstraint
btDeformableNodeRigidContactConstraint()
Definition: btDeformableContactConstraint.h:189
btDeformableRigidContactConstraint::solveConstraint
virtual btScalar solveConstraint(const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.cpp:256
btDeformableContactConstraint::getVb
virtual btVector3 getVb() const =0
btDeformableStaticConstraint::solveConstraint
virtual btScalar solveConstraint(const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.h:87
btDeformableStaticConstraint::btDeformableStaticConstraint
btDeformableStaticConstraint()
Definition: btDeformableContactConstraint.h:79
btSoftBody::DeformableNodeRigidAnchor
Definition: btSoftBody.h:385
btDeformableRigidContactConstraint::m_binding
bool m_binding
Definition: btDeformableContactConstraint.h:148
btDeformableContactConstraint::solveConstraint
virtual btScalar solveConstraint(const btContactSolverInfo &infoGlobal)=0
btDeformableFaceRigidContactConstraint::~btDeformableFaceRigidContactConstraint
virtual ~btDeformableFaceRigidContactConstraint()
Definition: btDeformableContactConstraint.h:224
btDeformableFaceRigidContactConstraint::m_useStrainLimiting
bool m_useStrainLimiting
Definition: btDeformableContactConstraint.h:220
btDeformableRigidContactConstraint::setPenetrationScale
virtual void setPenetrationScale(btScalar scale)
Definition: btDeformableContactConstraint.h:169
btDeformableNodeAnchorConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *n) const
Definition: btDeformableContactConstraint.h:130
btDeformableContactConstraint::~btDeformableContactConstraint
virtual ~btDeformableContactConstraint()
Definition: btDeformableContactConstraint.h:47
btDeformableRigidContactConstraint::applySplitImpulse
virtual void applySplitImpulse(const btVector3 &impulse)=0
btSoftBody::Face
Definition: btSoftBody.h:306
btDeformableRigidContactConstraint::solveSplitImpulse
btScalar solveSplitImpulse(const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.cpp:356
btDeformableStaticConstraint::~btDeformableStaticConstraint
virtual ~btDeformableStaticConstraint()
Definition: btDeformableContactConstraint.h:85
btDeformableFaceRigidContactConstraint::m_face
btSoftBody::Face * m_face
Definition: btDeformableContactConstraint.h:219
btDeformableFaceNodeContactConstraint::getVb
virtual btVector3 getVb() const
Definition: btDeformableContactConstraint.cpp:605
btDeformableNodeAnchorConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:128
btDeformableContactConstraint::setPenetrationScale
virtual void setPenetrationScale(btScalar scale)=0
btDeformableFaceNodeContactConstraint::~btDeformableFaceNodeContactConstraint
virtual ~btDeformableFaceNodeContactConstraint()
Definition: btDeformableContactConstraint.h:261
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btDeformableNodeRigidContactConstraint::getContact
const btSoftBody::DeformableNodeRigidContact * getContact() const
Definition: btDeformableContactConstraint.h:204
btDeformableContactConstraint::m_static
bool m_static
Definition: btDeformableContactConstraint.h:26
btDeformableNodeAnchorConstraint::setPenetrationScale
virtual void setPenetrationScale(btScalar scale)
Definition: btDeformableContactConstraint.h:136
btDeformableFaceRigidContactConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *) const
Definition: btDeformableContactConstraint.cpp:468
btDeformableRigidContactConstraint::getSplitVb
virtual btVector3 getSplitVb() const =0
btDeformableFaceNodeContactConstraint::btDeformableFaceNodeContactConstraint
btDeformableFaceNodeContactConstraint()
Definition: btDeformableContactConstraint.h:260
btSoftBody::DeformableFaceRigidContact
Definition: btSoftBody.h:391
btDeformableRigidContactConstraint
Definition: btDeformableContactConstraint.h:142
btDeformableNodeAnchorConstraint::m_anchor
const btSoftBody::DeformableNodeRigidAnchor * m_anchor
Definition: btDeformableContactConstraint.h:116
btDeformableStaticConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.h:107
btDeformableFaceNodeContactConstraint::m_total_normal_dv
btVector3 m_total_normal_dv
Definition: btDeformableContactConstraint.h:256
btDeformableRigidContactConstraint::getSplitVa
virtual btVector3 getSplitVa() const
Definition: btDeformableContactConstraint.cpp:205
btDeformableRigidContactConstraint::m_contact
const btSoftBody::DeformableRigidContact * m_contact
Definition: btDeformableContactConstraint.h:149
btDeformableNodeAnchorConstraint::solveConstraint
virtual btScalar solveConstraint(const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.cpp:80
btDeformableStaticConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *n) const
Definition: btDeformableContactConstraint.h:102
btDeformableFaceNodeContactConstraint::solveConstraint
virtual btScalar solveConstraint(const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.cpp:630
btDeformableNodeRigidContactConstraint::applySplitImpulse
virtual void applySplitImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:443
btDeformableContactConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)=0
btDeformableStaticConstraint::getVb
virtual btVector3 getVb() const
Definition: btDeformableContactConstraint.h:97
btDeformableFaceRigidContactConstraint::getVb
virtual btVector3 getVb() const
Definition: btDeformableContactConstraint.cpp:461
btSoftBody::DeformableFaceNodeContact
Definition: btSoftBody.h:400
btDeformableFaceNodeContactConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:691
btDeformableRigidContactConstraint::m_total_split_impulse
btScalar m_total_split_impulse
Definition: btDeformableContactConstraint.h:147
btDeformableNodeAnchorConstraint::~btDeformableNodeAnchorConstraint
virtual ~btDeformableNodeAnchorConstraint()
Definition: btDeformableContactConstraint.h:121
btDeformableNodeAnchorConstraint::getVb
virtual btVector3 getVb() const
Definition: btDeformableContactConstraint.cpp:123
btDeformableRigidContactConstraint::m_total_normal_dv
btVector3 m_total_normal_dv
Definition: btDeformableContactConstraint.h:144
btDeformableContactConstraint::btDeformableContactConstraint
btDeformableContactConstraint(const btVector3 &normal, const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.h:32
btDeformableFaceNodeContactConstraint::m_face
btSoftBody::Face * m_face
Definition: btDeformableContactConstraint.h:254
btDeformableFaceRigidContactConstraint::applySplitImpulse
virtual void applySplitImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:567
btDeformableFaceRigidContactConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:484
btSoftBody::DeformableRigidContact
Definition: btSoftBody.h:360
btDeformableFaceNodeContactConstraint::m_contact
const btSoftBody::DeformableFaceNodeContact * m_contact
Definition: btDeformableContactConstraint.h:255
btDeformableNodeRigidContactConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:436
btDeformableNodeRigidContactConstraint::~btDeformableNodeRigidContactConstraint
virtual ~btDeformableNodeRigidContactConstraint()
Definition: btDeformableContactConstraint.h:190
btDeformableFaceNodeContactConstraint::m_total_tangent_dv
btVector3 m_total_tangent_dv
Definition: btDeformableContactConstraint.h:257
btDeformableFaceNodeContactConstraint::setPenetrationScale
virtual void setPenetrationScale(btScalar scale)
Definition: btDeformableContactConstraint.h:282
btDeformableRigidContactConstraint::m_total_tangent_dv
btVector3 m_total_tangent_dv
Definition: btDeformableContactConstraint.h:145
btSoftBody.h
btDeformableContactConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *) const =0