-/* $Id$
-
-This file is part of the MSP Märklin suite
-Copyright © 2010 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
#include <msp/gl/matrix.h>
-#include "libmarklin/tracktype.h"
+#include <msp/gl/renderer.h>
+#include "libr2c2/tracktype.h"
#include "layout.h"
#include "path.h"
#include "track.h"
#include "tracktype.h"
+using namespace std;
using namespace Msp;
-namespace Marklin {
+namespace R2C2 {
Path3D::Path3D(const Track3D &t):
track(t),
paths(0),
- automatic(true)
+ automatic(true),
+ z_offs(0)
{
track.get_layout().get_path_scene().add(*this);
}
void Path3D::set_path(unsigned p)
{
if(!(track.get_track().get_type().get_paths()&(1<<p)))
- throw InvalidParameterValue("Invalid path");
+ throw invalid_argument("Path3D::set_path");
automatic = false;
paths = 1<<p;
}
void Path3D::set_mask(unsigned p)
{
if(p&~track.get_track().get_type().get_paths())
- throw InvalidParameterValue("Invalid path mask");
+ throw invalid_argument("Path3D::set_mask");
automatic = false;
paths = p;
}
color = c;
}
-void Path3D::render(const GL::Tag &tag) const
+void Path3D::set_layer(float l)
+{
+ z_offs = l*track.get_track().get_layout().get_catalogue().get_gauge()*0.01;
+}
+
+long Path3D::get_instance_key() const
+{
+ return reinterpret_cast<long>(&track.get_type());
+}
+
+void Path3D::render(GL::Renderer &renderer, const GL::Tag &tag) const
{
- if(tag==0)
+ if(tag=="unlit")
{
unsigned mask = (automatic ? 1<<track.get_track().get_active_path() : paths);
mask &= track.get_track().get_type().get_paths();
if(!mask)
return;
- GL::PushMatrix push_mat;
- track.apply_matrix();
+ GL::MatrixStack::Push push_mtx(renderer.matrix_stack());
+ GL::Matrix matrix = track.create_matrix();
+ matrix.translate(0, 0, z_offs);
+ renderer.matrix_stack() *= matrix;
glColor4f(color.r, color.g, color.b, color.a);
for(unsigned i=0; mask; ++i, mask>>=1)
if(mask&1)
- track.get_type().get_path_mesh(i).draw();
+ track.get_type().get_path_mesh(i).draw(renderer);
}
}
-} // namespace Marklin
+} // namespace R2C2