]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/endpoint.cpp
Don't crash if a train has no router
[r2c2.git] / source / 3d / endpoint.cpp
index 7e33ced696d92cc2abb3da7b54ddfbcaa0606ed6..aedd6894491cac216cee0741bd2cf0f45fb7be80 100644 (file)
@@ -1,13 +1,7 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2010 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 "endpoint.h"
 #include "layout.h"
 #include "track.h"
@@ -19,7 +13,7 @@ namespace R2C2 {
 Endpoint3D::Endpoint3D(const Track3D &t, unsigned i):
        track(t),
        index(i),
-       mesh(track.get_layout().get_catalogue().get_endpoint_mesh())
+       mesh(track.get_layout().get_catalogue().get_endpoint_mesh(track.get_track().get_type().get_appearance()))
 {
        track.get_layout().get_endpoint_scene().add(*this);
 }
@@ -29,24 +23,24 @@ Endpoint3D::~Endpoint3D()
        track.get_layout().get_endpoint_scene().remove(*this);
 }
 
-void Endpoint3D::render(const GL::Tag &tag) const
+void Endpoint3D::render(GL::Renderer &renderer, const GL::Tag &tag) const
 {
        if(tag=="unlit")
        {
-               Point p = track.get_track().get_endpoint_position(index);
-               float a = track.get_track().get_endpoint_direction(index)+M_PI;
+               Snap sn = track.get_track().get_snap_node(index);
 
-               GL::PushMatrix push_mat;
-               GL::translate(p.x, p.y, p.z);
-               GL::rotate(a*180/M_PI, 0, 0, 1);
+               GL::MatrixStack::Push push_mtx(renderer.matrix_stack());
+               GL::Matrix matrix;
+               matrix.translate(sn.position);
+               matrix.rotate(sn.rotation+Angle::half_turn(), 0, 0, 1);
+               renderer.matrix_stack() *= matrix;
 
-               GL::set(GL_CULL_FACE, track.get_track().get_link(index));
                if(track.get_track().get_link(index))
                        glColor4f(0.5, 0, 1, 0.5);
                else
                        glColor4f(1, 0, 0.5, 0.5);
 
-               mesh.draw();
+               mesh.draw(renderer);
        }
 }