]> git.tdb.fi Git - r2c2.git/blob - source/engineer/placementghost.cpp
Clear destination when setting a null route
[r2c2.git] / source / engineer / placementghost.cpp
1 #include <msp/gl/box.h>
2 #include <msp/gl/meshbuilder.h>
3 #include <msp/gl/renderer.h>
4 #include <msp/gl/technique.h>
5 #include "libr2c2/vehicletype.h"
6 #include "placementghost.h"
7
8 using namespace Msp;
9 using namespace R2C2;
10
11 PlacementGhost::PlacementGhost(Layout3D &a, const VehicleType &t):
12         layout(a),
13         type(t),
14         placement(type),
15         mesh(new GL::Mesh((GL::VERTEX3, GL::NORMAL3))),
16         object(new GL::Object(mesh, &layout.get_catalogue().get<GL::Technique>("ghost.technique")))
17 {
18         GL::MeshBuilder bld(*mesh);
19         float l = type.get_length();
20         float w = type.get_width();
21         float h = type.get_height();
22         GL::BoxBuilder(GL::Vector3(-l/2, -w/2, 0), GL::Vector3(l, w, h)).build(bld);
23
24         layout.get_scene().add(*this);
25 }
26
27 PlacementGhost::~PlacementGhost()
28 {
29         layout.get_scene().remove(*this);
30
31         delete object;
32         delete mesh;
33 }
34
35 void PlacementGhost::place(const TrackOffsetIter &track)
36 {
37         placement.place(track, VehiclePlacement::BACK_BUFFER);
38 }
39
40 void PlacementGhost::place_before(const PlacementGhost &other)
41 {
42         placement.place_before(other.placement);
43 }
44
45 void PlacementGhost::render(GL::Renderer &renderer, const GL::Tag &tag) const
46 {
47         if(!object->get_technique()->has_pass(tag))
48                 return;
49
50         GL::Renderer::Push push(renderer);
51
52         OrientedPoint point = placement.get_point();
53         GL::Matrix matrix;
54         matrix.translate(point.position);
55         matrix.rotate(point.rotation, 0, 0, 1);
56         renderer.matrix_stack() *= matrix;
57
58         object->render(renderer, tag);
59 }