]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/track.cpp
Render tracks through GL::Objects
[r2c2.git] / source / 3d / track.cpp
index 49ef02e4ff06ae079968d5698c565b71e19f6f86..c8bf0e6309211c1308bd6a56bbba803934e37ac5 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$
 
-This file is part of the MSP Märklin suite
+This file is part of R²C²
 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
@@ -8,7 +8,7 @@ Distributed under the GPL
 #include <cmath>
 #include <msp/gl/matrix.h>
 #include <msp/gl/misc.h>
-#include "libmarklin/tracktype.h"
+#include "libr2c2/tracktype.h"
 #include "endpoint.h"
 #include "layout.h"
 #include "path.h"
@@ -18,9 +18,10 @@ Distributed under the GPL
 using namespace std;
 using namespace Msp;
 
-namespace Marklin {
+namespace R2C2 {
 
 Track3D::Track3D(Layout3D &l, Track &t):
+       GL::ObjectInstance(l.get_catalogue().get_track(t.get_type()).get_object()),
        layout(l),
        track(t),
        type(layout.get_catalogue().get_track(track.get_type())),
@@ -81,27 +82,30 @@ Point Track3D::get_node() const
        return Point(pos.x+c*center.x-s*center.y, pos.y+s*center.x+c*center.y, pos.z+0.02);
 }
 
-void Track3D::apply_matrix() const
+GL::Matrix Track3D::get_matrix() const
 {
        const Point &pos = track.get_position();
        float rot = track.get_rotation();
 
-       glTranslatef(pos.x, pos.y, pos.z);
-       glRotatef(rot*180/M_PI, 0, 0, 1);
-       glRotatef(track.get_slope()/track.get_type().get_total_length()*180/M_PI, 0, -1, 0);
+       GL::Matrix matrix;
+       matrix.translate(pos.x, pos.y, pos.z);
+       matrix.rotate(rot, 0, 0, 1);
+       matrix.rotate(track.get_slope()/track.get_type().get_total_length(), 0, -1, 0);
+
+       return matrix;
 }
 
-void Track3D::render(const GL::Tag &tag) const
+void Track3D::setup_render(const GL::Tag &) const
 {
-       GL::PushMatrix push_mat;
-
-       apply_matrix();
-
+       GL::MatrixStack::modelview().push();
+       GL::MatrixStack::modelview() *= get_matrix();
        glPushName(reinterpret_cast<unsigned>(this));
+}
 
-       type.render(tag);
-
+void Track3D::finish_render(const GL::Tag &) const
+{
        glPopName();
+       GL::MatrixStack::modelview().pop();
 }
 
-} // namespace Marklin
+} // namespace R2C2