Bullet Collision Detection & Physics Library
btDeformableMousePickingForce.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_MOUSE_PICKING_FORCE_H
17#define BT_MOUSE_PICKING_FORCE_H
18
20
22{
23 // If true, the damping force will be in the direction of the spring
24 // If false, the damping force will be in the direction of the velocity
29
30public:
33 {
34 }
35
36 virtual void addScaledForces(btScalar scale, TVStack& force)
37 {
40 }
41
43 {
45 }
46
48 {
49 for (int i = 0; i < 3; ++i)
50 {
53 if ((m_face.m_n[i]->m_x - m_mouse_pos).norm() > SIMD_EPSILON)
54 {
55 btVector3 dir = (m_face.m_n[i]->m_x - m_mouse_pos).normalized();
57 }
59 }
60 }
61
63 {
65 for (int i = 0; i < 3; ++i)
66 {
69 if (scaled_force.safeNorm() > m_maxForce)
70 {
73 }
75 }
76 }
77
79 {
81 for (int i = 0; i < 3; ++i)
82 {
84 if ((m_face.m_n[i]->m_x - m_mouse_pos).norm() > SIMD_EPSILON)
85 {
86 btVector3 dir = (m_face.m_n[i]->m_x - m_mouse_pos).normalized();
88 }
90 }
91 }
92
94
95 virtual double totalElasticEnergy(btScalar dt)
96 {
97 double energy = 0;
98 for (int i = 0; i < 3; ++i)
99 {
102 if (scaled_force.safeNorm() > m_maxForce)
103 {
106 }
107 energy += 0.5 * scaled_force.dot(dir);
108 }
109 return energy;
110 }
111
112 virtual double totalDampingEnergy(btScalar dt)
113 {
114 double energy = 0;
115 for (int i = 0; i < 3; ++i)
116 {
119 if ((m_face.m_n[i]->m_x - m_mouse_pos).norm() > SIMD_EPSILON)
120 {
121 btVector3 dir = (m_face.m_n[i]->m_x - m_mouse_pos).normalized();
123 }
124 energy -= scaled_force.dot(m_face.m_n[i]->m_v) / dt;
125 }
126 return energy;
127 }
128
130 {
132 for (int i = 0; i < 3; ++i)
133 {
137 int id = m_face.m_n[i]->index;
138 btVector3 dx_diff = dx[id];
139 btScalar r = 0; // rest length is 0 for picking spring
140 btVector3 scaled_df = btVector3(0, 0, 0);
142 {
146 }
147 df[id] += scaled_df;
148 }
149 }
150
151 void setMousePos(const btVector3& p)
152 {
153 m_mouse_pos = p;
154 }
155
157 {
159 }
160};
161
162#endif /* btMassSpring_h */
btDeformableLagrangianForceType
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define SIMD_EPSILON
Definition btScalar.h:543
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
virtual void addScaledDampingForceDifferential(btScalar scale, const TVStack &dv, TVStack &df)
virtual void addScaledDampingForce(btScalar scale, TVStack &force)
virtual double totalElasticEnergy(btScalar dt)
virtual btDeformableLagrangianForceType getForceType()
virtual void buildDampingForceDifferentialDiagonal(btScalar scale, TVStack &diagA)
virtual double totalDampingEnergy(btScalar dt)
virtual void addScaledExplicitForce(btScalar scale, TVStack &force)
btDeformableMousePickingForce(btScalar k, btScalar d, const btSoftBody::Face &face, const btVector3 &mouse_pos, btScalar maxForce=0.3)
btAlignedObjectArray< btVector3 > TVStack
virtual void addScaledForces(btScalar scale, TVStack &force)
virtual void addScaledElasticForce(btScalar scale, TVStack &force)
virtual void addScaledElasticForceDifferential(btScalar scale, const TVStack &dx, TVStack &df)
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btVector3 & safeNormalize()
Definition btVector3.h:286
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition btVector3.h:229
btScalar norm() const
Return the norm (length) of the vector.
Definition btVector3.h:263
btVector3 normalized() const
Return a normalized version of this vector.
Definition btVector3.h:949