3 This file is part of the MSP Märklin suite
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
9 #include <msp/gl/matrix.h>
12 #include "vehicletype.h"
19 Vehicle3D::Vehicle3D(Layout3D &l, Vehicle &v):
22 type(layout.get_catalogue().get_vehicle(vehicle.get_type()))
24 layout.add_vehicle(*this);
25 layout.get_scene().add(*this);
28 Vehicle3D::~Vehicle3D()
30 layout.remove_vehicle(*this);
31 layout.get_scene().remove(*this);
34 Point Vehicle3D::get_node() const
36 Point p = vehicle.get_position();
37 return Point(p.x, p.y, p.z+0.01+vehicle.get_type().get_height());
40 bool Vehicle3D::is_visible() const
42 return vehicle.get_track();
45 void Vehicle3D::render(const GL::Tag &tag) const
47 if(!vehicle.get_track())
52 GL::PushMatrix push_mat;
54 const Point &pos = vehicle.get_position();
55 GL::translate(pos.x, pos.y, pos.z);
56 GL::rotate(vehicle.get_direction()*180/M_PI, 0, 0, 1);
58 if(const GL::Object *obj = type.get_body_object())
61 const vector<VehicleType::Axle> &axles = vehicle.get_type().get_axles();
62 for(unsigned i=0; i<axles.size(); ++i)
63 if(const GL::Object *obj = type.get_axle_object(i))
65 GL::PushMatrix push_mat2;
66 GL::translate(axles[i].position, 0, axles[i].wheel_dia/2);
70 const vector<VehicleType::Bogie> &bogies = vehicle.get_type().get_bogies();
71 for(unsigned i=0; i<bogies.size(); ++i)
73 GL::PushMatrix push_mat2;
74 GL::translate(bogies[i].position, 0, 0);
75 float angle = vehicle.get_bogie_direction(i)*180/M_PI;
76 GL::rotate(angle, 0, 0, 1);
78 for(unsigned j=0; j<bogies[i].axles.size(); ++j)
79 if(const GL::Object *obj = type.get_bogie_axle_object(i, j))
81 GL::PushMatrix push_mat3;
82 GL::translate(bogies[i].axles[j].position, 0, bogies[i].axles[j].wheel_dia/2);
86 if(bogies[i].rotate_object)
87 GL::rotate(180, 0, 0, 1);
88 if(const GL::Object *obj = type.get_bogie_object(i))
94 } // namespace Marklin