-/* $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"
namespace R2C2 {
Axle3D::Axle3D(const Vehicle3D &v, unsigned a):
- GL::ObjectInstance(*v.get_type().get_fixed_axle_object(a)),
- vehicle(v.get_vehicle()),
+ VehiclePart3D(v, *v.get_type().get_axle_object(a)),
bogie(0),
- axle(vehicle.get_fixed_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
+ axle(vehicle.get_vehicle().get_axle(a))
{
- if(!vehicle.get_track())
- return;
-
- ObjectInstance::render(renderer, tag);
+ if(axle.type->bogie)
+ bogie = &vehicle.get_vehicle().get_bogie(axle.type->bogie->index);
}
-void Axle3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const
+void Axle3D::update_matrix()
{
- GL::Matrix matrix;
-
- const Vector &pos = vehicle.get_position();
- matrix.translate(pos.x, pos.y, pos.z);
- matrix.rotate(vehicle.get_direction(), 0, 0, 1);
+ matrix = vehicle.Object3D::get_matrix();
if(bogie)
{
matrix.rotate(bogie->direction, 0, 0, 1);
}
- matrix.translate(axle.type->position, 0, axle.type->wheel_dia/2);
+ matrix.translate(axle.type->local_position, 0, axle.type->wheel_dia/2);
matrix.rotate(axle.angle, 0, 1, 0);
-
- renderer.matrix_stack() *= matrix;
}
} // namespace R2C2