]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/path.cpp
Reimplement path display
[r2c2.git] / source / 3d / path.cpp
diff --git a/source/3d/path.cpp b/source/3d/path.cpp
new file mode 100644 (file)
index 0000000..1128b67
--- /dev/null
@@ -0,0 +1,77 @@
+/* $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 "layout.h"
+#include "path.h"
+#include "track.h"
+#include "tracktype.h"
+
+using namespace Msp;
+
+namespace Marklin {
+
+Path3D::Path3D(const Track3D &t):
+       track(t),
+       paths(0),
+       automatic(true)
+{
+       track.get_layout().get_path_scene().add(*this);
+}
+
+Path3D::~Path3D()
+{
+       track.get_layout().get_path_scene().remove(*this);
+}
+
+void Path3D::set_automatic()
+{
+       automatic = true;
+}
+
+void Path3D::set_path(unsigned p)
+{
+       if(!(track.get_track().get_type().get_paths()&(1<<p)))
+               throw InvalidParameterValue("Invalid 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");
+       automatic = false;
+       paths = p;
+}
+
+void Path3D::set_color(const GL::Color &c)
+{
+       color = c;
+}
+
+void Path3D::render(const GL::Tag &tag) const
+{
+       if(tag==0)
+       {
+               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();
+
+               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();
+       }
+}
+
+} // namespace Marklin