summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
Diffstat (limited to 'game')
-rw-r--r--game/geoData.cpp14
-rw-r--r--game/geoData.h4
-rw-r--r--game/network/link.cpp9
-rw-r--r--game/network/link.h8
-rw-r--r--game/network/network.cpp7
-rw-r--r--game/network/network.h8
-rw-r--r--game/network/network.impl.h2
-rw-r--r--game/selectable.h5
-rw-r--r--game/vehicles/railVehicle.cpp27
-rw-r--r--game/vehicles/railVehicle.h4
-rw-r--r--game/vehicles/train.cpp4
-rw-r--r--game/vehicles/train.h4
12 files changed, 46 insertions, 50 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index 97f4a26..b30a35b 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -161,7 +161,7 @@ namespace {
positionOnTriangle(const GlobalPosition2D point, const GeoData::Triangle<3> & t)
{
const CalcPosition3D a = t[1] - t[0], b = t[2] - t[0];
- const auto n = crossInt(a, b);
+ const auto n = crossProduct(a, b);
return {point, ((n.x * t[0].x) + (n.y * t[0].y) + (n.z * t[0].z) - (n.x * point.x) - (n.y * point.y)) / n.z};
}
@@ -194,23 +194,23 @@ GeoData::positionAt(const PointFace & p) const
}
[[nodiscard]] std::optional<GlobalPosition3D>
-GeoData::intersectRay(const Ray & ray) const
+GeoData::intersectRay(const Ray<GlobalPosition3D> & ray) const
{
return intersectRay(ray, findPoint(ray.start));
}
[[nodiscard]] std::optional<GlobalPosition3D>
-GeoData::intersectRay(const Ray & ray, FaceHandle face) const
+GeoData::intersectRay(const Ray<GlobalPosition3D> & ray, FaceHandle face) const
{
std::optional<GlobalPosition3D> out;
walkUntil(PointFace {ray.start, face},
- ray.start.xy() + (ray.direction.xy() * RelativePosition2D(upperExtent.xy() - lowerExtent.xy())),
+ ray.start.xy()
+ + GlobalPosition2D(ray.direction.xy() * RelativePosition2D(upperExtent.xy() - lowerExtent.xy())),
[&out, &ray, this](FaceHandle face) {
BaryPosition bari {};
- float dist {};
+ RelativeDistance dist {};
const auto t = triangle<3>(face);
- if (glm::intersectRayTriangle<RelativePosition3D::value_type, glm::defaultp>(
- ray.start, ray.direction, t[0], t[1], t[2], bari, dist)) {
+ if (ray.intersectTriangle(t.x, t.y, t.z, bari, dist)) {
out = t * bari;
return true;
}
diff --git a/game/geoData.h b/game/geoData.h
index d4d0fb3..e234bfe 100644
--- a/game/geoData.h
+++ b/game/geoData.h
@@ -74,8 +74,8 @@ public:
[[nodiscard]] FaceHandle findPoint(GlobalPosition2D, FaceHandle start) const;
[[nodiscard]] GlobalPosition3D positionAt(const PointFace &) const;
- [[nodiscard]] std::optional<GlobalPosition3D> intersectRay(const Ray &) const;
- [[nodiscard]] std::optional<GlobalPosition3D> intersectRay(const Ray &, FaceHandle start) const;
+ [[nodiscard]] std::optional<GlobalPosition3D> intersectRay(const Ray<GlobalPosition3D> &) const;
+ [[nodiscard]] std::optional<GlobalPosition3D> intersectRay(const Ray<GlobalPosition3D> &, FaceHandle start) const;
void walk(const PointFace & from, const GlobalPosition2D to, const std::function<void(FaceHandle)> & op) const;
void walkUntil(const PointFace & from, const GlobalPosition2D to, const std::function<bool(FaceHandle)> & op) const;
diff --git a/game/network/link.cpp b/game/network/link.cpp
index 703a1ca..e8eaea2 100644
--- a/game/network/link.cpp
+++ b/game/network/link.cpp
@@ -33,9 +33,10 @@ LinkStraight::positionAt(float dist, unsigned char start) const
}
bool
-LinkStraight::intersectRay(const Ray & ray) const
+LinkStraight::intersectRay(const Ray<GlobalPosition3D> & ray) const
{
- return ray.passesCloseToEdges(std::array {ends.front().node->pos, ends.back().node->pos}, 1.F);
+ return ray.passesCloseToEdges(
+ std::array {GlobalPosition3D {ends.front().node->pos}, GlobalPosition3D {ends.back().node->pos}}, 1000);
}
Location
@@ -54,7 +55,7 @@ LinkCurve::positionAt(float dist, unsigned char start) const
}
bool
-LinkCurve::intersectRay(const Ray & ray) const
+LinkCurve::intersectRay(const Ray<GlobalPosition3D> & ray) const
{
const auto & e0p {ends[0].node->pos};
const auto & e1p {ends[1].node->pos};
@@ -64,7 +65,7 @@ LinkCurve::intersectRay(const Ray & ray) const
const auto trans {glm::translate(centreBase)};
auto segCount = static_cast<std::size_t>(std::lround(segs)) + 1;
- std::vector<Position3D> points;
+ std::vector<GlobalPosition3D> points;
points.reserve(segCount);
for (Position3D swing = {arc.first, centreBase.z - e0p.z, 0.F}; segCount; swing += step, --segCount) {
const auto t {trans * glm::rotate(half_pi - swing.x, up) * glm::translate(Position3D {radius, 0.F, swing.y})};
diff --git a/game/network/link.h b/game/network/link.h
index 78d3e91..95c141e 100644
--- a/game/network/link.h
+++ b/game/network/link.h
@@ -10,7 +10,7 @@
#include <utility>
#include <vector>
-class Ray;
+template<typename> class Ray;
// Generic network node
// something that can be travelled to
@@ -45,7 +45,7 @@ public:
NO_MOVE(Link);
[[nodiscard]] virtual Location positionAt(float dist, unsigned char start) const = 0;
- [[nodiscard]] virtual bool intersectRay(const Ray &) const = 0;
+ [[nodiscard]] virtual bool intersectRay(const Ray<GlobalPosition3D> &) const = 0;
std::array<End, 2> ends;
float length;
@@ -69,7 +69,7 @@ public:
NO_MOVE(LinkStraight);
[[nodiscard]] Location positionAt(float dist, unsigned char start) const override;
- [[nodiscard]] bool intersectRay(const Ray &) const override;
+ [[nodiscard]] bool intersectRay(const Ray<GlobalPosition3D> &) const override;
};
LinkStraight::~LinkStraight() = default;
@@ -82,7 +82,7 @@ public:
NO_MOVE(LinkCurve);
[[nodiscard]] Location positionAt(float dist, unsigned char start) const override;
- [[nodiscard]] bool intersectRay(const Ray &) const override;
+ [[nodiscard]] bool intersectRay(const Ray<GlobalPosition3D> &) const override;
Position3D centreBase;
float radius;
diff --git a/game/network/network.cpp b/game/network/network.cpp
index 1ff5b26..d52e804 100644
--- a/game/network/network.cpp
+++ b/game/network/network.cpp
@@ -49,13 +49,14 @@ Network::candidateNodeAt(Position3D pos) const
}
Node::Ptr
-Network::intersectRayNodes(const Ray & ray) const
+Network::intersectRayNodes(const Ray<GlobalPosition3D> & ray) const
{
// Click within 2m of a node
if (const auto node = std::find_if(nodes.begin(), nodes.end(),
[&ray](const Node::Ptr & node) {
- Position3D ipos, inorm;
- return glm::intersectRaySphere(ray.start, ray.direction, node->pos, 2.F, ipos, inorm);
+ GlobalPosition3D ipos;
+ Normal3D inorm;
+ return ray.intersectSphere(node->pos, 2000, ipos, inorm);
});
node != nodes.end()) {
return *node;
diff --git a/game/network/network.h b/game/network/network.h
index 8af06a9..9ce6e81 100644
--- a/game/network/network.h
+++ b/game/network/network.h
@@ -14,7 +14,7 @@
class Texture;
class SceneShader;
-class Ray;
+template<typename> class Ray;
template<size_t... n> using GenDef = std::tuple<glm::vec<n, Distance>...>;
using GenCurveDef = GenDef<3, 3, 2>;
@@ -32,8 +32,8 @@ public:
using NodeInsertion = std::pair<Node::Ptr, NodeIs>;
[[nodiscard]] NodeInsertion newNodeAt(Position3D);
[[nodiscard]] NodeInsertion candidateNodeAt(Position3D) const;
- [[nodiscard]] virtual Link::Ptr intersectRayLinks(const Ray &) const = 0;
- [[nodiscard]] virtual Node::Ptr intersectRayNodes(const Ray &) const;
+ [[nodiscard]] virtual Link::Ptr intersectRayLinks(const Ray<GlobalPosition3D> &) const = 0;
+ [[nodiscard]] virtual Node::Ptr intersectRayNodes(const Ray<GlobalPosition3D> &) const;
[[nodiscard]] Link::Nexts routeFromTo(const Link::End &, Position3D) const;
[[nodiscard]] Link::Nexts routeFromTo(const Link::End &, const Node::Ptr &) const;
@@ -66,7 +66,7 @@ protected:
void joinLinks(const Link::Ptr &) const;
protected:
- [[nodiscard]] Link::Ptr intersectRayLinks(const Ray &) const override;
+ [[nodiscard]] Link::Ptr intersectRayLinks(const Ray<GlobalPosition3D> &) const override;
public:
template<typename L, typename... Params>
diff --git a/game/network/network.impl.h b/game/network/network.impl.h
index 8e9e85c..4acbb6d 100644
--- a/game/network/network.impl.h
+++ b/game/network/network.impl.h
@@ -24,7 +24,7 @@ NetworkOf<T>::joinLinks(const Link::Ptr & l) const
template<typename T>
Link::Ptr
-NetworkOf<T>::intersectRayLinks(const Ray & ray) const
+NetworkOf<T>::intersectRayLinks(const Ray<GlobalPosition3D> & ray) const
{
// Click link
if (const auto link = std::find_if(links.objects.begin(), links.objects.end(),
diff --git a/game/selectable.h b/game/selectable.h
index c794461..fc6af4e 100644
--- a/game/selectable.h
+++ b/game/selectable.h
@@ -4,7 +4,7 @@
#include <glm/glm.hpp>
#include <special_members.h>
-class Ray;
+template<typename> class Ray;
class Selectable {
public:
@@ -12,5 +12,6 @@ public:
virtual ~Selectable() = default;
DEFAULT_MOVE_COPY(Selectable);
- [[nodiscard]] virtual bool intersectRay(const Ray &, BaryPosition &, RelativeDistance &) const = 0;
+ [[nodiscard]] virtual bool intersectRay(const Ray<GlobalPosition3D> &, BaryPosition &, RelativeDistance &) const
+ = 0;
};
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;