From e118b1f5d8071460e3a9d4d731c6d69221f785dc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 6 Mar 2021 19:44:58 +0000 Subject: Carve up the mess in game/vehicles --- game/vehicles/railVehicle.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 game/vehicles/railVehicle.cpp (limited to 'game/vehicles/railVehicle.cpp') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp new file mode 100644 index 0000000..a2373e7 --- /dev/null +++ b/game/vehicles/railVehicle.cpp @@ -0,0 +1,26 @@ +#include "railVehicle.h" +#include "railVehicleClass.h" +#include "train.h" +#include +#include +#include +#include +#include + +void +RailVehicle::render(const Shader & shader) const +{ + rvClass->render(shader, location, bogies); +} + +void +RailVehicle::move(const Train * t, float & trailBy) +{ + const auto overhang {(rvClass->length - rvClass->wheelBase) / 2}; + const auto & b1Pos = bogies[0] = t->getBogiePosition(t->linkDist, trailBy += overhang); + const auto & b2Pos = bogies[1] = t->getBogiePosition(t->linkDist, trailBy += rvClass->wheelBase); + const auto diff = glm::normalize(b2Pos.pos - b1Pos.pos); + location.pos = (b1Pos.pos + b2Pos.pos) / 2.F; + location.rot = {-vector_pitch(diff), vector_yaw(diff), 0}; + trailBy += 0.6F + overhang; +} -- cgit v1.2.3