From 927b35a45d37c4e9b0277dbf107f1f0fa2e117f1 Mon Sep 17 00:00:00 2001 From: Irlan <-> Date: Tue, 24 Jul 2018 16:46:28 -0300 Subject: [PATCH] bugfix --- include/bounce/dynamics/body.h | 8 ++++++ src/bounce/dynamics/cloth/cloth.cpp | 40 +++++++++++++++-------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/include/bounce/dynamics/body.h b/include/bounce/dynamics/body.h index 2980f6a..7fe2d5a 100644 --- a/include/bounce/dynamics/body.h +++ b/include/bounce/dynamics/body.h @@ -152,6 +152,9 @@ public: // Get the local position of the center of mass. b3Vec3 GetLocalCenter() const; + + // Get the velocity at a given point. + b3Vec3 GetPointVelocity(const b3Vec3& point) const; // Get the linear velocity of the center of mass. b3Vec3 GetLinearVelocity() const; @@ -556,6 +559,11 @@ inline void b3Body::SetGravityScale(float32 scale) } } +inline b3Vec3 b3Body::GetPointVelocity(const b3Vec3& point) const +{ + return m_linearVelocity + b3Cross(m_angularVelocity, point - m_sweep.worldCenter); +} + inline b3Vec3 b3Body::GetLinearVelocity() const { return m_linearVelocity; diff --git a/src/bounce/dynamics/cloth/cloth.cpp b/src/bounce/dynamics/cloth/cloth.cpp index 904ebcb..81ba63f 100644 --- a/src/bounce/dynamics/cloth/cloth.cpp +++ b/src/bounce/dynamics/cloth/cloth.cpp @@ -594,18 +594,6 @@ void b3Cloth::UpdateContacts() } } -#if 0 - // Notify the new contact state - if (c0.n_active == false && c->n_active == true) - { - // The contact has begun - } - - if (c0.n_active == true && c->active_n == false) - { - // The contact has ended - } -#endif if (c->n_active == false) { continue; @@ -618,13 +606,16 @@ void b3Cloth::UpdateContacts() } b3Shape* s = c->s2; + b3Body* b = s->GetBody(); b3Vec3 n = c->n; float32 u = s->GetFriction(); float32 normalForce = c0.Fn; float32 maxFrictionForce = u * normalForce; - // Relative velocity - b3Vec3 dv = p->m_velocity; + // Relative velocity at contact point + b3Vec3 v1 = b->GetPointVelocity(c->p); + b3Vec3 v2 = p->m_velocity; + b3Vec3 dv = v2 - v1; b3Vec3 t1 = dv - b3Dot(dv, n) * n; if (b3Dot(t1, t1) > B3_EPSILON * B3_EPSILON) @@ -637,11 +628,6 @@ void b3Cloth::UpdateContacts() c->t1 = t1; c->t2 = t2; - - //c->f_active = true; - //c->f.m_type = e_frictionForce; - //c->f.m_p = p; - //c->f.m_kd = 10.0f; } b3Vec3 ts[2]; @@ -676,6 +662,22 @@ void b3Cloth::UpdateContacts() c->t1_active = t_active[0]; c->t2_active = t_active[1]; + + if (c0.t1_active == true) + { + if (c0.Ft1 > maxFrictionForce) + { + c->t1_active = false; + } + } + + if (c0.t2_active == true) + { + if (c0.Ft2 > maxFrictionForce) + { + c->t2_active = false; + } + } } }