]> git.tdb.fi Git - r2c2.git/blob - source/3d/rod.cpp
Rename Point to Vector
[r2c2.git] / source / 3d / rod.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 "rod.h"
11 #include "vehicle.h"
12 #include "vehicletype.h"
13
14 using namespace Msp;
15
16 namespace R2C2 {
17
18 Rod3D::Rod3D(const Vehicle3D &v, unsigned r):
19         GL::ObjectInstance(*v.get_type().get_rod_object(r)),
20         vehicle(v.get_vehicle()),
21         rod(vehicle.get_rod(r))
22 { }
23
24 void Rod3D::render(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 Rod3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const
33 {
34         GL::Matrix matrix;
35         const Vector &pos = vehicle.get_position();
36         matrix.translate(pos.x, pos.y, pos.z);
37         matrix.rotate(vehicle.get_direction(), 0, 0, 1);
38
39         matrix.translate(rod.position.x, rod.position.y, rod.position.z);
40         if(rod.type->mirror_object)
41                 matrix.scale(1, -1, 1);
42         matrix.rotate(rod.angle, 0, -1, 0);
43
44         renderer.matrix_stack() *= matrix;
45 }
46
47 } // namespace R2C2