]> git.tdb.fi Git - r2c2.git/blob - source/3d/vehicle.cpp
Add vehicles
[r2c2.git] / source / 3d / vehicle.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <cmath>
9 #include <msp/gl/matrix.h>
10 #include "layout.h"
11 #include "vehicle.h"
12 #include "vehicletype.h"
13
14 using namespace Msp;
15
16 namespace Marklin {
17
18 Vehicle3D::Vehicle3D(Layout3D &l, Vehicle &v):
19         layout(l),
20         vehicle(v),
21         type(layout.get_catalogue().get_vehicle(vehicle.get_type()))
22 {
23         layout.add_vehicle(*this);
24         layout.get_scene().add(*this);
25 }
26
27 Vehicle3D::~Vehicle3D()
28 {
29         layout.remove_vehicle(*this);
30         layout.get_scene().remove(*this);
31 }
32
33 Point Vehicle3D::get_node() const
34 {
35         Point p = vehicle.get_position();
36         return Point(p.x, p.y, p.z+0.01+vehicle.get_type().get_height());
37 }
38
39 void Vehicle3D::render(const GL::Tag &tag) const
40 {
41         if(tag==0)
42         {
43                 GL::PushMatrix push_mat;
44
45                 const Point &pos = vehicle.get_position();
46                 GL::translate(pos.x, pos.y, pos.z+0.01);
47                 GL::rotate(vehicle.get_direction()*180/M_PI, 0, 0, 1);
48
49                 type.get_body_mesh().draw();
50         }
51 }
52
53 } // namespace Marklin