better logic for tension contribution

This commit is contained in:
Irlan 2018-05-14 13:08:31 -03:00
parent ba544379c5
commit b8ca0d3829
2 changed files with 26 additions and 29 deletions

View File

@ -313,11 +313,9 @@ void b3SpringCloth::GetTension(b3Array<b3Vec3>& T) const
b3Vec3 dx = x1 - x2;
float32 L = b3Length(dx);
if (L < L0)
if (L >= L0)
{
L = L0;
}
// Force is tension.
b3Vec3 n = dx / L;
b3Vec3 sf1 = -ks * (L - L0) * n;
@ -325,6 +323,7 @@ void b3SpringCloth::GetTension(b3Array<b3Vec3>& T) const
T[i1] += sf1;
T[i2] += sf2;
}
// Damping
b3Vec3 dv = v1 - v2;

View File

@ -195,16 +195,15 @@ void b3SpringSolver::ApplySpringForces()
b3Vec3 x2 = m_x[i2];
b3Vec3 v2 = m_v[i2];
// Compute strech forces
const b3Mat33 I = b3Mat33_identity;
// Strech
b3Vec3 dx = x1 - x2;
float32 L = b3Length(dx);
// Ensure force is a tension.
if (L < L0)
if (L >= L0)
{
L = L0;
}
// Force is tension.
b3Vec3 n = dx / L;
b3Vec3 sf1 = -ks * (L - L0) * n;
@ -213,13 +212,12 @@ void b3SpringSolver::ApplySpringForces()
m_f[i1] += sf1;
m_f[i2] += sf2;
const b3Mat33 I = b3Mat33_identity;
b3Mat33 Jx11 = -ks * (b3Outer(dx, dx) + (1.0f - L0 / L) * (I - b3Outer(dx, dx)));
m_Jx[i] = Jx11;
}
// Compute damping forces
// Damping
b3Vec3 dv = v1 - v2;
b3Vec3 df1 = -kd * dv;