summaryrefslogtreecommitdiff
path: root/game/vehicles/railVehicle.cpp
diff options
context:
space:
mode:
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;
+}