From b9b35e546c33259f48e916e964f84062fbf51067 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 20 Mar 2010 17:39:36 +0000 Subject: [PATCH] Fix gradient calculations --- maps/uphill/uphill.bin | Bin 4364 -> 4364 bytes maps/uphill/uphill.xml | 2 +- src/Engine.cpp | 14 +++++++------- src/Train.cpp | 18 +++++++++++++++--- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/maps/uphill/uphill.bin b/maps/uphill/uphill.bin index 26e62a856d397d82752dc149e33f16012af5c3cf..8e53c717cb917803388c01fd6cce9e9b79b96fbd 100644 GIT binary patch delta 124 zcmeBC>QUOD!f4D@cfyvd&cm)FZkipCZPzpR7mzJx@0q7>4-~gQ-J59NGq=iq`L#}a apc?y(XNxA^X4IYB!l*)y-p#ie4fz4rBr-Vw delta 124 zcmeBC>QUOD!f3o__io!gyRGfcp6Rgzvh7x{dIe No Name - + uphill.bin diff --git a/src/Engine.cpp b/src/Engine.cpp index 2d64809..2706333 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -205,15 +205,15 @@ void Engine::update(int delta, float gradient) const double P = tractiveEffort(); const double Q = resistance(); const double B = isBrakeOn ? brakeForce() : 0.0; - const double G = 0;//gravity(gradient); + const double G = gravity(gradient); -#if 0 - if (gradient * P > 0.001f) - debug() << "D"; - else if (gradient * P < -0.001f) - debug() << "U"; +#if 1 + if (gradient > 0.01f) + debug() << "U = " << gradient; + else if (gradient < -0.01f) + debug() << "D =" << gradient; else - debug() << "F"; + debug() << "F =" << gradient; #endif // The applied tractive effort is controlled by the throttle diff --git a/src/Train.cpp b/src/Train.cpp index e0a6e31..314b000 100644 --- a/src/Train.cpp +++ b/src/Train.cpp @@ -283,9 +283,21 @@ void Train::update(int delta) int oldSpeedSign = engine().vehicle->speed() >= 0.0 ? 1 : 0; for (list::iterator it = parts.begin(); - it != parts.end(); ++it) - (*it).vehicle->update(delta, - (*it).travelToken.gradient((*it).segmentDelta)); + it != parts.end(); ++it) { + float gradient = (*it).travelToken.gradient((*it).segmentDelta); + + + debug() << "dir=" << (*it).direction << " ms=" << (*it).movementSign + << " g=" << gradient; + + if ((*it).direction.x < 0 || (*it).direction.z < 0) + gradient *= -1.0f; + + gradient *= (*it).movementSign; + + + (*it).vehicle->update(delta, gradient); + } int newSpeedSign = engine().vehicle->speed() >= 0.0 ? 1 : 0; -- 2.39.2