]> git.tdb.fi Git - r2c2.git/blob - source/3d/endpoint.cpp
5b7f8104f808dee56d30304e747597c6bd121d68
[r2c2.git] / source / 3d / endpoint.cpp
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2010-2011  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 <msp/gl/renderer.h>
12 #include "endpoint.h"
13 #include "layout.h"
14 #include "track.h"
15
16 using namespace Msp;
17
18 namespace R2C2 {
19
20 Endpoint3D::Endpoint3D(const Track3D &t, unsigned i):
21         track(t),
22         index(i),
23         mesh(track.get_layout().get_catalogue().get_endpoint_mesh())
24 {
25         track.get_layout().get_endpoint_scene().add(*this);
26 }
27
28 Endpoint3D::~Endpoint3D()
29 {
30         track.get_layout().get_endpoint_scene().remove(*this);
31 }
32
33 void Endpoint3D::render(GL::Renderer &renderer, const GL::Tag &tag) const
34 {
35         if(tag=="unlit")
36         {
37                 Vector p = track.get_track().get_endpoint_position(index);
38                 float a = track.get_track().get_endpoint_direction(index)+M_PI;
39
40                 GL::MatrixStack::Push push_mtx(renderer.matrix_stack());
41                 GL::Matrix matrix;
42                 matrix.translate(p.x, p.y, p.z);
43                 matrix.rotate(a, 0, 0, 1);
44                 renderer.matrix_stack() *= matrix;
45
46                 if(track.get_track().get_link(index))
47                         glColor4f(0.5, 0, 1, 0.5);
48                 else
49                         glColor4f(1, 0, 0.5, 0.5);
50
51                 mesh.draw(renderer);
52         }
53 }
54
55 } // namespace R2C2