summaryrefslogtreecommitdiff
path: root/game/vehicles/railVehicle.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-23 21:31:41 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-23 21:31:41 +0100
commit687afb09ada73fb4aee932242a3b7ee492e63cb0 (patch)
treee8c654edf5b0927238c89d8c861afe9bed995c8c /game/vehicles/railVehicle.cpp
parentAdd BufferedLocation (diff)
downloadilt-687afb09ada73fb4aee932242a3b7ee492e63cb0.tar.bz2
ilt-687afb09ada73fb4aee932242a3b7ee492e63cb0.tar.xz
ilt-687afb09ada73fb4aee932242a3b7ee492e63cb0.zip
Handle rendering of RailVehicles through RailVehicleClass instancing
Trains no longer need rendering as their parts are all RVC assets and that just works now. This commit creates some irritating duplication in RVC wrt body/2 bogies all of which are stored separately, but function in exactly the same way. This breaks RV shadows as we have no instancing shadow shaders yet.
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