]> git.tdb.fi Git - r2c2.git/blob - source/3d/bogie.cpp
Enable Renderer for Endpoint3D and Path3D
[r2c2.git] / source / 3d / bogie.cpp
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2011  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <msp/gl/matrix.h>
9 #include <msp/gl/renderer.h>
10 #include "bogie.h"
11 #include "vehicle.h"
12 #include "vehicletype.h"
13
14 using namespace Msp;
15
16 namespace R2C2 {
17
18 Bogie3D::Bogie3D(const Vehicle3D &v, unsigned b):
19         GL::ObjectInstance(*v.get_type().get_bogie_object(b)),
20         vehicle(v.get_vehicle()),
21         bogie(vehicle.get_bogie(b))
22 { }
23
24 void Bogie3D::render(Msp::GL::Renderer &renderer, const GL::Tag &tag) const
25 {
26         if(!vehicle.get_track())
27                 return;
28
29         ObjectInstance::render(renderer, tag);
30 }
31
32 void Bogie3D::setup_render(Msp::GL::Renderer &renderer, const GL::Tag &) const
33 {
34         GL::Matrix matrix;
35
36         const Point &pos = vehicle.get_position();
37         matrix.translate(pos.x, pos.y, pos.z);
38         matrix.rotate(vehicle.get_direction(), 0, 0, 1);
39
40         matrix.translate(bogie.type->position, 0, 0);
41         matrix.rotate(bogie.direction, 0, 0, 1);
42
43         renderer.matrix_stack() *= matrix;
44 }
45
46 } // namespace R2C2