From 2917ed23b8f47200f597b6ba9c0eeeb4c6fa881b Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 7 Jun 2009 19:09:14 +0100 Subject: [PATCH] Transform function for points partially working --- src/Points.cpp | 30 +++++++++++++++++++++++++----- src/Train.cpp | 4 ++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/Points.cpp b/src/Points.cpp index b645f06..89c3b60 100644 --- a/src/Points.cpp +++ b/src/Points.cpp @@ -96,13 +96,33 @@ void Points::render() const double Points::segmentLength() const { - return 1.0; + return 2.0; } void Points::transform(const track::Direction& aDirection, double aDelta) const { + assert(aDelta < 2.0); + if (aDirection == -myAxis) + aDelta = 2.0 - aDelta; + + const double xTrans = + myAxis == axis::X || myAxis == -axis::X ? aDelta : 0.0; + const double yTrans = + myAxis == axis::Y || myAxis == -axis::Y ? aDelta : 0.0; + + glTranslatef(static_cast(myX) - xTrans, + 0.0, + static_cast(myY) - yTrans); + + //if (myAxis == axis::Y || myAxis == -axis::Y) + // glRotated(-90.0, 0.0, 1.0, 0.0); + + glTranslated(-0.5, 0.0, 0.0); + + if (aDirection == myAxis) + glRotated(-180.0, 0.0, 1.0, 0.0); } ITrackSegment::TransformFunc @@ -138,13 +158,13 @@ track::Connection Points::nextPosition(const track::Direction& aDirection) const ensureValidDirection(aDirection); if (aDirection == axis::X) - return make_pair(makePoint(myX + 1, myY), axis::X); + return make_pair(makePoint(myX + 3, myY), axis::X); else if (aDirection == -axis::X) - return make_pair(makePoint(myX - 1, myY), -axis::X); + return make_pair(makePoint(myX - 3, myY), -axis::X); else if (aDirection == axis::Y) - return make_pair(makePoint(myX, myY + 1), axis::Y); + return make_pair(makePoint(myX, myY + 3), axis::Y); else if (aDirection == -axis::Y) - return make_pair(makePoint(myX, myY - 1), -axis::Y); + return make_pair(makePoint(myX, myY - 3), -axis::Y); else assert(false); } diff --git a/src/Train.cpp b/src/Train.cpp index 3499790..2055978 100644 --- a/src/Train.cpp +++ b/src/Train.cpp @@ -205,8 +205,8 @@ void Train::enterSegment(Part& aPart, const track::Connection& aConnection) Point pos; tie(pos, aPart.direction) = aConnection; - //debug() << "Train part entered segment at " << pos - // << " moving " << aPart.direction; + debug() << "Train part entered segment at " << pos + << " moving " << aPart.direction; if (!myMap->isValidTrack(pos)) throw runtime_error("Train fell off end of track!"); -- 2.39.2