Bullet Collision Detection & Physics Library: btDeformableGravityForce.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
19#include "btDeformableLagrangianForce.h"
20
21 class btDeformableGravityForce : public btDeformableLagrangianForce
22{
23public:
24 typedef btAlignedObjectArray<btVector3> TVStack;
25 btVector3 m_gravity;
26
27 btDeformableGravityForce(const btVector3& g) : m_gravity(g)
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
53 virtual void buildDampingForceDifferentialDiagonal(btScalar scale, TVStack& diagA) {}
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
77 virtual btDeformableLagrangianForceType getForceType()
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 */
btDeformableLagrangianForce.h
btDeformableLagrangianForceType
btDeformableLagrangianForceType
Definition btDeformableLagrangianForce.h:24
BT_GRAVITY_FORCE
@ BT_GRAVITY_FORCE
Definition btDeformableLagrangianForce.h:25
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
btAssert
#define btAssert(x)
Definition btScalar.h:153
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition btAlignedObjectArray.h:46
btAlignedObjectArray::size
int size() const
return the number of elements in the array
Definition btAlignedObjectArray.h:142
btCollisionObject::isActive
bool isActive() const
Definition btCollisionObject.h:306
btDeformableGravityForce
Definition btDeformableGravityForce.h:22
btDeformableGravityForce::totalEnergy
virtual double totalEnergy(btScalar dt)
Definition btDeformableGravityForce.h:83
btDeformableGravityForce::m_gravity
btVector3 m_gravity
Definition btDeformableGravityForce.h:25
btDeformableGravityForce::getForceType
virtual btDeformableLagrangianForceType getForceType()
Definition btDeformableGravityForce.h:77
btDeformableGravityForce::addScaledGravityForce
virtual void addScaledGravityForce(btScalar scale, TVStack &force)
Definition btDeformableGravityForce.h:55
btDeformableGravityForce::addScaledElasticForceDifferential
virtual void addScaledElasticForceDifferential(btScalar scale, const TVStack &dx, TVStack &df)
Definition btDeformableGravityForce.h:45
btDeformableGravityForce::addScaledForces
virtual void addScaledForces(btScalar scale, TVStack &force)
Definition btDeformableGravityForce.h:31
btDeformableGravityForce::buildDampingForceDifferentialDiagonal
virtual void buildDampingForceDifferentialDiagonal(btScalar scale, TVStack &diagA)
Definition btDeformableGravityForce.h:53
btDeformableGravityForce::addScaledDampingForce
virtual void addScaledDampingForce(btScalar scale, TVStack &force)
Definition btDeformableGravityForce.h:41
btDeformableGravityForce::TVStack
btAlignedObjectArray< btVector3 > TVStack
Definition btDeformableGravityForce.h:24
btDeformableGravityForce::addScaledExplicitForce
virtual void addScaledExplicitForce(btScalar scale, TVStack &force)
Definition btDeformableGravityForce.h:36
btDeformableGravityForce::btDeformableGravityForce
btDeformableGravityForce(const btVector3 &g)
Definition btDeformableGravityForce.h:27
btDeformableGravityForce::addScaledDampingForceDifferential
virtual void addScaledDampingForceDifferential(btScalar scale, const TVStack &dv, TVStack &df)
Definition btDeformableGravityForce.h:49
btDeformableLagrangianForce
Definition btDeformableLagrangianForce.h:39
btDeformableLagrangianForce::getNumNodes
virtual int getNumNodes()
Definition btDeformableLagrangianForce.h:78
btDeformableLagrangianForce::m_softBodies
btAlignedObjectArray< btSoftBody * > m_softBodies
Definition btDeformableLagrangianForce.h:42
btSoftBody
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition btSoftBody.h:75
btSoftBody::m_nodes
tNodeArray m_nodes
Definition btSoftBody.h:814
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btVector3::dot
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition btVector3.h:229
btSoftBody::Node
Definition btSoftBody.h:268
btSoftBody::Node::m_im
btScalar m_im
Definition btSoftBody.h:275
btSoftBody::Node::m_q
btVector3 m_q
Definition btSoftBody.h:270
btSoftBody::Node::index
int index
Definition btSoftBody.h:280