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;
27 
28  // normal of the contact
30 
31  btDeformableContactConstraint(const btVector3& normal): m_static(false), m_normal(normal)
32  {
33  }
34 
35  btDeformableContactConstraint(bool isStatic, const btVector3& normal): m_static(isStatic), m_normal(normal)
36  {
37  }
38 
40  : m_static(other.m_static)
41  , m_normal(other.m_normal)
42  {
43 
44  }
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() = 0;
52 
53  // solve the position error by applying an inelastic impulse that changes only the position (not velocity)
54  virtual btScalar solveSplitImpulse(const btContactSolverInfo& infoGlobal) = 0;
55 
56  // get the velocity of the object A in the contact
57  virtual btVector3 getVa() const = 0;
58 
59  // get the velocity of the object B in the contact
60  virtual btVector3 getVb() const = 0;
61 
62  // get the velocity change of the soft body node in the constraint
63  virtual btVector3 getDv(const btSoftBody::Node*) const = 0;
64 
65  // apply impulse to the soft body node and/or face involved
66  virtual void applyImpulse(const btVector3& impulse) = 0;
67 
68  // apply position based impulse to the soft body node and/or face involved
69  virtual void applySplitImpulse(const btVector3& impulse) = 0;
70 
71  // scale the penetration depth by erp
72  virtual void setPenetrationScale(btScalar scale) = 0;
73 };
74 
75 //
76 // Constraint that a certain node in the deformable objects cannot move
78 {
79 public:
81 
83 
85  {
86  }
87 
89  : m_node(other.m_node)
91  {
92 
93  }
94 
96 
98  {
99  return 0;
100  }
101 
102  virtual btScalar solveSplitImpulse(const btContactSolverInfo& infoGlobal)
103  {
104  return 0;
105  }
106 
107  virtual btVector3 getVa() const
108  {
109  return btVector3(0,0,0);
110  }
111 
112  virtual btVector3 getVb() const
113  {
114  return btVector3(0,0,0);
115  }
116 
117  virtual btVector3 getDv(const btSoftBody::Node* n) const
118  {
119  return btVector3(0,0,0);
120  }
121 
122  virtual void applyImpulse(const btVector3& impulse){}
123  virtual void applySplitImpulse(const btVector3& impulse){}
124  virtual void setPenetrationScale(btScalar scale){}
125 };
126 
127 //
128 // Anchor Constraint between rigid and deformable node
130 {
131 public:
133 
138  {
139  }
140  virtual btScalar solveConstraint();
141  virtual btScalar solveSplitImpulse(const btContactSolverInfo& infoGlobal)
142  {
143  // todo xuchenhan@
144  return 0;
145  }
146  // object A is the rigid/multi body, and object B is the deformable node/face
147  virtual btVector3 getVa() const;
148  // get the velocity of the deformable node in contact
149  virtual btVector3 getVb() const;
150  virtual btVector3 getDv(const btSoftBody::Node* n) const
151  {
152  return btVector3(0,0,0);
153  }
154  virtual void applyImpulse(const btVector3& impulse);
155  virtual void applySplitImpulse(const btVector3& impulse)
156  {
157  // todo xuchenhan@
158  };
159  virtual void setPenetrationScale(btScalar scale){}
160 };
161 
162 
163 //
164 // Constraint between rigid/multi body and deformable objects
166 {
167 public:
172 
177  {
178  }
179 
180  // object A is the rigid/multi body, and object B is the deformable node/face
181  virtual btVector3 getVa() const;
182 
183  virtual btScalar solveConstraint();
184 
185  virtual btScalar solveSplitImpulse(const btContactSolverInfo& infoGlobal);
186 
187  virtual void setPenetrationScale(btScalar scale)
188  {
189  m_penetration *= scale;
190  }
191 };
192 
193 //
194 // Constraint between rigid/multi body and deformable objects nodes
196 {
197 public:
198  // the deformable node in contact
200 
204 
206  {
207  }
208 
209  // get the velocity of the deformable node in contact
210  virtual btVector3 getVb() const;
211 
212  // get the velocity change of the input soft body node in the constraint
213  virtual btVector3 getDv(const btSoftBody::Node*) const;
214 
215  // cast the contact to the desired type
217  {
218  return static_cast<const btSoftBody::DeformableNodeRigidContact*>(m_contact);
219  }
220 
221  virtual void applyImpulse(const btVector3& impulse);
222  virtual void applySplitImpulse(const btVector3& impulse);
223 };
224 
225 //
226 // Constraint between rigid/multi body and deformable objects faces
228 {
229 public:
234 
236  {
237  }
238 
239  // get the velocity of the deformable face at the contact point
240  virtual btVector3 getVb() const;
241 
242  // get the velocity change of the input soft body node in the constraint
243  virtual btVector3 getDv(const btSoftBody::Node*) const;
244 
245  // cast the contact to the desired type
247  {
248  return static_cast<const btSoftBody::DeformableFaceRigidContact*>(m_contact);
249  }
250 
251  virtual void applyImpulse(const btVector3& impulse);
252  virtual void applySplitImpulse(const btVector3& impulse);
253 };
254 
255 //
256 // Constraint between deformable objects faces and deformable objects nodes
258 {
259 public:
265 
267 
269 
271 
272  virtual btScalar solveConstraint();
273 
274  virtual btScalar solveSplitImpulse(const btContactSolverInfo& infoGlobal)
275  {
276  // todo: xuchenhan@
277  return 0;
278  }
279 
280  // get the velocity of the object A in the contact
281  virtual btVector3 getVa() const;
282 
283  // get the velocity of the object B in the contact
284  virtual btVector3 getVb() const;
285 
286  // get the velocity change of the input soft body node in the constraint
287  virtual btVector3 getDv(const btSoftBody::Node*) const;
288 
289  // cast the contact to the desired type
291  {
292  return static_cast<const btSoftBody::DeformableFaceNodeContact*>(m_contact);
293  }
294 
295  virtual void applyImpulse(const btVector3& impulse);
296  virtual void applySplitImpulse(const btVector3& impulse)
297  {
298  // todo xuchenhan@
299  }
300  virtual void setPenetrationScale(btScalar scale){}
301 };
302 #endif /* BT_DEFORMABLE_CONTACT_CONSTRAINT_H */
btDeformableStaticConstraint::m_node
const btSoftBody::Node * m_node
Definition: btDeformableContactConstraint.h:80
btDeformableContactConstraint::m_normal
btVector3 m_normal
Definition: btDeformableContactConstraint.h:29
btDeformableStaticConstraint::btDeformableStaticConstraint
btDeformableStaticConstraint(const btDeformableStaticConstraint &other)
Definition: btDeformableContactConstraint.h:88
btDeformableFaceNodeContactConstraint::getVa
virtual btVector3 getVa() const
Definition: btDeformableContactConstraint.cpp:460
btDeformableFaceNodeContactConstraint::m_node
btSoftBody::Node * m_node
Definition: btDeformableContactConstraint.h:260
btDeformableRigidContactConstraint::~btDeformableRigidContactConstraint
virtual ~btDeformableRigidContactConstraint()
Definition: btDeformableContactConstraint.h:176
btDeformableFaceRigidContactConstraint
Definition: btDeformableContactConstraint.h:227
btDeformableRigidContactConstraint::getVa
virtual btVector3 getVa() const
Definition: btDeformableContactConstraint.cpp:157
btDeformableContactConstraint
Definition: btDeformableContactConstraint.h:21
btDeformableNodeRigidContactConstraint::m_node
const btSoftBody::Node * m_node
Definition: btDeformableContactConstraint.h:199
btDeformableNodeRigidContactConstraint::getVb
virtual btVector3 getVb() const
Definition: btDeformableContactConstraint.cpp:334
btContactSolverInfo
Definition: btContactSolverInfo.h:72
btDeformableFaceRigidContactConstraint::getContact
const btSoftBody::DeformableFaceRigidContact * getContact() const
Definition: btDeformableContactConstraint.h:246
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btDeformableContactConstraint::btDeformableContactConstraint
btDeformableContactConstraint()
Definition: btDeformableContactConstraint.h:45
btDeformableFaceRigidContactConstraint::m_face
const btSoftBody::Face * m_face
Definition: btDeformableContactConstraint.h:230
btDeformableRigidContactConstraint::btDeformableRigidContactConstraint
btDeformableRigidContactConstraint()
Definition: btDeformableContactConstraint.h:173
btDeformableFaceRigidContactConstraint::btDeformableFaceRigidContactConstraint
btDeformableFaceRigidContactConstraint()
Definition: btDeformableContactConstraint.h:231
btSoftBody::DeformableNodeRigidContact
Definition: btSoftBody.h:354
btDeformableNodeAnchorConstraint
Definition: btDeformableContactConstraint.h:129
btDeformableStaticConstraint::btDeformableStaticConstraint
btDeformableStaticConstraint(const btSoftBody::Node *node)
Definition: btDeformableContactConstraint.h:84
btDeformableNodeRigidContactConstraint
Definition: btDeformableContactConstraint.h:195
btDeformableFaceNodeContactConstraint
Definition: btDeformableContactConstraint.h:257
btDeformableRigidContactConstraint::m_penetration
btScalar m_penetration
Definition: btDeformableContactConstraint.h:170
btDeformableNodeAnchorConstraint::solveSplitImpulse
virtual btScalar solveSplitImpulse(const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.h:141
btDeformableContactConstraint::solveConstraint
virtual btScalar solveConstraint()=0
btDeformableStaticConstraint
Definition: btDeformableContactConstraint.h:77
btDeformableContactConstraint::getVa
virtual btVector3 getVa() const =0
btDeformableStaticConstraint::setPenetrationScale
virtual void setPenetrationScale(btScalar scale)
Definition: btDeformableContactConstraint.h:124
btDeformableFaceNodeContactConstraint::getContact
const btSoftBody::DeformableFaceNodeContact * getContact() const
Definition: btDeformableContactConstraint.h:290
btDeformableNodeAnchorConstraint::btDeformableNodeAnchorConstraint
btDeformableNodeAnchorConstraint()
Definition: btDeformableContactConstraint.h:134
btDeformableFaceNodeContactConstraint::solveSplitImpulse
virtual btScalar solveSplitImpulse(const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.h:274
btDeformableContactConstraint::btDeformableContactConstraint
btDeformableContactConstraint(const btDeformableContactConstraint &other)
Definition: btDeformableContactConstraint.h:39
btDeformableContactConstraint::btDeformableContactConstraint
btDeformableContactConstraint(const btVector3 &normal)
Definition: btDeformableContactConstraint.h:31
btDeformableNodeRigidContactConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *) const
Definition: btDeformableContactConstraint.cpp:340
btDeformableFaceNodeContactConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *) const
Definition: btDeformableContactConstraint.cpp:472
btSoftBody::Node
Definition: btSoftBody.h:255
btDeformableNodeAnchorConstraint::getVa
virtual btVector3 getVa() const
Definition: btDeformableContactConstraint.cpp:30
btDeformableStaticConstraint::getVa
virtual btVector3 getVa() const
Definition: btDeformableContactConstraint.h:107
btDeformableNodeRigidContactConstraint::btDeformableNodeRigidContactConstraint
btDeformableNodeRigidContactConstraint()
Definition: btDeformableContactConstraint.h:201
btDeformableContactConstraint::getVb
virtual btVector3 getVb() const =0
btDeformableStaticConstraint::btDeformableStaticConstraint
btDeformableStaticConstraint()
Definition: btDeformableContactConstraint.h:82
btSoftBody::DeformableNodeRigidAnchor
Definition: btSoftBody.h:360
btDeformableFaceRigidContactConstraint::~btDeformableFaceRigidContactConstraint
virtual ~btDeformableFaceRigidContactConstraint()
Definition: btDeformableContactConstraint.h:235
btDeformableFaceNodeContactConstraint::applySplitImpulse
virtual void applySplitImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.h:296
btDeformableRigidContactConstraint::setPenetrationScale
virtual void setPenetrationScale(btScalar scale)
Definition: btDeformableContactConstraint.h:187
btDeformableNodeAnchorConstraint::solveConstraint
virtual btScalar solveConstraint()
Definition: btDeformableContactConstraint.cpp:82
btDeformableNodeAnchorConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *n) const
Definition: btDeformableContactConstraint.h:150
btDeformableStaticConstraint::solveConstraint
virtual btScalar solveConstraint()
Definition: btDeformableContactConstraint.h:97
btDeformableContactConstraint::~btDeformableContactConstraint
virtual ~btDeformableContactConstraint()
Definition: btDeformableContactConstraint.h:47
btSoftBody::Face
Definition: btSoftBody.h:285
btDeformableNodeAnchorConstraint::applySplitImpulse
virtual void applySplitImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.h:155
btDeformableFaceNodeContactConstraint::solveConstraint
virtual btScalar solveConstraint()
Definition: btDeformableContactConstraint.cpp:490
btDeformableRigidContactConstraint::solveSplitImpulse
virtual btScalar solveSplitImpulse(const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.cpp:291
btDeformableStaticConstraint::~btDeformableStaticConstraint
virtual ~btDeformableStaticConstraint()
Definition: btDeformableContactConstraint.h:95
btDeformableFaceNodeContactConstraint::getVb
virtual btVector3 getVb() const
Definition: btDeformableContactConstraint.cpp:465
btDeformableNodeAnchorConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:130
btDeformableContactConstraint::setPenetrationScale
virtual void setPenetrationScale(btScalar scale)=0
btDeformableFaceNodeContactConstraint::~btDeformableFaceNodeContactConstraint
virtual ~btDeformableFaceNodeContactConstraint()
Definition: btDeformableContactConstraint.h:270
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:80
btDeformableNodeRigidContactConstraint::getContact
const btSoftBody::DeformableNodeRigidContact * getContact() const
Definition: btDeformableContactConstraint.h:216
btDeformableContactConstraint::m_static
bool m_static
Definition: btDeformableContactConstraint.h:26
btDeformableNodeAnchorConstraint::setPenetrationScale
virtual void setPenetrationScale(btScalar scale)
Definition: btDeformableContactConstraint.h:159
btDeformableFaceRigidContactConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *) const
Definition: btDeformableContactConstraint.cpp:380
btDeformableFaceNodeContactConstraint::btDeformableFaceNodeContactConstraint
btDeformableFaceNodeContactConstraint()
Definition: btDeformableContactConstraint.h:266
btSoftBody::DeformableFaceRigidContact
Definition: btSoftBody.h:366
btDeformableRigidContactConstraint
Definition: btDeformableContactConstraint.h:165
btDeformableStaticConstraint::solveSplitImpulse
virtual btScalar solveSplitImpulse(const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactConstraint.h:102
btDeformableStaticConstraint::applySplitImpulse
virtual void applySplitImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.h:123
btDeformableNodeAnchorConstraint::m_anchor
const btSoftBody::DeformableNodeRigidAnchor * m_anchor
Definition: btDeformableContactConstraint.h:132
btDeformableStaticConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.h:122
btDeformableFaceNodeContactConstraint::m_total_normal_dv
btVector3 m_total_normal_dv
Definition: btDeformableContactConstraint.h:263
btDeformableRigidContactConstraint::m_contact
const btSoftBody::DeformableRigidContact * m_contact
Definition: btDeformableContactConstraint.h:171
btDeformableStaticConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *n) const
Definition: btDeformableContactConstraint.h:117
btDeformableNodeRigidContactConstraint::applySplitImpulse
virtual void applySplitImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:352
btDeformableContactConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)=0
btDeformableStaticConstraint::getVb
virtual btVector3 getVb() const
Definition: btDeformableContactConstraint.h:112
btDeformableFaceRigidContactConstraint::getVb
virtual btVector3 getVb() const
Definition: btDeformableContactConstraint.cpp:372
btSoftBody::DeformableFaceNodeContact
Definition: btSoftBody.h:375
btDeformableFaceNodeContactConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:551
btDeformableNodeAnchorConstraint::~btDeformableNodeAnchorConstraint
virtual ~btDeformableNodeAnchorConstraint()
Definition: btDeformableContactConstraint.h:137
btDeformableNodeAnchorConstraint::getVb
virtual btVector3 getVb() const
Definition: btDeformableContactConstraint.cpp:125
btDeformableRigidContactConstraint::m_total_normal_dv
btVector3 m_total_normal_dv
Definition: btDeformableContactConstraint.h:168
btDeformableFaceNodeContactConstraint::m_face
btSoftBody::Face * m_face
Definition: btDeformableContactConstraint.h:261
btDeformableFaceRigidContactConstraint::applySplitImpulse
virtual void applySplitImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:429
btDeformableContactConstraint::applySplitImpulse
virtual void applySplitImpulse(const btVector3 &impulse)=0
btDeformableFaceRigidContactConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:396
btSoftBody::DeformableRigidContact
Definition: btSoftBody.h:336
btDeformableFaceNodeContactConstraint::m_contact
const btSoftBody::DeformableFaceNodeContact * m_contact
Definition: btDeformableContactConstraint.h:262
btDeformableNodeRigidContactConstraint::applyImpulse
virtual void applyImpulse(const btVector3 &impulse)
Definition: btDeformableContactConstraint.cpp:345
btDeformableNodeRigidContactConstraint::~btDeformableNodeRigidContactConstraint
virtual ~btDeformableNodeRigidContactConstraint()
Definition: btDeformableContactConstraint.h:205
btDeformableFaceNodeContactConstraint::m_total_tangent_dv
btVector3 m_total_tangent_dv
Definition: btDeformableContactConstraint.h:264
btDeformableFaceNodeContactConstraint::setPenetrationScale
virtual void setPenetrationScale(btScalar scale)
Definition: btDeformableContactConstraint.h:300
btDeformableRigidContactConstraint::m_total_tangent_dv
btVector3 m_total_tangent_dv
Definition: btDeformableContactConstraint.h:169
btDeformableContactConstraint::solveSplitImpulse
virtual btScalar solveSplitImpulse(const btContactSolverInfo &infoGlobal)=0
btSoftBody.h
btDeformableRigidContactConstraint::solveConstraint
virtual btScalar solveConstraint()
Definition: btDeformableContactConstraint.cpp:209
btDeformableContactConstraint::btDeformableContactConstraint
btDeformableContactConstraint(bool isStatic, const btVector3 &normal)
Definition: btDeformableContactConstraint.h:35
btDeformableContactConstraint::getDv
virtual btVector3 getDv(const btSoftBody::Node *) const =0