Blender  V3.3
btDeformableGravityForce.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_GRAVITY_FORCE_H
17 #define BT_DEFORMABLE_GRAVITY_FORCE_H
18 
20 
22 {
23 public:
26 
28  {
29  }
30 
31  virtual void addScaledForces(btScalar scale, TVStack& force)
32  {
33  addScaledGravityForce(scale, force);
34  }
35 
36  virtual void addScaledExplicitForce(btScalar scale, TVStack& force)
37  {
38  addScaledGravityForce(scale, force);
39  }
40 
41  virtual void addScaledDampingForce(btScalar scale, TVStack& force)
42  {
43  }
44 
45  virtual void addScaledElasticForceDifferential(btScalar scale, const TVStack& dx, TVStack& df)
46  {
47  }
48 
49  virtual void addScaledDampingForceDifferential(btScalar scale, const TVStack& dv, TVStack& df)
50  {
51  }
52 
54 
55  virtual void addScaledGravityForce(btScalar scale, TVStack& force)
56  {
57  int numNodes = getNumNodes();
58  btAssert(numNodes <= force.size());
59  for (int i = 0; i < m_softBodies.size(); ++i)
60  {
61  btSoftBody* psb = m_softBodies[i];
62  if (!psb->isActive())
63  {
64  continue;
65  }
66  for (int j = 0; j < psb->m_nodes.size(); ++j)
67  {
68  btSoftBody::Node& n = psb->m_nodes[j];
69  size_t id = n.index;
70  btScalar mass = (n.m_im == 0) ? 0 : 1. / n.m_im;
71  btVector3 scaled_force = scale * m_gravity * mass * m_softBodies[i]->m_gravityFactor;
72  force[id] += scaled_force;
73  }
74  }
75  }
76 
78  {
79  return BT_GRAVITY_FORCE;
80  }
81 
82  // the gravitational potential energy
83  virtual double totalEnergy(btScalar dt)
84  {
85  double e = 0;
86  for (int i = 0; i < m_softBodies.size(); ++i)
87  {
88  btSoftBody* psb = m_softBodies[i];
89  if (!psb->isActive())
90  {
91  continue;
92  }
93  for (int j = 0; j < psb->m_nodes.size(); ++j)
94  {
95  const btSoftBody::Node& node = psb->m_nodes[j];
96  if (node.m_im > 0)
97  {
98  e -= m_gravity.dot(node.m_q) / node.m_im;
99  }
100  }
101  }
102  return e;
103  }
104 };
105 #endif /* BT_DEFORMABLE_GRAVITY_FORCE_H */
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
btDeformableLagrangianForceType
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define btAssert(x)
Definition: btScalar.h:295
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
SIMD_FORCE_INLINE int size() const
return the number of elements in the array
virtual double totalEnergy(btScalar dt)
virtual btDeformableLagrangianForceType getForceType()
virtual void addScaledGravityForce(btScalar scale, TVStack &force)
virtual void addScaledElasticForceDifferential(btScalar scale, const TVStack &dx, TVStack &df)
virtual void addScaledForces(btScalar scale, TVStack &force)
virtual void buildDampingForceDifferentialDiagonal(btScalar scale, TVStack &diagA)
virtual void addScaledDampingForce(btScalar scale, TVStack &force)
btAlignedObjectArray< btVector3 > TVStack
virtual void addScaledExplicitForce(btScalar scale, TVStack &force)
btDeformableGravityForce(const btVector3 &g)
virtual void addScaledDampingForceDifferential(btScalar scale, const TVStack &dv, TVStack &df)
btAlignedObjectArray< btSoftBody * > m_softBodies
tNodeArray m_nodes
Definition: btSoftBody.h:799
OperationNode * node
static const pxr::TfToken g("g", pxr::TfToken::Immortal)