]> git.tdb.fi Git - r2c2.git/commitdiff
Take z coordinate into account when computing points on tracks
authorMikko Rasa <tdb@tdb.fi>
Fri, 18 Dec 2009 06:34:30 +0000 (06:34 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 18 Dec 2009 06:34:30 +0000 (06:34 +0000)
source/engineer/engineer.cpp
source/libmarklin/track.cpp

index 11729be5b9a6f1754c0036704258f893cea6c4ff..777758700a4a857bf81df07c42d4a8cb7975ae50 100644 (file)
@@ -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);
index d2822f61efacbf92d1af2bccb9a531b533dadc37..6c72c469a7540972f540e029d68bece473963c09 100644 (file)
@@ -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<TrackPart> &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(d<plen)
                                        {
+                                               z += d*slope_norm;
                                                if(j==1)
                                                        d = plen-d;
                                                Point p = i->get_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;