16 #ifndef BT_MASS_SPRING_H
17 #define BT_MASS_SPRING_H
25 bool m_momentum_conserving;
26 btScalar m_elasticStiffness, m_dampingStiffness, m_bendingStiffness;
33 btDeformableMassSpringForce(
btScalar k,
btScalar d,
bool conserve_angular =
true,
double bending_k = -1) : m_momentum_conserving(conserve_angular), m_elasticStiffness(k), m_dampingStiffness(d), m_bendingStiffness(bending_k)
35 if (m_bendingStiffness <
btScalar(0))
37 m_bendingStiffness = m_elasticStiffness;
68 size_t id1 = node1->
index;
69 size_t id2 = node2->
index;
73 btVector3 scaled_force = scale * m_dampingStiffness * v_diff;
74 if (m_momentum_conserving)
79 scaled_force = scale * m_dampingStiffness * v_diff.dot(dir) * dir;
82 force[id1] += scaled_force;
83 force[id2] -= scaled_force;
105 size_t id1 = node1->
index;
106 size_t id2 = node2->
index;
111 btScalar scaled_stiffness = scale * (link.m_bbending ? m_bendingStiffness : m_elasticStiffness);
112 btVector3 scaled_force = scaled_stiffness * (dir - dir_normalized *
r);
113 force[id1] += scaled_force;
114 force[id2] -= scaled_force;
125 if (!psb->isActive())
129 btScalar scaled_k_damp = m_dampingStiffness * scale;
135 size_t id1 = node1->
index;
136 size_t id2 = node2->
index;
138 btVector3 local_scaled_df = scaled_k_damp * (dv[id2] - dv[id1]);
139 if (m_momentum_conserving)
144 local_scaled_df = scaled_k_damp * (dv[id2] - dv[id1]).
dot(dir) * dir;
147 df[id1] += local_scaled_df;
148 df[id2] -= local_scaled_df;
159 if (!psb->isActive())
163 btScalar scaled_k_damp = m_dampingStiffness * scale;
169 size_t id1 = node1->
index;
170 size_t id2 = node2->
index;
171 if (m_momentum_conserving)
176 for (
int d = 0; d < 3; ++d)
179 diagA[id1][d] -= scaled_k_damp * dir[d] * dir[d];
181 diagA[id2][d] -= scaled_k_damp * dir[d] * dir[d];
187 for (
int d = 0; d < 3; ++d)
190 diagA[id1][d] -= scaled_k_damp;
192 diagA[id2][d] -= scaled_k_damp;
205 if (!psb->isActive())
218 energy += 0.5 * m_elasticStiffness * (dir.norm() -
r) * (dir.norm() -
r);
231 if (!psb->isActive())
241 dampingForce.
resize(sz + 1);
242 for (
int i = 0; i < dampingForce.
size(); ++i)
251 energy -= dampingForce[
node.index].dot(
node.m_v) / dt;
263 if (!psb->isActive())
272 size_t id1 = node1->
index;
273 size_t id2 = node2->
index;
281 btScalar scaled_k = scale * (link.m_bbending ? m_bendingStiffness : m_elasticStiffness);
284 scaled_df -= scaled_k * dir_normalized.dot(dx_diff) * dir_normalized;
285 scaled_df += scaled_k * dir_normalized.dot(dx_diff) * ((dir_norm -
r) / dir_norm) * dir_normalized;
286 scaled_df -= scaled_k * ((dir_norm -
r) / dir_norm) * dx_diff;
289 df[id1] += scaled_df;
290 df[id2] -= scaled_df;
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
void setZero()
Set the matrix to the identity.
SIMD_FORCE_INLINE const T & btMax(const T &a, const T &b)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
SIMD_FORCE_INLINE btVector3 normalized() const
Return a normalized version of this vector.
SIMD_FORCE_INLINE int size() const
return the number of elements in the array
SIMD_FORCE_INLINE void resize(int newsize, const T &fillData=T())
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)