summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-11-25 16:28:39 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-11-25 16:28:39 +0000
commit0aa665c3648d788755b00c9e431c872d57fddbb8 (patch)
tree859dba97d3026db485813d808e8180ac94a0ed2a
parentRemove getTransform (diff)
downloadilt-0aa665c3648d788755b00c9e431c872d57fddbb8.tar.bz2
ilt-0aa665c3648d788755b00c9e431c872d57fddbb8.tar.xz
ilt-0aa665c3648d788755b00c9e431c872d57fddbb8.zip
Model positions as integers
Introduces test failure in arcs due to rounding, but I don't want to create a complicated fix as link positions are still floats and hopefully that'll go away... somehow
-rw-r--r--config/types.h19
-rw-r--r--game/geoData.cpp4
-rw-r--r--game/scenary/foliage.h2
-rw-r--r--game/vehicles/railVehicle.cpp22
-rw-r--r--game/vehicles/railVehicleClass.h2
-rw-r--r--gfx/followCameraController.cpp4
-rw-r--r--gfx/gl/bufferedLocation.cpp8
-rw-r--r--gfx/gl/bufferedLocation.h8
-rw-r--r--gfx/gl/sceneShader.cpp2
-rw-r--r--gfx/gl/shaders/dynamicPoint.vs2
-rw-r--r--gfx/gl/shaders/dynamicPointInst.vs2
-rw-r--r--gfx/gl/shaders/fixedPoint.vs2
-rw-r--r--gfx/gl/shaders/shadowDynamicPoint.vs2
-rw-r--r--gfx/gl/shaders/shadowDynamicPointInst.vs2
-rw-r--r--gfx/gl/shaders/shadowFixedPoint.vs2
-rw-r--r--gfx/gl/shadowMapper.cpp2
-rw-r--r--lib/location.h4
-rw-r--r--test/test-maths.cpp12
18 files changed, 56 insertions, 45 deletions
diff --git a/config/types.h b/config/types.h
index d99735e..6fc7b61 100644
--- a/config/types.h
+++ b/config/types.h
@@ -3,10 +3,14 @@
#include "glad/gl.h"
#include <glm/geometric.hpp>
-using Distance = float;
+using Distance = float; // deprecate
+using RelativeDistance = float;
+using GlobalDistance = int32_t;
using Angle = float;
-template<glm::length_t D> using Position = glm::vec<D, Distance>;
+template<glm::length_t D> using Position = glm::vec<D, Distance>; // deprecate
+template<glm::length_t D> using RelativePosition = glm::vec<D, RelativeDistance>;
+template<glm::length_t D> using GlobalPosition = glm::vec<D, GlobalDistance>;
template<glm::length_t D> using Size = glm::vec<D, Distance>;
template<glm::length_t D> using Scale = glm::vec<D, float>;
template<glm::length_t D> using Direction = glm::vec<D, float>;
@@ -14,8 +18,15 @@ template<glm::length_t D> using Normal = Direction<D>;
template<glm::length_t D> using Rotation = glm::vec<D, Angle>;
template<glm::length_t Channels> using Colour = glm::vec<Channels, float>;
-using Position2D = Position<2>;
-using Position3D = Position<3>;
+using Position2D = Position<2>; // deprecate
+using Position3D = Position<3>; // deprecate
+using BaryPosition = glm::vec<2, float>;
+using RelativePosition2D = RelativePosition<2>;
+using RelativePosition3D = RelativePosition<3>;
+using RelativePosition4D = RelativePosition<4>;
+using GlobalPosition2D = GlobalPosition<2>;
+using GlobalPosition3D = GlobalPosition<3>;
+using GlobalPosition4D = GlobalPosition<4>;
using Size2D = Size<2>;
using Size3D = Size<3>;
using Scale2D = Scale<2>;
diff --git a/game/geoData.cpp b/game/geoData.cpp
index da067f7..ec990ea 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -73,7 +73,7 @@ GeoData::loadFromImages(const std::filesystem::path & fileName, float scale_)
}
GeoData::Quad
-GeoData::quad(glm::vec2 wcoord) const
+GeoData::quad(Position2D wcoord) const
{
constexpr static const std::array<glm::vec2, 4> corners {{{0, 0}, {0, 1}, {1, 0}, {1, 1}}};
return transform_array(transform_array(corners,
@@ -154,7 +154,7 @@ GeoData::intersectRay(const Ray & ray) const
try {
const auto point = quad(n);
for (auto offset : {0U, 1U}) {
- glm::vec2 bary;
+ BaryPosition bary;
float distance;
if (glm::intersectRayTriangle(ray.start, ray.direction, point[offset], point[offset + 1],
point[offset + 2], bary, distance)) {
diff --git a/game/scenary/foliage.h b/game/scenary/foliage.h
index 5a9d2de..bbb6200 100644
--- a/game/scenary/foliage.h
+++ b/game/scenary/foliage.h
@@ -15,7 +15,7 @@ class Foliage : public Asset, public Renderable, public StdTypeDefs<Foliage> {
glVertexArray instanceVAO;
public:
- using LocationVertex = std::pair<glm::mat4, Position3D>;
+ using LocationVertex = std::pair<glm::mat4, GlobalPosition3D>;
mutable InstanceVertices<LocationVertex> instances;
void render(const SceneShader &) const override;
void shadows(const ShadowMapper &) const override;
diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp
index bee0dd0..30b615c 100644
--- a/game/vehicles/railVehicle.cpp
+++ b/game/vehicles/railVehicle.cpp
@@ -38,9 +38,9 @@ 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
@@ -51,14 +51,14 @@ RailVehicle::intersectRay(const Ray & ray, Position2D * baryPos, float * distanc
constexpr const auto Z = 3900.F;
const auto moveBy = location.getRotationTransform();
const std::array<Position3D, 8> cornerVertices {{
- location.position() + (moveBy * glm::vec4 {-X, Y, 0, 1}).xyz(), // LFB
- location.position() + (moveBy * glm::vec4 {X, Y, 0, 1}).xyz(), // RFB
- location.position() + (moveBy * glm::vec4 {-X, Y, Z, 1}).xyz(), // LFT
- location.position() + (moveBy * glm::vec4 {X, Y, Z, 1}).xyz(), // RFT
- location.position() + (moveBy * glm::vec4 {-X, -Y, 0, 1}).xyz(), // LBB
- location.position() + (moveBy * glm::vec4 {X, -Y, 0, 1}).xyz(), // RBB
- location.position() + (moveBy * glm::vec4 {-X, -Y, Z, 1}).xyz(), // LBT
- location.position() + (moveBy * glm::vec4 {X, -Y, Z, 1}).xyz(), // RBT
+ 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::vec<3, uint8_t>, 10> triangles {{
// Front
diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h
index 16dce01..913feea 100644
--- a/game/vehicles/railVehicleClass.h
+++ b/game/vehicles/railVehicleClass.h
@@ -20,7 +20,7 @@ public:
struct LocationVertex {
glm::mat4 body, front, back;
- Position3D bodyPos, frontPos, backPos;
+ GlobalPosition3D bodyPos, frontPos, backPos;
};
std::array<Mesh::Ptr, 2> bogies;
diff --git a/gfx/followCameraController.cpp b/gfx/followCameraController.cpp
index 5b08483..aee2187 100644
--- a/gfx/followCameraController.cpp
+++ b/gfx/followCameraController.cpp
@@ -24,11 +24,11 @@ FollowCameraController::updateCamera(Camera * camera) const
break;
case Mode::Ride:
- camera->setView(pos + (up * 4.8F), !-sincosf(rot.y));
+ camera->setView(pos + GlobalPosition3D(up * 4.8F), !-sincosf(rot.y));
break;
case Mode::ISO:
- camera->setView(pos + ((up + north + east) * 40.F), glm::normalize(down + south + west),
+ camera->setView(pos + GlobalPosition3D((up + north + east) * 40.F), glm::normalize(down + south + west),
glm::normalize(up - north - east));
break;
}
diff --git a/gfx/gl/bufferedLocation.cpp b/gfx/gl/bufferedLocation.cpp
index 2a2e723..d6a63b9 100644
--- a/gfx/gl/bufferedLocation.cpp
+++ b/gfx/gl/bufferedLocation.cpp
@@ -2,7 +2,7 @@
#include "location.h"
#include <glm/gtx/transform.hpp>
-BufferedLocation::BufferedLocation(Position3D p, Rotation3D r) : BufferedLocation {Location {p, r}} { }
+BufferedLocation::BufferedLocation(GlobalPosition3D p, Rotation3D r) : BufferedLocation {Location {p, r}} { }
BufferedLocation::BufferedLocation(const Location & l) : loc {l} { }
@@ -19,7 +19,7 @@ BufferedLocation::operator=(const Location & l)
return *this;
}
-Position3D
+GlobalPosition3D
BufferedLocation::position() const
{
return loc.pos;
@@ -32,7 +32,7 @@ BufferedLocation::rotation() const
}
void
-BufferedLocation::setPosition(Position3D p, bool update)
+BufferedLocation::setPosition(GlobalPosition3D p, bool update)
{
loc.pos = p;
if (update) {
@@ -50,7 +50,7 @@ BufferedLocation::setRotation(Position3D r, bool update)
}
void
-BufferedLocation::setLocation(Position3D p, Rotation3D r)
+BufferedLocation::setLocation(GlobalPosition3D p, Rotation3D r)
{
loc.pos = p;
loc.rot = r;
diff --git a/gfx/gl/bufferedLocation.h b/gfx/gl/bufferedLocation.h
index 30967e3..87b957f 100644
--- a/gfx/gl/bufferedLocation.h
+++ b/gfx/gl/bufferedLocation.h
@@ -8,7 +8,7 @@
class BufferedLocation {
public:
- BufferedLocation(Position3D = {}, Rotation3D = {});
+ BufferedLocation(GlobalPosition3D = {}, Rotation3D = {});
BufferedLocation(const Location &);
virtual ~BufferedLocation() = default;
@@ -16,11 +16,11 @@ public:
operator const Location &() const;
- [[nodiscard]] Position3D position() const;
+ [[nodiscard]] GlobalPosition3D position() const;
[[nodiscard]] Rotation3D rotation() const;
- void setPosition(Position3D, bool update = true);
+ void setPosition(GlobalPosition3D, bool update = true);
void setRotation(Rotation3D, bool update = true);
- void setLocation(Position3D, Rotation3D);
+ void setLocation(GlobalPosition3D, Rotation3D);
[[nodiscard]] glm::mat4 getRotationTransform() const;
diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp
index de75814..59a9748 100644
--- a/gfx/gl/sceneShader.cpp
+++ b/gfx/gl/sceneShader.cpp
@@ -69,7 +69,7 @@ void
SceneShader::BasicProgram::setModel(Location const & location) const
{
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(rotate_ypr(location.rot)));
- glUniform3fv(modelPosLoc, 1, glm::value_ptr(location.pos));
+ glUniform3iv(modelPosLoc, 1, glm::value_ptr(location.pos));
}
void
diff --git a/gfx/gl/shaders/dynamicPoint.vs b/gfx/gl/shaders/dynamicPoint.vs
index 9dd6a47..667f247 100644
--- a/gfx/gl/shaders/dynamicPoint.vs
+++ b/gfx/gl/shaders/dynamicPoint.vs
@@ -7,6 +7,6 @@ include(`materialInterface.glsl')
uniform mat4 viewProjection;
uniform vec3 viewPoint;
uniform mat4 model;
-uniform vec3 modelPos;
+uniform ivec3 modelPos;
include(`commonPoint.glsl')
diff --git a/gfx/gl/shaders/dynamicPointInst.vs b/gfx/gl/shaders/dynamicPointInst.vs
index 4ae6813..adf39bd 100644
--- a/gfx/gl/shaders/dynamicPointInst.vs
+++ b/gfx/gl/shaders/dynamicPointInst.vs
@@ -7,6 +7,6 @@ include(`materialInterface.glsl')
uniform mat4 viewProjection;
uniform vec3 viewPoint;
layout(location = 5) in mat4 model;
-layout(location = 9) in vec3 modelPos;
+layout(location = 9) in ivec3 modelPos;
include(`commonPoint.glsl')
diff --git a/gfx/gl/shaders/fixedPoint.vs b/gfx/gl/shaders/fixedPoint.vs
index 0adbb02..6e1ab49 100644
--- a/gfx/gl/shaders/fixedPoint.vs
+++ b/gfx/gl/shaders/fixedPoint.vs
@@ -7,6 +7,6 @@ include(`materialInterface.glsl')
uniform mat4 viewProjection;
uniform vec3 viewPoint;
const mat4 model = mat4(1);
-const vec3 modelPos = vec3(0);
+const vec3 modelPos = ivec3(0);
include(`commonPoint.glsl')
diff --git a/gfx/gl/shaders/shadowDynamicPoint.vs b/gfx/gl/shaders/shadowDynamicPoint.vs
index eb25423..e20d31a 100644
--- a/gfx/gl/shaders/shadowDynamicPoint.vs
+++ b/gfx/gl/shaders/shadowDynamicPoint.vs
@@ -5,6 +5,6 @@ include(`meshIn.glsl')
uniform mat4 viewProjection;
uniform vec3 viewPoint;
uniform mat4 model;
-uniform vec3 modelPos;
+uniform ivec3 modelPos;
include(`commonShadowPoint.glsl')
diff --git a/gfx/gl/shaders/shadowDynamicPointInst.vs b/gfx/gl/shaders/shadowDynamicPointInst.vs
index a0f51c3..ab3e976 100644
--- a/gfx/gl/shaders/shadowDynamicPointInst.vs
+++ b/gfx/gl/shaders/shadowDynamicPointInst.vs
@@ -5,6 +5,6 @@ include(`meshIn.glsl')
uniform mat4 viewProjection;
uniform vec3 viewPoint;
layout(location = 5) in mat4 model;
-layout(location = 9) in vec3 modelPos;
+layout(location = 9) in ivec3 modelPos;
include(`commonShadowPoint.glsl')
diff --git a/gfx/gl/shaders/shadowFixedPoint.vs b/gfx/gl/shaders/shadowFixedPoint.vs
index dfc5c42..a9fb4a3 100644
--- a/gfx/gl/shaders/shadowFixedPoint.vs
+++ b/gfx/gl/shaders/shadowFixedPoint.vs
@@ -5,6 +5,6 @@ include(`meshIn.glsl')
uniform mat4 viewProjection;
uniform vec3 viewPoint;
const mat4 model = mat4(1);
-const vec3 modelPos = vec3(0);
+const ivec3 modelPos = ivec3(0);
include(`commonShadowPoint.glsl')
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index 4a8d7ec..07db6a1 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -202,5 +202,5 @@ void
ShadowMapper::DynamicPoint::setModel(const Location & location) const
{
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(rotate_ypr(location.rot)));
- glUniform3fv(modelPosLoc, 1, glm::value_ptr(location.pos));
+ glUniform3iv(modelPosLoc, 1, glm::value_ptr(location.pos));
}
diff --git a/lib/location.h b/lib/location.h
index 85834a0..8570fc2 100644
--- a/lib/location.h
+++ b/lib/location.h
@@ -6,11 +6,11 @@
class Location {
public:
#ifndef __cpp_aggregate_paren_init
- explicit Location(Position3D pos = {}, Rotation3D rot = {}) : pos {pos}, rot {rot} { }
+ explicit Location(GlobalPosition3D pos = {}, Rotation3D rot = {}) : pos {pos}, rot {rot} { }
#endif
[[nodiscard]] glm::mat4 getRotationTransform() const;
- Position3D pos;
+ GlobalPosition3D pos;
Rotation3D rot;
};
diff --git a/test/test-maths.cpp b/test/test-maths.cpp
index 2560319..9eae918 100644
--- a/test/test-maths.cpp
+++ b/test/test-maths.cpp
@@ -196,12 +196,12 @@ BOOST_DATA_TEST_CASE(straight1,
const TestLinkStraight l(v);
{
const auto p = l.positionAt(0, 0);
- BOOST_CHECK_EQUAL(p.pos, origin);
+ BOOST_CHECK_EQUAL(p.pos, GlobalPosition3D {origin});
BOOST_CHECK_EQUAL(p.rot, glm::vec3(0, angFor, 0));
}
{
const auto p = l.positionAt(0, 1);
- BOOST_CHECK_EQUAL(p.pos, v);
+ BOOST_CHECK_EQUAL(p.pos, GlobalPosition3D {v});
BOOST_CHECK_EQUAL(p.rot, glm::vec3(0, angBack, 0));
}
}
@@ -231,12 +231,12 @@ BOOST_DATA_TEST_CASE(curve1,
BOOST_CHECK_EQUAL(l.radius, 1.F);
{
const auto p = l.positionAt(0, 0);
- BOOST_CHECK_CLOSE_VEC(p.pos, origin);
+ BOOST_CHECK_CLOSE_VEC(RelativePosition3D {p.pos}, origin);
BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angFor, 0));
}
{
const auto p = l.positionAt(0, 1);
- BOOST_CHECK_CLOSE_VEC(p.pos, e1);
+ BOOST_CHECK_CLOSE_VEC(RelativePosition3D {p.pos}, e1);
BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angBack, 0));
}
}
@@ -247,13 +247,13 @@ BOOST_DATA_TEST_CASE(curve1,
{
const auto p = l.positionAt(0, 0);
const auto angForReversed = normalize(vector_yaw(origin - e1) * 2 - angFor);
- BOOST_CHECK_CLOSE_VEC(p.pos, e1);
+ BOOST_CHECK_CLOSE_VEC(RelativePosition3D {p.pos}, e1);
BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angForReversed, 0));
}
{
const auto p = l.positionAt(0, 1);
const auto angBackReversed = normalize(vector_yaw(e1 - origin) * 2 - angBack);
- BOOST_CHECK_CLOSE_VEC(p.pos, origin);
+ BOOST_CHECK_CLOSE_VEC(RelativePosition3D {p.pos}, origin);
BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angBackReversed, 0));
}
}