]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/placementghost.cpp
Better visualization for placing a train
[r2c2.git] / source / engineer / placementghost.cpp
diff --git a/source/engineer/placementghost.cpp b/source/engineer/placementghost.cpp
new file mode 100644 (file)
index 0000000..e59da68
--- /dev/null
@@ -0,0 +1,59 @@
+#include <msp/gl/box.h>
+#include <msp/gl/meshbuilder.h>
+#include <msp/gl/renderer.h>
+#include <msp/gl/technique.h>
+#include "libr2c2/vehicletype.h"
+#include "placementghost.h"
+
+using namespace Msp;
+using namespace R2C2;
+
+PlacementGhost::PlacementGhost(Layout3D &a, const VehicleType &t):
+       layout(a),
+       type(t),
+       placement(type),
+       mesh(new GL::Mesh((GL::VERTEX3, GL::NORMAL3))),
+       object(new GL::Object(mesh, &layout.get_catalogue().get<GL::Technique>("ghost.technique")))
+{
+       GL::MeshBuilder bld(*mesh);
+       float l = type.get_length();
+       float w = type.get_width();
+       float h = type.get_height();
+       GL::BoxBuilder(GL::Vector3(-l/2, -w/2, 0), GL::Vector3(l, w, h)).build(bld);
+
+       layout.get_scene().add(*this);
+}
+
+PlacementGhost::~PlacementGhost()
+{
+       layout.get_scene().remove(*this);
+
+       delete object;
+       delete mesh;
+}
+
+void PlacementGhost::place(const TrackOffsetIter &track)
+{
+       placement.place(track, VehiclePlacement::BACK_BUFFER);
+}
+
+void PlacementGhost::place_before(const PlacementGhost &other)
+{
+       placement.place_before(other.placement);
+}
+
+void PlacementGhost::render(GL::Renderer &renderer, const GL::Tag &tag) const
+{
+       if(!object->get_technique()->has_pass(tag))
+               return;
+
+       GL::Renderer::Push push(renderer);
+
+       OrientedPoint point = placement.get_point();
+       GL::Matrix matrix;
+       matrix.translate(point.position);
+       matrix.rotate(point.rotation, 0, 0, 1);
+       renderer.matrix_stack() *= matrix;
+
+       object->render(renderer, tag);
+}