]> git.tdb.fi Git - r2c2.git/blob - source/3d/path.cpp
Reimplement path display
[r2c2.git] / source / 3d / path.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 <msp/gl/matrix.h>
9 #include "libmarklin/tracktype.h"
10 #include "layout.h"
11 #include "path.h"
12 #include "track.h"
13 #include "tracktype.h"
14
15 using namespace Msp;
16
17 namespace Marklin {
18
19 Path3D::Path3D(const Track3D &t):
20         track(t),
21         paths(0),
22         automatic(true)
23 {
24         track.get_layout().get_path_scene().add(*this);
25 }
26
27 Path3D::~Path3D()
28 {
29         track.get_layout().get_path_scene().remove(*this);
30 }
31
32 void Path3D::set_automatic()
33 {
34         automatic = true;
35 }
36
37 void Path3D::set_path(unsigned p)
38 {
39         if(!(track.get_track().get_type().get_paths()&(1<<p)))
40                 throw InvalidParameterValue("Invalid path");
41         automatic = false;
42         paths = 1<<p;
43 }
44
45 void Path3D::set_mask(unsigned p)
46 {
47         if(p&~track.get_track().get_type().get_paths())
48                 throw InvalidParameterValue("Invalid path mask");
49         automatic = false;
50         paths = p;
51 }
52
53 void Path3D::set_color(const GL::Color &c)
54 {
55         color = c;
56 }
57
58 void Path3D::render(const GL::Tag &tag) const
59 {
60         if(tag==0)
61         {
62                 unsigned mask = (automatic ? 1<<track.get_track().get_active_path() : paths);
63                 mask &= track.get_track().get_type().get_paths();
64                 if(!mask)
65                         return;
66
67                 GL::PushMatrix push_mat;
68                 track.apply_matrix();
69
70                 glColor4f(color.r, color.g, color.b, color.a);
71                 for(unsigned i=0; mask; ++i, mask>>=1)
72                         if(mask&1)
73                                 track.get_type().get_path_mesh(i).draw();
74         }
75 }
76
77 } // namespace Marklin