From 1c655aeda0aeb89e9d6c39938e9e8b5a1a6a35b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Wed, 6 May 2015 21:59:29 +0200 Subject: [PATCH] Corrected the problem with pendown() hanging the game (fixes #203) --- src/math/geometry.h | 6 +++++- src/physics/physics.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/math/geometry.h b/src/math/geometry.h index 595046e7..57557771 100644 --- a/src/math/geometry.h +++ b/src/math/geometry.h @@ -517,7 +517,11 @@ inline Math::Vector NormalToPlane(const Math::Vector &p1, const Math::Vector &p2 */ inline Math::Vector SegmentPoint(const Math::Vector &p1, const Math::Vector &p2, float dist) { - return p1 + (p2 - p1) * dist; + Math::Vector direction = p2 - p1; + + direction.Normalize(); + + return p1 + direction * dist; } //! Returns the distance between given point and a plane diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 5a6be899..26a87797 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -3818,9 +3818,12 @@ void CPhysics::WheelParticle(int color, float width) { dist1 = Math::Distance(m_wheelParticlePos[0], goal1); if ( dist1 < step ) break; + dist2 = Math::Distance(m_wheelParticlePos[1], goal2); + wheel1 = Math::SegmentPoint(m_wheelParticlePos[0], goal1, step); - wheel2 = Math::SegmentPoint(m_wheelParticlePos[1], goal2, step*dist2/dist1); + wheel2 = Math::SegmentPoint(m_wheelParticlePos[1], goal2, step * dist2 / dist1); + if ( m_linMotion.realSpeed.x >= 0.0f ) { m_particle->CreateWheelTrace(m_wheelParticlePos[0], m_wheelParticlePos[1], wheel1, wheel2, parti); @@ -3829,6 +3832,7 @@ void CPhysics::WheelParticle(int color, float width) { m_particle->CreateWheelTrace(m_wheelParticlePos[1], m_wheelParticlePos[0], wheel2, wheel1, parti); } + m_wheelParticlePos[0] = wheel1; m_wheelParticlePos[1] = wheel2; }