summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-06 13:03:42 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-06 13:03:42 +0000
commitdcef947ea986f4ad4633189652abccebdd7aa3f6 (patch)
tree7d07de0389f3e7bf8653838bd5709fc9a0c66e58
parentSimplified RailVehicle::intersectRay (diff)
downloadilt-dcef947ea986f4ad4633189652abccebdd7aa3f6.tar.bz2
ilt-dcef947ea986f4ad4633189652abccebdd7aa3f6.tar.xz
ilt-dcef947ea986f4ad4633189652abccebdd7aa3f6.zip
Helper to create a cubiod from dimensions
-rw-r--r--game/vehicles/railVehicle.cpp16
-rw-r--r--lib/basicShapes.h19
2 files changed, 24 insertions, 11 deletions
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 <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) :
@@ -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<Position3D, 8> 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<glm::vec<3, uint8_t>, 10> triangles {{
// Front
{0, 1, 2},
diff --git a/lib/basicShapes.h b/lib/basicShapes.h
new file mode 100644
index 0000000..183863e
--- /dev/null
+++ b/lib/basicShapes.h
@@ -0,0 +1,19 @@
+#pragma once
+#include <array>
+#include <glm/vec3.hpp>
+
+template<typename T, glm::qualifier Q = glm::defaultp>
+constexpr std::array<glm::vec<3, T, Q>, 8>
+cuboidCorners(T lx, T ux, T ly, T uy, T lz, T uz)
+{
+ return {{
+ {lx, uy, lz}, // LFB
+ {ux, uy, lz}, // RFB
+ {lx, uy, uz}, // LFT
+ {ux, uy, uz}, // RFT
+ {lx, ly, lz}, // LBB
+ {ux, ly, lz}, // RBB
+ {lx, ly, uz}, // LBT
+ {ux, ly, uz}, // RBT
+ }};
+}