Add more code for completeness
This commit is contained in:
parent
e32c2e61ee
commit
d863741587
@ -78,6 +78,7 @@ public:
|
|||||||
float32 fn0;
|
float32 fn0;
|
||||||
float32 fn;
|
float32 fn;
|
||||||
float32 ft1, ft2;
|
float32 ft1, ft2;
|
||||||
|
bool nActive;
|
||||||
bool t1Active;
|
bool t1Active;
|
||||||
bool t2Active;
|
bool t2Active;
|
||||||
|
|
||||||
|
@ -552,6 +552,7 @@ void b3Cloth::UpdateBodyContacts()
|
|||||||
c->fn = 0.0f;
|
c->fn = 0.0f;
|
||||||
c->ft1 = 0.0f;
|
c->ft1 = 0.0f;
|
||||||
c->ft2 = 0.0f;
|
c->ft2 = 0.0f;
|
||||||
|
c->nActive = true;
|
||||||
c->t1Active = false;
|
c->t1Active = false;
|
||||||
c->t2Active = false;
|
c->t2Active = false;
|
||||||
c->localPoint1.SetZero();
|
c->localPoint1.SetZero();
|
||||||
@ -560,48 +561,56 @@ void b3Cloth::UpdateBodyContacts()
|
|||||||
c->t2 = b3Cross(c->t1, normal);
|
c->t2 = b3Cross(c->t1, normal);
|
||||||
c->normalImpulse = 0.0f;
|
c->normalImpulse = 0.0f;
|
||||||
c->tangentImpulse.SetZero();
|
c->tangentImpulse.SetZero();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// Apply position correction
|
// Apply position correction
|
||||||
b3Vec3 dx = separation * normal;
|
p->m_translation += separation * normal;
|
||||||
p->m_translation += dx;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Update contact state
|
// Update contact state
|
||||||
if (c0.active == true)
|
if (c0.active == true)
|
||||||
{
|
{
|
||||||
c->fn0 = c0.fn0;
|
if (c0.nActive == true)
|
||||||
c->fn = c0.fn;
|
|
||||||
c->ft1 = c0.ft1;
|
|
||||||
c->ft2 = c0.ft2;
|
|
||||||
|
|
||||||
c->normalImpulse = c0.normalImpulse;
|
|
||||||
c->tangentImpulse = c0.tangentImpulse;
|
|
||||||
#if 0
|
|
||||||
const float32 kForceTol = 0.0f;
|
|
||||||
|
|
||||||
// Allow the contact to release when the constraint force
|
|
||||||
// switches from a repulsive force to an attractive one.
|
|
||||||
// if (c0.fn0 < kForceTol && c0.fn > kForceTol)
|
|
||||||
if (c0.fn > kForceTol)
|
|
||||||
{
|
{
|
||||||
// Contact force is attractive.
|
c->fn0 = c0.fn0;
|
||||||
c->active = false;
|
c->fn = c0.fn;
|
||||||
continue;
|
c->ft1 = c0.ft1;
|
||||||
}
|
c->ft2 = c0.ft2;
|
||||||
|
|
||||||
|
c->normalImpulse = c0.normalImpulse;
|
||||||
|
c->tangentImpulse = c0.tangentImpulse;
|
||||||
|
#if 1
|
||||||
|
const float32 kForceTol = 0.0f;
|
||||||
|
|
||||||
|
// Allow the contact to release when the constraint force
|
||||||
|
// switches from a repulsive force to an attractive one.
|
||||||
|
// if (c0.fn0 < kForceTol && c0.fn > kForceTol)
|
||||||
|
if (c0.fn > kForceTol)
|
||||||
|
{
|
||||||
|
// Contact force is attractive.
|
||||||
|
c->nActive = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
// A friction force requires an associated normal force.
|
|
||||||
if (c0.active == false)
|
if (c0.active == false)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A friction force requires an associated normal force.
|
||||||
|
if (c0.nActive == false)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
b3Vec3 v1; v1.SetZero();
|
b3Vec3 v1; v1.SetZero();
|
||||||
b3Vec3 v2 = p->m_velocity;
|
b3Vec3 v2 = p->m_velocity;
|
||||||
b3Vec3 dv = v2 - v1;
|
b3Vec3 dv = v2 - v1;
|
||||||
|
|
||||||
const float32 kVelTol = B3_EPSILON * B3_EPSILON;
|
const float32 kVelTol = 2.0f * B3_EPSILON;
|
||||||
|
|
||||||
// Lock particle on surface
|
// Lock particle on surface
|
||||||
float32 dvt1 = b3Dot(dv, c->t1);
|
float32 dvt1 = b3Dot(dv, c->t1);
|
||||||
|
@ -166,6 +166,11 @@ void b3ClothSolver::ApplyConstraints()
|
|||||||
for (u32 i = 0; i < m_bodyContactCount; ++i)
|
for (u32 i = 0; i < m_bodyContactCount; ++i)
|
||||||
{
|
{
|
||||||
b3BodyContact* bc = m_bodyContacts[i];
|
b3BodyContact* bc = m_bodyContacts[i];
|
||||||
|
|
||||||
|
if (bc->nActive == false)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
b3Particle* p1 = bc->p1;
|
b3Particle* p1 = bc->p1;
|
||||||
|
|
||||||
@ -357,6 +362,7 @@ void b3ClothSolver::Solve(float32 dt, const b3Vec3& gravity)
|
|||||||
// Integrate positions
|
// Integrate positions
|
||||||
sx = sx + h * sv;
|
sx = sx + h * sv;
|
||||||
|
|
||||||
|
#if 1
|
||||||
// Solve position constraints
|
// Solve position constraints
|
||||||
{
|
{
|
||||||
const u32 kPositionIterations = 2;
|
const u32 kPositionIterations = 2;
|
||||||
@ -374,7 +380,7 @@ void b3ClothSolver::Solve(float32 dt, const b3Vec3& gravity)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
// Synchronize bodies
|
// Synchronize bodies
|
||||||
for (u32 i = 0; i < m_bodyContactCount; ++i)
|
for (u32 i = 0; i < m_bodyContactCount; ++i)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user