+/* $Id$
+
+This file is part of R²C²
+Copyright © 2011 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#include <msp/gl/matrix.h>
+#include <msp/gl/renderer.h>
+#include "axle.h"
+#include "vehicle.h"
+#include "vehicletype.h"
+
+using namespace Msp;
+
+namespace R2C2 {
+
+Axle3D::Axle3D(const Vehicle3D &v, unsigned a):
+ GL::ObjectInstance(*v.get_type().get_axle_object(a)),
+ vehicle(v.get_vehicle()),
+ bogie(0),
+ axle(vehicle.get_axle(a))
+{ }
+
+Axle3D::Axle3D(const Vehicle3D &v, unsigned b, unsigned a):
+ GL::ObjectInstance(*v.get_type().get_bogie_axle_object(b, a)),
+ vehicle(v.get_vehicle()),
+ bogie(&vehicle.get_bogie(b)),
+ axle(bogie->axles[a])
+{ }
+
+void Axle3D::render(GL::Renderer &renderer, const GL::Tag &tag) const
+{
+ if(!vehicle.get_track())
+ return;
+
+ ObjectInstance::render(renderer, tag);
+}
+
+void Axle3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const
+{
+ GL::Matrix matrix;
+
+ const Point &pos = vehicle.get_position();
+ matrix.translate(pos.x, pos.y, pos.z);
+ matrix.rotate(vehicle.get_direction(), 0, 0, 1);
+
+ if(bogie)
+ {
+ matrix.translate(bogie->type->position, 0, 0);
+ matrix.rotate(bogie->direction, 0, 0, 1);
+ }
+
+ matrix.translate(axle.type->position, 0, axle.type->wheel_dia/2);
+ matrix.rotate(axle.angle, 0, 1, 0);
+
+ renderer.matrix_stack() *= matrix;
+}
+
+} // namespace R2C2