summaryrefslogtreecommitdiff
path: root/game/vehicles/railVehicle.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-03-06 19:44:58 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-03-06 19:44:58 +0000
commite118b1f5d8071460e3a9d4d731c6d69221f785dc (patch)
tree64ea6b1761afba27d36319648e78ddd457670ff8 /game/vehicles/railVehicle.cpp
parentIntroduce the Train concept as a literal collection of rail vehicles (diff)
downloadilt-e118b1f5d8071460e3a9d4d731c6d69221f785dc.tar.bz2
ilt-e118b1f5d8071460e3a9d4d731c6d69221f785dc.tar.xz
ilt-e118b1f5d8071460e3a9d4d731c6d69221f785dc.zip
Carve up the mess in game/vehicles
Diffstat (limited to 'game/vehicles/railVehicle.cpp')
-rw-r--r--game/vehicles/railVehicle.cpp26
1 files changed, 26 insertions, 0 deletions
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 <array>
+#include <glm/glm.hpp>
+#include <location.hpp>
+#include <maths.h>
+#include <memory>
+
+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;
+}