X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Fplacementghost.cpp;fp=source%2Fengineer%2Fplacementghost.cpp;h=e59da686670a469f63b85192ac3f6d8379487375;hb=77db8741430ca462e3b624dd42d5ead96be7f264;hp=0000000000000000000000000000000000000000;hpb=b8fe5be9bf33510499ec26b87a72a7cd65489ae9;p=r2c2.git diff --git a/source/engineer/placementghost.cpp b/source/engineer/placementghost.cpp new file mode 100644 index 0000000..e59da68 --- /dev/null +++ b/source/engineer/placementghost.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#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("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); +}