]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/vehicle.cpp
Allow rotating the body object of a vehicle
[r2c2.git] / source / 3d / vehicle.cpp
index 78899fd371d07a25f3f8046c7411974daedcf179..0bd57e95da2b80d276fdf82cef0015649dc1d53d 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2010-2011  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #include <cmath>
 #include <msp/gl/matrix.h>
 #include <msp/gl/renderer.h>
@@ -26,9 +19,9 @@ Vehicle3D::Vehicle3D(Layout3D &l, Vehicle &v):
        vehicle(v),
        type(layout.get_catalogue().get_vehicle(vehicle.get_type()))
 {
-       unsigned n_axles = vehicle.get_type().get_axles().size();
+       unsigned n_axles = vehicle.get_type().get_fixed_axles().size();
        for(unsigned i=0; i<n_axles; ++i)
-               if(type.get_axle_object(i))
+               if(type.get_fixed_axle_object(i))
                {
                        Axle3D *a = new Axle3D(*this, i);
                        axles.push_back(a);
@@ -78,10 +71,10 @@ Vehicle3D::~Vehicle3D()
                delete *i;
 }
 
-Point Vehicle3D::get_node() const
+Vector Vehicle3D::get_node() const
 {
-       Point p = vehicle.get_position();
-       return Point(p.x, p.y, p.z+0.01+vehicle.get_type().get_height());
+       Vector p = vehicle.get_position();
+       return Vector(p.x, p.y, p.z+0.01+vehicle.get_type().get_height());
 }
 
 bool Vehicle3D::is_visible() const
@@ -100,9 +93,12 @@ void Vehicle3D::render(GL::Renderer &renderer, const GL::Tag &tag) const
 void Vehicle3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const
 {
        GL::Matrix matrix;
-       const Point &pos = vehicle.get_position();
+       const Vector &pos = vehicle.get_position();
        matrix.translate(pos.x, pos.y, pos.z);
-       matrix.rotate(vehicle.get_direction(), 0, 0, 1);
+       float dir = vehicle.get_direction();
+       if(vehicle.get_type().get_rotate_object())
+               dir += M_PI;
+       matrix.rotate(dir, 0, 0, 1);
        renderer.matrix_stack() *= matrix;
 }