]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/track.cpp
Use different stopping margin depending on whether the next track is a turnout
[r2c2.git] / source / 3d / track.cpp
index c8bf0e6309211c1308bd6a56bbba803934e37ac5..5d31a4de93294f1c2ec46b815ad804aa09767c3b 100644 (file)
@@ -1,13 +1,14 @@
 /* $Id$
 
 This file is part of R²C²
-Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
 #include <cmath>
 #include <msp/gl/matrix.h>
 #include <msp/gl/misc.h>
+#include <msp/gl/renderer.h>
 #include "libr2c2/tracktype.h"
 #include "endpoint.h"
 #include "layout.h"
@@ -31,8 +32,16 @@ Track3D::Track3D(Layout3D &l, Track &t):
        layout.get_scene().add(*this);
 
        const vector<TrackType::Endpoint> &type_eps = track.get_type().get_endpoints();
+       const vector<Track *> &links = track.get_links();
        for(unsigned i=0; i<type_eps.size(); ++i)
-               endpoints.push_back(new Endpoint3D(*this, i));
+       {
+               if(!links[i] || links[i]>&track)
+                       endpoints.push_back(new Endpoint3D(*this, i));
+               else
+                       endpoints.push_back(0);
+       }
+
+       track.signal_link_changed.connect(sigc::mem_fun(this, &Track3D::link_changed));
 }
 
 Track3D::~Track3D()
@@ -95,17 +104,29 @@ GL::Matrix Track3D::get_matrix() const
        return matrix;
 }
 
-void Track3D::setup_render(const GL::Tag &) const
+void Track3D::setup_render(Msp::GL::Renderer &renderer, const GL::Tag &) const
 {
-       GL::MatrixStack::modelview().push();
-       GL::MatrixStack::modelview() *= get_matrix();
+       renderer.matrix_stack() *= get_matrix();
        glPushName(reinterpret_cast<unsigned>(this));
 }
 
-void Track3D::finish_render(const GL::Tag &) const
+void Track3D::finish_render(Msp::GL::Renderer &, const GL::Tag &) const
 {
        glPopName();
-       GL::MatrixStack::modelview().pop();
+}
+
+void Track3D::link_changed(unsigned i, Track *trk)
+{
+       if(!trk || trk>&track)
+       {
+               if(!endpoints[i])
+                       endpoints[i] = new Endpoint3D(*this, i);
+       }
+       else if(endpoints[i])
+       {
+               delete endpoints[i];
+               endpoints[i] = 0;
+       }
 }
 
 } // namespace R2C2