From a448b6ac73e0eb19980e69b095136eabe95d2534 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 18 Dec 2009 06:34:30 +0000 Subject: [PATCH] Take z coordinate into account when computing points on tracks --- source/engineer/engineer.cpp | 2 +- source/libmarklin/track.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 11729be..7777587 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -268,7 +268,7 @@ void Engineer::tick() GL::PushMatrix _push; const Point &tp = (*i)->get_position(); - GL::translate(tp.x, tp.y, 0.02); + GL::translate(tp.x, tp.y, tp.z+0.02); GL::Immediate imm((GL::COLOR4_UBYTE, GL::VERTEX2)); imm.color(0.8f, 0.8f, 1.0f); imm.begin(GL::TRIANGLE_FAN); diff --git a/source/libmarklin/track.cpp b/source/libmarklin/track.cpp index d2822f6..6c72c46 100644 --- a/source/libmarklin/track.cpp +++ b/source/libmarklin/track.cpp @@ -257,6 +257,17 @@ Point Track::get_point(unsigned epi, unsigned path, float d) const float x = eps[epi].pos.x; float y = eps[epi].pos.y; + float z = 0; + float slope_norm = 0; + if(eps.size()==2) + { + slope_norm = slope/type.get_total_length(); + if(epi==1) + { + z = slope; + slope_norm = -slope_norm; + } + } const vector &parts = type.get_parts(); const TrackPart *last_part = 0; @@ -282,18 +293,20 @@ Point Track::get_point(unsigned epi, unsigned path, float d) const plen *= abs(i->radius); if(dget_point(d); float c = cos(rot); float s = sin(rot); - return Point(pos.x+c*p.x-s*p.y, pos.y+c*p.y+s*p.x); + return Point(pos.x+c*p.x-s*p.y, pos.y+c*p.y+s*p.x, pos.z+z); } else if(part_eps.size()>1) { d -= plen; x = part_eps[1-j].pos.x; y = part_eps[1-j].pos.y; + z += plen*slope_norm; last_part = &*i; i = parts.begin(); break; -- 2.43.0