From e3b587143dfc4e8b97d8916ef1d4bcd1dd43734c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 6 Jan 2024 12:06:26 +0000 Subject: Simplified RailVehicle::intersectRay --- game/vehicles/railVehicle.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index 6653333..94f72e4 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -49,16 +49,16 @@ RailVehicle::intersectRay(const Ray & ray, BaryPosition & baryPos, RelativeDista 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 glm::mat3 moveBy = location.getRotationTransform(); const std::array 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 + location.position() + GlobalPosition3D(moveBy * glm::vec3 {-X, Y, 0}), // LFB + location.position() + GlobalPosition3D(moveBy * glm::vec3 {X, Y, 0}), // RFB + location.position() + GlobalPosition3D(moveBy * glm::vec3 {-X, Y, Z}), // LFT + location.position() + GlobalPosition3D(moveBy * glm::vec3 {X, Y, Z}), // RFT + location.position() + GlobalPosition3D(moveBy * glm::vec3 {-X, -Y, 0}), // LBB + location.position() + GlobalPosition3D(moveBy * glm::vec3 {X, -Y, 0}), // RBB + location.position() + GlobalPosition3D(moveBy * glm::vec3 {-X, -Y, Z}), // LBT + location.position() + GlobalPosition3D(moveBy * glm::vec3 {X, -Y, Z}), // RBT }}; static constexpr const std::array, 10> triangles {{ // Front -- cgit v1.2.3 From dcef947ea986f4ad4633189652abccebdd7aa3f6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 6 Jan 2024 13:03:42 +0000 Subject: Helper to create a cubiod from dimensions --- game/vehicles/railVehicle.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index 94f72e4..c720eb6 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -3,12 +3,12 @@ #include "train.h" #include #include +#include #include #include #include #include #include -#include #include RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : @@ -50,16 +50,10 @@ RailVehicle::intersectRay(const Ray & ray, BaryPosition & baryPos, RelativeDista const auto Y = this->rvClass->length / 2.F; constexpr const auto Z = 3900.F; const glm::mat3 moveBy = location.getRotationTransform(); - const std::array cornerVertices {{ - location.position() + GlobalPosition3D(moveBy * glm::vec3 {-X, Y, 0}), // LFB - location.position() + GlobalPosition3D(moveBy * glm::vec3 {X, Y, 0}), // RFB - location.position() + GlobalPosition3D(moveBy * glm::vec3 {-X, Y, Z}), // LFT - location.position() + GlobalPosition3D(moveBy * glm::vec3 {X, Y, Z}), // RFT - location.position() + GlobalPosition3D(moveBy * glm::vec3 {-X, -Y, 0}), // LBB - location.position() + GlobalPosition3D(moveBy * glm::vec3 {X, -Y, 0}), // RBB - location.position() + GlobalPosition3D(moveBy * glm::vec3 {-X, -Y, Z}), // LBT - location.position() + GlobalPosition3D(moveBy * glm::vec3 {X, -Y, Z}), // RBT - }}; + const auto cornerVertices + = cuboidCorners(-X, X, -Y, Y, 0.F, Z) * [&moveBy, this](const auto & corner) -> Position3D { + return location.position() + GlobalPosition3D(moveBy * corner); + }; static constexpr const std::array, 10> triangles {{ // Front {0, 1, 2}, -- cgit v1.2.3 From 6a1df3dfbae98a05e74c646cc216fbc19ffdb6d6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 7 Jan 2024 13:04:31 +0000 Subject: Template Ray on position type --- game/vehicles/railVehicle.cpp | 6 +++--- game/vehicles/railVehicle.h | 4 ++-- game/vehicles/train.cpp | 4 ++-- game/vehicles/train.h | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index c720eb6..985e9f2 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -44,7 +44,7 @@ RailVehicle::move(const Train * t, float & trailBy) } bool -RailVehicle::intersectRay(const Ray & ray, BaryPosition & baryPos, RelativeDistance & distance) const +RailVehicle::intersectRay(const Ray & ray, BaryPosition & baryPos, RelativeDistance & distance) const { constexpr const auto X = 1350.F; const auto Y = this->rvClass->length / 2.F; @@ -73,7 +73,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 #include -class Ray; +template 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 &, 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 #include -class Ray; +template 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 & 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 class Ray; class Train : public Vehicle, public Collection, public Can, public Can { public: @@ -25,7 +25,7 @@ public: return objects.front()->location; } - [[nodiscard]] bool intersectRay(const Ray &, BaryPosition &, RelativeDistance &) const override; + [[nodiscard]] bool intersectRay(const Ray &, BaryPosition &, RelativeDistance &) const override; void tick(TickDuration elapsed) override; void doActivity(Go *, TickDuration) override; -- cgit v1.2.3 From 25c7bec4acd63ebe01b3d1d21fa01ddf382df829 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 7 Jan 2024 13:18:56 +0000 Subject: Remove Position3D from RailVehicle --- game/vehicles/railVehicle.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index 985e9f2..4a1fdab 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -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}}, }} { } @@ -50,8 +50,7 @@ RailVehicle::intersectRay(const Ray & ray, BaryPosition & bary const auto Y = this->rvClass->length / 2.F; constexpr const auto Z = 3900.F; const glm::mat3 moveBy = location.getRotationTransform(); - const auto cornerVertices - = cuboidCorners(-X, X, -Y, Y, 0.F, Z) * [&moveBy, this](const auto & corner) -> Position3D { + 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, 10> triangles {{ -- cgit v1.2.3