From a993f204ba2cd282637814caec3ab115040fc0cc Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 26 Apr 2013 21:21:58 +0300 Subject: [PATCH] Allow rotating the body object of a vehicle This is a quick and dirty solution to support multiple units. A better solution is to allow rotating the vehicle instance, but that needs some additional coding to handle correctly. --- source/3d/vehicle.cpp | 5 ++++- source/libr2c2/vehicletype.cpp | 4 +++- source/libr2c2/vehicletype.h | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/3d/vehicle.cpp b/source/3d/vehicle.cpp index 4e5965b..0bd57e9 100644 --- a/source/3d/vehicle.cpp +++ b/source/3d/vehicle.cpp @@ -95,7 +95,10 @@ void Vehicle3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const 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); + 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; } diff --git a/source/libr2c2/vehicletype.cpp b/source/libr2c2/vehicletype.cpp index 720b922..2da44cc 100644 --- a/source/libr2c2/vehicletype.cpp +++ b/source/libr2c2/vehicletype.cpp @@ -13,7 +13,8 @@ VehicleType::VehicleType(const ArticleNumber &an): swap_direction(false), length(0), width(0), - height(0) + height(0), + rotate_object(false) { } unsigned VehicleType::get_max_function() const @@ -115,6 +116,7 @@ VehicleType::Loader::Loader(VehicleType &vt): add("name", &VehicleType::name); add("object", &VehicleType::object); add("rod", &Loader::rod); + add("rotate_object", &VehicleType::rotate_object); add("swap_direction", &VehicleType::swap_direction); add("width", &Loader::width); } diff --git a/source/libr2c2/vehicletype.h b/source/libr2c2/vehicletype.h index d9afdbc..d8bec87 100644 --- a/source/libr2c2/vehicletype.h +++ b/source/libr2c2/vehicletype.h @@ -137,6 +137,7 @@ private: BogieArray bogies; RodArray rods; std::string object; + bool rotate_object; public: VehicleType(const ArticleNumber &); @@ -160,6 +161,7 @@ public: float get_front_axle_offset() const; float get_back_axle_offset() const; const std::string &get_object() const { return object; } + bool get_rotate_object() const { return rotate_object; } }; } // namespace R2C2 -- 2.45.2