]> git.tdb.fi Git - r2c2.git/blob - source/3d/endpoint.cpp
77a8af8af9cabdabf870accafa07d8ee657152bd
[r2c2.git] / source / 3d / endpoint.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <cmath>
9 #include <msp/gl/matrix.h>
10 #include <msp/gl/misc.h>
11 #include "endpoint.h"
12 #include "layout.h"
13 #include "track.h"
14
15 using namespace Msp;
16
17 namespace Marklin {
18
19 Endpoint3D::Endpoint3D(const Track3D &t, unsigned i):
20         track(t),
21         index(i),
22         mesh(track.get_layout().get_catalogue().get_endpoint_mesh())
23 {
24         track.get_layout().get_endpoint_scene().add(*this);
25 }
26
27 Endpoint3D::~Endpoint3D()
28 {
29         track.get_layout().get_endpoint_scene().remove(*this);
30 }
31
32 void Endpoint3D::render(const GL::Tag &tag) const
33 {
34         if(tag=="unlit")
35         {
36                 Point p = track.get_track().get_endpoint_position(index);
37                 float a = track.get_track().get_endpoint_direction(index)+M_PI;
38
39                 GL::PushMatrix push_mat;
40                 GL::translate(p.x, p.y, p.z);
41                 GL::rotate(a*180/M_PI, 0, 0, 1);
42
43                 GL::set(GL_CULL_FACE, track.get_track().get_link(index));
44                 if(track.get_track().get_link(index))
45                         glColor4f(0.5, 0, 1, 0.5);
46                 else
47                         glColor4f(1, 0, 0.5, 0.5);
48
49                 mesh.draw();
50         }
51 }
52
53 } // namespace Marklin