From 0348d55d21db474f6afc58774b7e7f5f49364f96 Mon Sep 17 00:00:00 2001 From: Irlan <-> Date: Wed, 30 May 2018 15:29:45 -0300 Subject: [PATCH] allow direct particle position alteration in order for mouse spring work --- examples/testbed/tests/cloth_test.h | 2 +- include/bounce/dynamics/cloth/particle.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/testbed/tests/cloth_test.h b/examples/testbed/tests/cloth_test.h index 885ed47..d514418 100644 --- a/examples/testbed/tests/cloth_test.h +++ b/examples/testbed/tests/cloth_test.h @@ -168,7 +168,7 @@ public: if (m_spring) { - m_particle->ApplyTranslation(dx); + m_particle->SetPosition(B); } else { diff --git a/include/bounce/dynamics/cloth/particle.h b/include/bounce/dynamics/cloth/particle.h index fce588e..f8a3f40 100644 --- a/include/bounce/dynamics/cloth/particle.h +++ b/include/bounce/dynamics/cloth/particle.h @@ -81,6 +81,11 @@ public: // Get the vertex index. u32 GetVertex() const; + // Set the particle position. + // If the particle is dynamic changing the position directly might lead + // to physically incorrect simulation behaviour. + void SetPosition(const b3Vec3& position); + // Get the particle position. const b3Vec3& GetPosition() const; @@ -175,6 +180,12 @@ inline u32 b3Particle::GetVertex() const return m_vertex; } +inline void b3Particle::SetPosition(const b3Vec3& position) +{ + m_position = position; + m_translation.SetZero(); +} + inline const b3Vec3& b3Particle::GetPosition() const { return m_position;