]> git.tdb.fi Git - r2c2.git/blob - source/3d/endpoint.cpp
e851007b2ba0736546f27b6d81ae5bac2518a1c5
[r2c2.git] / source / 3d / endpoint.cpp
1 #include <cmath>
2 #include <msp/gl/matrix.h>
3 #include <msp/gl/misc.h>
4 #include <msp/gl/renderer.h>
5 #include "endpoint.h"
6 #include "layout.h"
7 #include "track.h"
8
9 using namespace Msp;
10
11 namespace R2C2 {
12
13 Endpoint3D::Endpoint3D(const Track3D &t, unsigned i):
14         track(t),
15         index(i),
16         mesh(track.get_layout().get_catalogue().get_endpoint_mesh())
17 {
18         track.get_layout().get_endpoint_scene().add(*this);
19 }
20
21 Endpoint3D::~Endpoint3D()
22 {
23         track.get_layout().get_endpoint_scene().remove(*this);
24 }
25
26 void Endpoint3D::render(GL::Renderer &renderer, const GL::Tag &tag) const
27 {
28         if(tag=="unlit")
29         {
30                 Vector p = track.get_track().get_endpoint_position(index);
31                 float a = track.get_track().get_endpoint_direction(index)+M_PI;
32
33                 GL::MatrixStack::Push push_mtx(renderer.matrix_stack());
34                 GL::Matrix matrix;
35                 matrix.translate(p.x, p.y, p.z);
36                 matrix.rotate(a, 0, 0, 1);
37                 renderer.matrix_stack() *= matrix;
38
39                 if(track.get_track().get_link(index))
40                         glColor4f(0.5, 0, 1, 0.5);
41                 else
42                         glColor4f(1, 0, 0.5, 0.5);
43
44                 mesh.draw(renderer);
45         }
46 }
47
48 } // namespace R2C2