summaryrefslogtreecommitdiff
path: root/game/vehicles
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-11-26 13:51:33 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-11-26 14:14:13 +0000
commit7fba471728f2216d7e3b7900297fc3b3531e286c (patch)
tree5caef3b2efc23aefccb215ec9005cd8e7d2e91b8 /game/vehicles
parentFix todo for handling a terrain walk from outside the mesh (diff)
parentModel positions as integers (diff)
downloadilt-7fba471728f2216d7e3b7900297fc3b3531e286c.tar.bz2
ilt-7fba471728f2216d7e3b7900297fc3b3531e286c.tar.xz
ilt-7fba471728f2216d7e3b7900297fc3b3531e286c.zip
Merge branch 'ints' into terrain
Conflicts fix, compiles, some test failures remain. Trees not added, possibility of OM invalid handle assertion failures, normals broken due to integer overflow in Newell's method.
Diffstat (limited to 'game/vehicles')
-rw-r--r--game/vehicles/linkHistory.cpp2
-rw-r--r--game/vehicles/railVehicle.cpp54
-rw-r--r--game/vehicles/railVehicle.h8
-rw-r--r--game/vehicles/railVehicleClass.cpp8
-rw-r--r--game/vehicles/railVehicleClass.h2
-rw-r--r--game/vehicles/train.cpp2
-rw-r--r--game/vehicles/train.h2
-rw-r--r--game/vehicles/vehicle.h1
8 files changed, 48 insertions, 31 deletions
diff --git a/game/vehicles/linkHistory.cpp b/game/vehicles/linkHistory.cpp
index 2802109..e6bab36 100644
--- a/game/vehicles/linkHistory.cpp
+++ b/game/vehicles/linkHistory.cpp
@@ -8,7 +8,7 @@ LinkHistory::add(const Link::WPtr & l, unsigned char d)
links.insert(links.begin(), {l, d});
const auto lp = l.lock();
totalLen += lp->length;
- while (totalLen >= 1000.F && !links.empty()) {
+ while (totalLen >= 1000000.F && !links.empty()) {
totalLen -= links.back().first.lock()->length;
links.pop_back();
}
diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp
index 2d820b6..30b615c 100644
--- a/game/vehicles/railVehicle.cpp
+++ b/game/vehicles/railVehicle.cpp
@@ -12,10 +12,22 @@
#include <ray.h>
RailVehicle::RailVehicle(RailVehicleClassPtr rvc) :
- RailVehicleClass::Instance {rvc->instances.acquire()}, rvClass {std::move(rvc)}, location {&LV::body, *this},
+ RailVehicleClass::Instance {rvc->instances.acquire()}, rvClass {std::move(rvc)},
+ location {[this](const BufferedLocation * l) {
+ this->get()->body = l->getRotationTransform();
+ this->get()->bodyPos = l->position();
+ }},
bogies {{
- {&LV::front, *this, glm::vec3 {0, rvClass->wheelBase / 2.F, 0}},
- {&LV::back, *this, glm::vec3 {0, -rvClass->wheelBase / 2.F, 0}},
+ {[this](const BufferedLocation * l) {
+ this->get()->front = l->getRotationTransform();
+ this->get()->frontPos = l->position();
+ },
+ Position3D {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}},
}}
{
}
@@ -26,29 +38,29 @@ 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.position() - b1Pos.position());
- location.setLocation((b1Pos.position() + b2Pos.position()) / 2.F, {vector_pitch(diff), vector_yaw(diff), 0});
- trailBy += 0.6F + overhang;
+ const auto diff = glm::normalize(RelativePosition3D(b2Pos.position() - b1Pos.position()));
+ location.setLocation((b1Pos.position() + b2Pos.position()) / 2, {vector_pitch(diff), vector_yaw(diff), 0});
+ trailBy += 600.F + overhang;
}
bool
-RailVehicle::intersectRay(const Ray & ray, glm::vec2 * baryPos, float * distance) const
+RailVehicle::intersectRay(const Ray & ray, Position2D * baryPos, float * distance) const
{
- constexpr const auto X = 1.35F;
+ constexpr const auto X = 1350.F;
const auto Y = this->rvClass->length / 2.F;
- constexpr const auto Z = 3.9F;
- 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
- moveBy * glm::vec4 {-X, Y, Z, 1}, // LFT
- moveBy * glm::vec4 {X, Y, Z, 1}, // RFT
- moveBy * glm::vec4 {-X, -Y, 0, 1}, // LBB
- moveBy * glm::vec4 {X, -Y, 0, 1}, // RBB
- moveBy * glm::vec4 {-X, -Y, Z, 1}, // LBT
- moveBy * glm::vec4 {X, -Y, Z, 1}, // RBT
+ 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
}};
- static constexpr const std::array<glm::uvec3, 10> triangles {{
+ static constexpr const std::array<glm::vec<3, uint8_t>, 10> triangles {{
// Front
{0, 1, 2},
{1, 2, 3},
@@ -66,7 +78,7 @@ RailVehicle::intersectRay(const Ray & ray, glm::vec2 * baryPos, float * distance
{3, 6, 7},
}};
return std::any_of(
- triangles.begin(), triangles.end(), [&cornerVertices, &ray, &baryPos, &distance](const glm::uvec3 idx) {
+ 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);
});
diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h
index f34643e..20d1ea1 100644
--- a/game/vehicles/railVehicle.h
+++ b/game/vehicles/railVehicle.h
@@ -17,12 +17,12 @@ public:
void move(const Train *, float & trailBy);
- [[nodiscard]] bool intersectRay(const Ray &, glm::vec2 *, float *) const override;
+ [[nodiscard]] bool intersectRay(const Ray &, Position2D *, float *) const override;
RailVehicleClassPtr rvClass;
using LV = RailVehicleClass::LocationVertex;
- using BLocation = BufferedLocationT<glm::mat4 LV::*, RailVehicleClass::Instance &>;
- BLocation location;
- std::array<BLocation, 2> bogies;
+ BufferedLocationUpdater location;
+ std::array<BufferedLocationUpdater, 2> bogies;
};
+
using RailVehiclePtr = std::unique_ptr<RailVehicle>;
diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp
index 324148c..7a6a9fe 100644
--- a/game/vehicles/railVehicleClass.cpp
+++ b/game/vehicles/railVehicleClass.cpp
@@ -35,13 +35,15 @@ void
RailVehicleClass::postLoad()
{
texture = getTexture();
- bodyMesh->configureVAO(instanceVAO).addAttribs<LocationVertex, &LocationVertex::body>(instances.bufferName(), 1);
+ bodyMesh->configureVAO(instanceVAO)
+ .addAttribs<LocationVertex, &LocationVertex::body, &LocationVertex::bodyPos>(instances.bufferName(), 1);
bogies.front()
->configureVAO(instancesBogiesVAO.front())
- .addAttribs<LocationVertex, &LocationVertex::front>(instances.bufferName(), 1);
+ .addAttribs<LocationVertex, &LocationVertex::front, &LocationVertex::frontPos>(instances.bufferName(), 1);
bogies.back()
->configureVAO(instancesBogiesVAO.back())
- .addAttribs<LocationVertex, &LocationVertex::back>(instances.bufferName(), 1);
+ .addAttribs<LocationVertex, &LocationVertex::back, &LocationVertex::backPos>(instances.bufferName(), 1);
+ static_assert(sizeof(LocationVertex) == 228UL);
}
void
diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h
index 80b3fda..913feea 100644
--- a/game/vehicles/railVehicleClass.h
+++ b/game/vehicles/railVehicleClass.h
@@ -20,6 +20,7 @@ public:
struct LocationVertex {
glm::mat4 body, front, back;
+ GlobalPosition3D bodyPos, frontPos, backPos;
};
std::array<Mesh::Ptr, 2> bogies;
@@ -41,4 +42,5 @@ private:
glVertexArray instanceVAO;
std::array<glVertexArray, 2> instancesBogiesVAO;
};
+
using RailVehicleClassPtr = std::shared_ptr<RailVehicleClass>;
diff --git a/game/vehicles/train.cpp b/game/vehicles/train.cpp
index 6f3b036..4aa24dc 100644
--- a/game/vehicles/train.cpp
+++ b/game/vehicles/train.cpp
@@ -20,7 +20,7 @@ Train::getBogiePosition(float linkDist, float dist) const
}
bool
-Train::intersectRay(const Ray & ray, glm::vec2 * baryPos, float * distance) const
+Train::intersectRay(const Ray & ray, Position2D * baryPos, float * distance) const
{
return applyOne(&RailVehicle::intersectRay, ray, baryPos, distance) != end();
}
diff --git a/game/vehicles/train.h b/game/vehicles/train.h
index 20c3bc4..7f0bb99 100644
--- a/game/vehicles/train.h
+++ b/game/vehicles/train.h
@@ -27,7 +27,7 @@ public:
return objects.front()->location;
}
- [[nodiscard]] bool intersectRay(const Ray &, glm::vec2 *, float *) const override;
+ [[nodiscard]] bool intersectRay(const Ray &, Position2D *, float *) const override;
void tick(TickDuration elapsed) override;
void doActivity(Go *, TickDuration) override;
diff --git a/game/vehicles/vehicle.h b/game/vehicles/vehicle.h
index 763ade9..354f904 100644
--- a/game/vehicles/vehicle.h
+++ b/game/vehicles/vehicle.h
@@ -27,4 +27,5 @@ protected:
void move(TickDuration dur);
LinkHistory linkHist;
};
+
using VehicleWPtr = std::weak_ptr<Vehicle>;