Include Rayleigh damping. Use struct instead of class. Update PinnedSoftBody test

This commit is contained in:
Irlan 2019-05-24 13:04:42 -03:00
parent 5e044795df
commit b6f504b371
7 changed files with 44 additions and 15 deletions

View File

@ -32,7 +32,7 @@ public:
b3SoftBodyDef def;
def.mesh = &m_mesh;
def.density = 0.2f;
def.E = 100.0f;
def.E = 1000.0f;
def.nu = 0.33f;
def.c_yield = 0.1f;
def.c_creep = 0.5f;
@ -40,6 +40,12 @@ public:
m_body = new b3SoftBody(def);
for (u32 i = 0; i < m_mesh.vertexCount; ++i)
{
b3SoftBodyNode* n = m_body->GetVertexNode(i);
n->SetDamping(0.2f);
}
u32 pinIndex = ~0;
float32 pinDot = -B3_MAX_FLOAT;
for (u32 i = 0; i < m_mesh.vertexCount; ++i)

View File

@ -26,7 +26,8 @@ class b3World;
struct b3SoftBodyMesh;
class b3SoftBodyNode;
struct b3SoftBodyNode;
struct b3SoftBodyElement;
struct b3RayCastInput;
struct b3RayCastOutput;

View File

@ -24,10 +24,10 @@
class b3StackAllocator;
class b3SoftBodyNode;
struct b3SoftBodyNode;
class b3Body;
class b3NodeBodyContact;
struct b3NodeBodyContact;
struct b3DenseVec3;

View File

@ -25,15 +25,11 @@
class b3Shape;
class b3SoftBody;
class b3SoftBodyNode;
struct b3SoftBodyNode;
// A contact between a node and a body
class b3NodeBodyContact
struct b3NodeBodyContact
{
public:
b3NodeBodyContact() { }
~b3NodeBodyContact() { }
b3SoftBodyNode* n1;
b3Shape* s2;
@ -81,7 +77,7 @@ enum b3SoftBodyNodeType
};
// A soft body node.
class b3SoftBodyNode
struct b3SoftBodyNode
{
public:
// Set the node type.
@ -110,6 +106,12 @@ public:
// Get the node mass.
float32 GetMass() const;
// Set the node damping.
void SetDamping(float32 damping);
// Get the node damping.
float32 GetDamping() const;
// Set the node radius.
void SetRadius(float32 radius);
@ -151,6 +153,9 @@ private:
// Inverse mass
float32 m_invMass;
// Damping
float32 m_damping;
// Radius
float32 m_radius;
@ -227,6 +232,16 @@ inline float32 b3SoftBodyNode::GetMass() const
return m_mass;
}
inline void b3SoftBodyNode::SetDamping(float32 damping)
{
m_damping = damping;
}
inline float32 b3SoftBodyNode::GetDamping() const
{
return m_damping;
}
inline void b3SoftBodyNode::SetRadius(float32 radius)
{
m_radius = radius;

View File

@ -27,10 +27,10 @@ class b3StackAllocator;
class b3SoftBody;
class b3SoftBodyMesh;
class b3SoftBodyNode;
struct b3SoftBodyNode;
struct b3SoftBodyElement;
class b3NodeBodyContact;
struct b3NodeBodyContact;
struct b3SoftBodySolverDef
{

View File

@ -465,6 +465,7 @@ b3SoftBody::b3SoftBody(const b3SoftBodyDef& def)
n->m_force.SetZero();
n->m_mass = 0.0f;
n->m_invMass = 0.0f;
n->m_damping = 0.0f;
n->m_radius = 0.0f;
n->m_friction = 0.0f;
n->m_userData = nullptr;

View File

@ -195,6 +195,7 @@ void b3SoftBodySolver::Solve(float32 dt, const b3Vec3& gravity, u32 velocityIter
float32 inv_h = 1.0f / h;
b3SparseMat33 M(m_mesh->vertexCount);
b3SparseMat33 C(m_mesh->vertexCount);
b3DenseVec3 x(m_mesh->vertexCount);
b3DenseVec3 p(m_mesh->vertexCount);
b3DenseVec3 v(m_mesh->vertexCount);
@ -207,6 +208,12 @@ void b3SoftBodySolver::Solve(float32 dt, const b3Vec3& gravity, u32 velocityIter
b3SoftBodyNode* n = m_nodes + i;
M(i, i) = b3Diagonal(n->m_mass);
// Rayleigh damping
// C = alpha * M + beta * K
// Here the stiffness coefficient beta is zero
C(i, i) = b3Diagonal(n->m_damping * n->m_mass);
x[i] = m_mesh->vertices[i];
p[i] = n->m_position;
v[i] = n->m_velocity;
@ -369,9 +376,8 @@ void b3SoftBodySolver::Solve(float32 dt, const b3Vec3& gravity, u32 velocityIter
f0 = -f0;
b3SparseMat33 A = M + h * h * K;
b3SparseMat33 A = M + h * C + h * h * K;
//b3DenseVec3 b = M * v - h * (K * p + f0 + f_plastic - fe);
b3DenseVec3 b = M * v - h * (K * p + f0 - (f_plastic + fe));
// Solve Ax = b