]> git.tdb.fi Git - r2c2.git/blob - source/3d/axle.cpp
Make use of the mspmath library
[r2c2.git] / source / 3d / axle.cpp
1 #include <msp/gl/matrix.h>
2 #include <msp/gl/renderer.h>
3 #include "axle.h"
4 #include "vehicle.h"
5 #include "vehicletype.h"
6
7 using namespace Msp;
8
9 namespace R2C2 {
10
11 Axle3D::Axle3D(const Vehicle3D &v, unsigned a):
12         GL::ObjectInstance(*v.get_type().get_fixed_axle_object(a)),
13         vehicle(v.get_vehicle()),
14         bogie(0),
15         axle(vehicle.get_fixed_axle(a))
16 { }
17
18 Axle3D::Axle3D(const Vehicle3D &v, unsigned b, unsigned a):
19         GL::ObjectInstance(*v.get_type().get_bogie_axle_object(b, a)),
20         vehicle(v.get_vehicle()),
21         bogie(&vehicle.get_bogie(b)),
22         axle(bogie->axles[a])
23 { }
24
25 void Axle3D::render(GL::Renderer &renderer, const GL::Tag &tag) const
26 {
27         if(!vehicle.get_track())
28                 return;
29
30         ObjectInstance::render(renderer, tag);
31 }
32
33 void Axle3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const
34 {
35         GL::Matrix matrix;
36
37         matrix.translate(vehicle.get_position());
38         matrix.rotate(vehicle.get_rotation(), 0, 0, 1);
39
40         if(bogie)
41         {
42                 matrix.translate(bogie->type->position, 0, 0);
43                 matrix.rotate(bogie->direction, 0, 0, 1);
44         }
45
46         matrix.translate(axle.type->position, 0, axle.type->wheel_dia/2);
47         matrix.rotate(axle.angle, 0, 1, 0);
48
49         renderer.matrix_stack() *= matrix;
50 }
51
52 } // namespace R2C2