3 This file is part of R²C²
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gl/matrix.h>
9 #include <msp/gl/renderer.h>
10 #include "libr2c2/tracktype.h"
14 #include "tracktype.h"
20 Path3D::Path3D(const Track3D &t):
26 track.get_layout().get_path_scene().add(*this);
31 track.get_layout().get_path_scene().remove(*this);
34 void Path3D::set_automatic()
39 void Path3D::set_path(unsigned p)
41 if(!(track.get_track().get_type().get_paths()&(1<<p)))
42 throw InvalidParameterValue("Invalid path");
47 void Path3D::set_mask(unsigned p)
49 if(p&~track.get_track().get_type().get_paths())
50 throw InvalidParameterValue("Invalid path mask");
55 void Path3D::set_color(const GL::Color &c)
60 void Path3D::set_layer(float l)
62 z_offs = l*track.get_track().get_layout().get_catalogue().get_gauge()*0.01;
65 long Path3D::get_instance_key() const
67 return reinterpret_cast<long>(&track.get_type());
70 void Path3D::render(GL::Renderer &renderer, const GL::Tag &tag) const
74 unsigned mask = (automatic ? 1<<track.get_track().get_active_path() : paths);
75 mask &= track.get_track().get_type().get_paths();
79 GL::MatrixStack::Push push_mtx(renderer.matrix_stack());
80 GL::Matrix matrix = track.get_matrix();
81 matrix.translate(0, 0, z_offs);
82 renderer.matrix_stack() *= matrix;
84 glColor4f(color.r, color.g, color.b, color.a);
85 for(unsigned i=0; mask; ++i, mask>>=1)
87 track.get_type().get_path_mesh(i).draw(renderer);