diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-07 13:23:27 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-07 13:23:27 +0000 |
commit | 108bf5b2424da06aa2e1735ffd10a2b713834db8 (patch) | |
tree | af0918a6a266aa7e6ee1d8129df6d5ef9fc4f8ab /game/vehicles | |
parent | Remove more use of legacy types and unnecessary pointers from selectable inte... (diff) | |
parent | Remove Position3D from RailVehicle (diff) | |
download | ilt-108bf5b2424da06aa2e1735ffd10a2b713834db8.tar.bz2 ilt-108bf5b2424da06aa2e1735ffd10a2b713834db8.tar.xz ilt-108bf5b2424da06aa2e1735ffd10a2b713834db8.zip |
Merge branch 'template-types'
Diffstat (limited to 'game/vehicles')
-rw-r--r-- | game/vehicles/railVehicle.cpp | 27 | ||||
-rw-r--r-- | game/vehicles/railVehicle.h | 4 | ||||
-rw-r--r-- | game/vehicles/train.cpp | 4 | ||||
-rw-r--r-- | game/vehicles/train.h | 4 |
4 files changed, 16 insertions, 23 deletions
diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index 6653333..4a1fdab 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -3,12 +3,12 @@ #include "train.h" #include <algorithm> #include <array> +#include <basicShapes.h> #include <glm/glm.hpp> #include <glm/gtx/intersect.hpp> #include <glm/gtx/transform.hpp> #include <location.h> #include <maths.h> -#include <memory> #include <ray.h> RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : @@ -22,12 +22,12 @@ RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : this->get()->front = l->getRotationTransform(); this->get()->frontPos = l->position(); }, - Position3D {0, rvClass->wheelBase / 2.F, 0}}, + GlobalPosition3D {0, rvClass->wheelBase / 2.F, 0}}, {[this](const BufferedLocation * l) { this->get()->back = l->getRotationTransform(); this->get()->backPos = l->position(); }, - Position3D {0, -rvClass->wheelBase / 2.F, 0}}, + GlobalPosition3D {0, -rvClass->wheelBase / 2.F, 0}}, }} { } @@ -44,22 +44,15 @@ RailVehicle::move(const Train * t, float & trailBy) } bool -RailVehicle::intersectRay(const Ray & ray, BaryPosition & baryPos, RelativeDistance & distance) const +RailVehicle::intersectRay(const Ray<GlobalPosition3D> & ray, BaryPosition & baryPos, RelativeDistance & distance) const { constexpr const auto X = 1350.F; const auto Y = this->rvClass->length / 2.F; constexpr const auto Z = 3900.F; - const auto moveBy = location.getRotationTransform(); - const std::array<Position3D, 8> cornerVertices {{ - location.position() + GlobalPosition3D(moveBy * glm::vec4 {-X, Y, 0, 1}).xyz(), // LFB - location.position() + GlobalPosition3D(moveBy * glm::vec4 {X, Y, 0, 1}).xyz(), // RFB - location.position() + GlobalPosition3D(moveBy * glm::vec4 {-X, Y, Z, 1}).xyz(), // LFT - location.position() + GlobalPosition3D(moveBy * glm::vec4 {X, Y, Z, 1}).xyz(), // RFT - location.position() + GlobalPosition3D(moveBy * glm::vec4 {-X, -Y, 0, 1}).xyz(), // LBB - location.position() + GlobalPosition3D(moveBy * glm::vec4 {X, -Y, 0, 1}).xyz(), // RBB - location.position() + GlobalPosition3D(moveBy * glm::vec4 {-X, -Y, Z, 1}).xyz(), // LBT - location.position() + GlobalPosition3D(moveBy * glm::vec4 {X, -Y, Z, 1}).xyz(), // RBT - }}; + const glm::mat3 moveBy = location.getRotationTransform(); + const auto cornerVertices = cuboidCorners(-X, X, -Y, Y, 0.F, Z) * [&moveBy, this](const auto & corner) { + return location.position() + GlobalPosition3D(moveBy * corner); + }; static constexpr const std::array<glm::vec<3, uint8_t>, 10> triangles {{ // Front {0, 1, 2}, @@ -79,7 +72,7 @@ RailVehicle::intersectRay(const Ray & ray, BaryPosition & baryPos, RelativeDista }}; return std::any_of( triangles.begin(), triangles.end(), [&cornerVertices, &ray, &baryPos, &distance](const auto & idx) { - return glm::intersectRayTriangle(ray.start, ray.direction, cornerVertices[idx[0]], - cornerVertices[idx[1]], cornerVertices[idx[2]], baryPos, distance); + return ray.intersectTriangle( + cornerVertices[idx[0]], cornerVertices[idx[1]], cornerVertices[idx[2]], baryPos, distance); }); } diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index f6e4764..bf1e782 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -7,7 +7,7 @@ #include <glm/glm.hpp> #include <memory> -class Ray; +template<typename> class Ray; class Train; class RailVehicle : Selectable, RailVehicleClass::Instance { @@ -16,7 +16,7 @@ public: void move(const Train *, float & trailBy); - [[nodiscard]] bool intersectRay(const Ray &, BaryPosition &, RelativeDistance &) const override; + [[nodiscard]] bool intersectRay(const Ray<GlobalPosition3D> &, BaryPosition &, RelativeDistance &) const override; RailVehicleClassPtr rvClass; using LV = RailVehicleClass::LocationVertex; diff --git a/game/vehicles/train.cpp b/game/vehicles/train.cpp index 05b2d8a..5bddd61 100644 --- a/game/vehicles/train.cpp +++ b/game/vehicles/train.cpp @@ -9,7 +9,7 @@ #include <optional> #include <utility> -class Ray; +template<typename> class Ray; Location Train::getBogiePosition(float linkDist, float dist) const @@ -20,7 +20,7 @@ Train::getBogiePosition(float linkDist, float dist) const } bool -Train::intersectRay(const Ray & ray, BaryPosition & baryPos, RelativeDistance & distance) const +Train::intersectRay(const Ray<GlobalPosition3D> & ray, BaryPosition & baryPos, RelativeDistance & distance) const { return applyOne(&RailVehicle::intersectRay, ray, baryPos, distance) != end(); } diff --git a/game/vehicles/train.h b/game/vehicles/train.h index bb668ed..4320103 100644 --- a/game/vehicles/train.h +++ b/game/vehicles/train.h @@ -13,7 +13,7 @@ class SceneShader; class ShadowMapper; -class Ray; +template<typename> class Ray; class Train : public Vehicle, public Collection<RailVehicle, false>, public Can<Go>, public Can<Idle> { public: @@ -25,7 +25,7 @@ public: return objects.front()->location; } - [[nodiscard]] bool intersectRay(const Ray &, BaryPosition &, RelativeDistance &) const override; + [[nodiscard]] bool intersectRay(const Ray<GlobalPosition3D> &, BaryPosition &, RelativeDistance &) const override; void tick(TickDuration elapsed) override; void doActivity(Go *, TickDuration) override; |