summaryrefslogtreecommitdiff
path: root/game/vehicles/railVehicle.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-27 17:55:30 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-27 17:55:30 +0100
commit4f34ed9c949785784f0006f971b5fd2bb9508553 (patch)
tree20f6627a2f441212365d05d04160a5a6a97063e7 /game/vehicles/railVehicle.cpp
parentMerge remote-tracking branch 'origin/assimp-normals' (diff)
parentRevert "Export mesh size and primitive type" (diff)
downloadilt-4f34ed9c949785784f0006f971b5fd2bb9508553.tar.bz2
ilt-4f34ed9c949785784f0006f971b5fd2bb9508553.tar.xz
ilt-4f34ed9c949785784f0006f971b5fd2bb9508553.zip
Merge branch 'instancing-pt2'
Diffstat (limited to 'game/vehicles/railVehicle.cpp')
-rw-r--r--game/vehicles/railVehicle.cpp29
1 files changed, 10 insertions, 19 deletions
diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp
index 77907be..b77b93c 100644
--- a/game/vehicles/railVehicle.cpp
+++ b/game/vehicles/railVehicle.cpp
@@ -11,22 +11,14 @@
#include <memory>
#include <ray.hpp>
-RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : rvClass {std::move(rvc)}
+RailVehicle::RailVehicle(RailVehicleClassPtr rvc) :
+ rvClass {std::move(rvc)}, location {rvClass->instancesBody}, bogies {
+ rvClass->instancesBogies.front(),
+ rvClass->instancesBogies.back(),
+ }
{
- bogies.front().pos.y = rvClass->wheelBase / 2.F;
- bogies.back().pos.y = -bogies.front().pos.y;
-}
-
-void
-RailVehicle::render(const SceneShader & shader) const
-{
- rvClass->render(shader, location, bogies);
-}
-
-void
-RailVehicle::shadows(const ShadowMapper & shadowMapper) const
-{
- rvClass->shadows(shadowMapper, location, bogies);
+ bogies.front().setPosition({0, rvClass->wheelBase / 2.F, 0});
+ bogies.back().setPosition({0, -bogies.front().position().y, 0});
}
void
@@ -35,9 +27,8 @@ 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};
+ const auto diff = glm::normalize(b2Pos.position() - b1Pos.position());
+ location.setLocation((b1Pos.position() + b2Pos.position()) / 2.F, {vector_pitch(diff), vector_yaw(diff), 0});
trailBy += 0.6F + overhang;
}
@@ -47,7 +38,7 @@ RailVehicle::intersectRay(const Ray & ray, glm::vec2 * baryPos, float * distance
constexpr const auto X = 1.35F;
const auto Y = this->rvClass->length / 2.F;
constexpr const auto Z = 3.9F;
- const auto moveBy = glm::translate(location.pos) * rotate_ypr(location.rot);
+ const auto moveBy = location.getTransform();
const std::array<glm::vec3, 8> cornerVertices {{
moveBy * glm::vec4 {-X, Y, 0, 1}, // LFB
moveBy * glm::vec4 {X, Y, 0, 1}, // RFB