summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assetFactory/cuboid.cpp2
-rw-r--r--assetFactory/cylinder.cpp6
-rw-r--r--assetFactory/plane.cpp2
-rw-r--r--assetFactory/shape.cpp4
-rw-r--r--game/network/link.cpp14
-rw-r--r--game/network/network.cpp18
-rw-r--r--game/network/rail.cpp30
-rw-r--r--game/vehicles/railVehicle.cpp12
-rw-r--r--game/vehicles/train.cpp2
-rw-r--r--gfx/gl/bufferedLocation.cpp12
-rw-r--r--gfx/gl/camera.cpp11
-rw-r--r--gfx/gl/sceneRenderer.cpp7
-rw-r--r--gfx/gl/sceneShader.cpp14
-rw-r--r--gfx/gl/shadowMapper.cpp10
-rw-r--r--gfx/gl/uiShader.cpp2
-rw-r--r--gfx/models/texture.cpp6
-rw-r--r--lib/geometricPlane.cpp4
-rw-r--r--lib/maths.cpp40
-rw-r--r--lib/ray.cpp8
-rw-r--r--test/test-assetFactory.cpp2
-rw-r--r--test/testRenderOutput.cpp2
-rw-r--r--ui/builders/straight.cpp2
-rw-r--r--ui/gameMainSelector.cpp9
-rw-r--r--ui/gameMainWindow.cpp4
-rw-r--r--ui/manualCameraController.cpp2
25 files changed, 112 insertions, 113 deletions
diff --git a/assetFactory/cuboid.cpp b/assetFactory/cuboid.cpp
index a8ddcd9..cfb6cfb 100644
--- a/assetFactory/cuboid.cpp
+++ b/assetFactory/cuboid.cpp
@@ -4,7 +4,7 @@
Cuboid::CreatedFaces
Cuboid::createMesh(ModelFactoryMesh & mesh, float) const
{
- static constexpr std::array<glm::vec3, 8> VERTICES {{
+ static constexpr std::array<Position3D, 8> VERTICES {{
// bottom
{n, n, z},
{n, y, z},
diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp
index 7d22e36..ed034fd 100644
--- a/assetFactory/cylinder.cpp
+++ b/assetFactory/cylinder.cpp
@@ -9,8 +9,8 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, float lodf) const
const auto step = two_pi / static_cast<float>(P);
// Generate 2D circumference points
- std::vector<glm::vec2> circumference(P);
- std::generate(circumference.begin(), circumference.end(), [a = 0.f, step]() mutable {
+ std::vector<Position2D> circumference(P);
+ std::generate(circumference.begin(), circumference.end(), [a = 0.F, step]() mutable {
return sincosf(a += step) * .5F;
});
@@ -19,7 +19,7 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, float lodf) const
// Generate bottom face vertices
std::vector<OpenMesh::VertexHandle> bottom(P);
std::transform(circumference.begin(), circumference.end(), bottom.begin(), [&mesh](const auto & xy) {
- return mesh.add_vertex(xy ^ 0.f);
+ return mesh.add_vertex(xy ^ 0.F);
});
surface.insert(mesh.add_namedFace("bottom", bottom));
}
diff --git a/assetFactory/plane.cpp b/assetFactory/plane.cpp
index c6e1b5a..28fb690 100644
--- a/assetFactory/plane.cpp
+++ b/assetFactory/plane.cpp
@@ -4,7 +4,7 @@
Plane::CreatedFaces
Plane::createMesh(ModelFactoryMesh & mesh, float) const
{
- static constexpr std::array<glm::vec3, 4> VERTICES {{
+ static constexpr std::array<Position3D, 4> VERTICES {{
{n, n, z},
{y, n, z},
{y, y, z},
diff --git a/assetFactory/shape.cpp b/assetFactory/shape.cpp
index 1bfbdbb..0f83ee5 100644
--- a/assetFactory/shape.cpp
+++ b/assetFactory/shape.cpp
@@ -1,11 +1,9 @@
#include "shape.h"
-#include "gfx/models/vertex.h"
-#include "maths.h"
#include "modelFactoryMesh.h"
#include "shape.h"
std::vector<OpenMesh::VertexHandle>
-Shape::addToMesh(ModelFactoryMesh & mesh, const std::span<const glm::vec3> vertices)
+Shape::addToMesh(ModelFactoryMesh & mesh, const std::span<const Position3D> vertices)
{
std::vector<OpenMesh::VertexHandle> vhs;
std::transform(vertices.begin(), vertices.end(), std::back_inserter(vhs), [&mesh](const auto & p) {
diff --git a/game/network/link.cpp b/game/network/link.cpp
index bb27a52..498afe4 100644
--- a/game/network/link.cpp
+++ b/game/network/link.cpp
@@ -8,10 +8,10 @@
Link::Link(End a, End b, float l) : ends {{std::move(a), std::move(b)}}, length {l} { }
-LinkCurve::LinkCurve(glm::vec3 c, float r, Arc a) : centreBase {c}, radius {r}, arc {std::move(a)} { }
+LinkCurve::LinkCurve(Position3D c, float r, Arc a) : centreBase {c}, radius {r}, arc {std::move(a)} { }
bool
-operator<(const glm::vec3 & a, const glm::vec3 & b)
+operator<(const Position3D & a, const Position3D & b)
{
// NOLINTNEXTLINE(hicpp-use-nullptr,modernize-use-nullptr)
return std::tie(a.x, a.y, a.z) < std::tie(b.x, b.y, b.z);
@@ -48,7 +48,7 @@ LinkCurve::positionAt(float dist, unsigned char start) const
const auto ang {as.first + ((as.second - as.first) * frac)};
const auto relPos {!sincosf(ang) * radius};
const auto relClimb {vehiclePositionOffset()
- + glm::vec3 {0, 0, es.first->pos.z - centreBase.z + ((es.second->pos.z - es.first->pos.z) * frac)}};
+ + Position3D {0, 0, es.first->pos.z - centreBase.z + ((es.second->pos.z - es.first->pos.z) * frac)}};
const auto pitch {vector_pitch({0, 0, (es.second->pos.z - es.first->pos.z) / length})};
return Location {relPos + relClimb + centreBase, {pitch, normalize(ang + dirOffset[start]), 0}};
}
@@ -60,14 +60,14 @@ LinkCurve::intersectRay(const Ray & ray) const
const auto & e1p {ends[1].node->pos};
const auto slength = round_frac(length / 2.F, 5.F);
const auto segs = std::round(15.F * slength / std::pow(radius, 0.7F));
- const auto step {glm::vec3 {arc_length(arc), e1p.z - e0p.z, slength} / segs};
+ const auto step {Position3D {arc_length(arc), e1p.z - e0p.z, slength} / segs};
const auto trans {glm::translate(centreBase)};
auto segCount = static_cast<std::size_t>(std::lround(segs)) + 1;
- std::vector<glm::vec3> points;
+ std::vector<Position3D> points;
points.reserve(segCount);
- for (glm::vec3 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(glm::vec3 {radius, 0.F, swing.y})};
+ 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})};
points.emplace_back(t * glm::vec4 {0, 0, 0, 1});
}
return ray.passesCloseToEdges(points, 1.F);
diff --git a/game/network/network.cpp b/game/network/network.cpp
index 083b08e..d18345c 100644
--- a/game/network/network.cpp
+++ b/game/network/network.cpp
@@ -14,13 +14,13 @@
Network::Network(const std::string & tn) : texture {Texture::cachedTexture.get(tn)} { }
Node::Ptr
-Network::nodeAt(glm::vec3 pos)
+Network::nodeAt(Position3D pos)
{
return newNodeAt(pos).first;
}
Network::NodeInsertion
-Network::newNodeAt(glm::vec3 pos)
+Network::newNodeAt(Position3D pos)
{
if (auto [n, i] = candidateNodeAt(pos); i == NodeIs::NotInNetwork) {
return {*nodes.insert(std::move(n)).first, i};
@@ -31,7 +31,7 @@ Network::newNodeAt(glm::vec3 pos)
}
Node::Ptr
-Network::findNodeAt(glm::vec3 pos) const
+Network::findNodeAt(Position3D pos) const
{
if (const auto n = nodes.find(pos); n != nodes.end()) {
return *n;
@@ -40,7 +40,7 @@ Network::findNodeAt(glm::vec3 pos) const
}
Network::NodeInsertion
-Network::candidateNodeAt(glm::vec3 pos) const
+Network::candidateNodeAt(Position3D pos) const
{
if (const auto n = nodes.find(pos); n != nodes.end()) {
return {*n, NodeIs::InNetwork};
@@ -54,7 +54,7 @@ Network::intersectRayNodes(const Ray & ray) const
// Click within 2m of a node
if (const auto node = std::find_if(nodes.begin(), nodes.end(),
[&ray](const Node::Ptr & node) {
- glm::vec3 ipos, inorm;
+ Position3D ipos, inorm;
return glm::intersectRaySphere(ray.start, ray.direction, node->pos, 2.F, ipos, inorm);
});
node != nodes.end()) {
@@ -79,7 +79,7 @@ Network::joinLinks(const Link::Ptr & l, const Link::Ptr & ol)
}
Link::Nexts
-Network::routeFromTo(const Link::End & start, glm::vec3 dest) const
+Network::routeFromTo(const Link::End & start, Position3D dest) const
{
auto destNode {findNodeAt(dest)};
if (!destNode) {
@@ -95,7 +95,7 @@ Network::routeFromTo(const Link::End & end, const Node::Ptr & dest) const
}
GenCurveDef
-Network::genCurveDef(const glm::vec3 & start, const glm::vec3 & end, float startDir)
+Network::genCurveDef(const Position3D & start, const Position3D & end, float startDir)
{
const auto diff {end - start};
const auto vy {vector_yaw(diff)};
@@ -111,11 +111,11 @@ Network::genCurveDef(const glm::vec3 & start, const glm::vec3 & end, float start
}
std::pair<GenCurveDef, GenCurveDef>
-Network::genCurveDef(const glm::vec3 & start, const glm::vec3 & end, float startDir, float endDir)
+Network::genCurveDef(const Position3D & start, const Position3D & end, float startDir, float endDir)
{
startDir += pi;
endDir += pi;
- const glm::vec2 flatStart {!start}, flatEnd {!end};
+ const Position2D flatStart {!start}, flatEnd {!end};
auto midheight = [&](auto mid) {
const auto sm = glm::distance(flatStart, mid), em = glm::distance(flatEnd, mid);
return start.z + ((end.z - start.z) * (sm / (sm + em)));
diff --git a/game/network/rail.cpp b/game/network/rail.cpp
index 5a4f1e1..f46504b 100644
--- a/game/network/rail.cpp
+++ b/game/network/rail.cpp
@@ -18,7 +18,7 @@
template class NetworkOf<RailLink>;
constexpr auto RAIL_CROSSSECTION_VERTICES {5U};
-constexpr glm::vec3 RAIL_HEIGHT {0, 0, .25F};
+constexpr Size3D RAIL_HEIGHT {0, 0, .25F};
RailLinks::RailLinks() : NetworkOf<RailLink> {"rails.jpg"} { }
@@ -28,7 +28,7 @@ RailLinks::tick(TickDuration)
}
std::shared_ptr<RailLink>
-RailLinks::addLinksBetween(glm::vec3 start, glm::vec3 end)
+RailLinks::addLinksBetween(Position3D start, Position3D end)
{
auto node1ins = newNodeAt(start), node2ins = newNodeAt(end);
if (node1ins.second == NodeIs::NotInNetwork && node2ins.second == NodeIs::NotInNetwork) {
@@ -45,7 +45,7 @@ RailLinks::addLinksBetween(glm::vec3 start, glm::vec3 end)
if (dir == vector_yaw(end - start)) {
return addLink<RailLinkStraight>(start, end);
}
- const glm::vec2 flatStart {!start}, flatEnd {!end};
+ const Position2D flatStart {!start}, flatEnd {!end};
if (node2ins.second == NodeIs::InNetwork) {
auto midheight = [&](auto mid) {
const auto sm = glm::distance(flatStart, mid), em = glm::distance(flatEnd, mid);
@@ -100,7 +100,7 @@ RailLink::render(const SceneShader &) const
mesh->Draw();
}
-constexpr const std::array<std::pair<glm::vec3, float>, RAIL_CROSSSECTION_VERTICES> railCrossSection {{
+constexpr const std::array<std::pair<Position3D, float>, RAIL_CROSSSECTION_VERTICES> railCrossSection {{
// ___________
// _/ \_
// left to right
@@ -122,7 +122,7 @@ RailLinkStraight::RailLinkStraight(const Node::Ptr & a, const Node::Ptr & b) : R
{
}
-RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const glm::vec3 & diff) :
+RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const Position3D & diff) :
Link({std::move(a), vector_yaw(diff)}, {std::move(b), vector_yaw(-diff)}, glm::length(diff))
{
if (glGenVertexArrays) {
@@ -133,20 +133,20 @@ RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const glm::vec3 & d
for (auto ei : {1U, 0U}) {
const auto trans {glm::translate(ends[ei].node->pos) * e};
for (const auto & rcs : railCrossSection) {
- const glm::vec3 m {(trans * glm::vec4 {rcs.first, 1})};
- vertices.emplace_back(m, glm::vec2 {rcs.second, len * static_cast<float>(ei)}, up);
+ const Position3D m {(trans * glm::vec4 {rcs.first, 1})};
+ vertices.emplace_back(m, Position2D {rcs.second, len * static_cast<float>(ei)}, up);
}
}
mesh = defaultMesh(vertices);
}
}
-RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, glm::vec2 c) :
+RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, Position2D c) :
RailLinkCurve(a, b, c ^ a->pos.z, {!c, a->pos, b->pos})
{
}
-RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, glm::vec3 c, const Arc arc) :
+RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, Position3D c, const Arc arc) :
Link({a, normalize(arc.first + half_pi)}, {b, normalize(arc.second - half_pi)},
(glm::length(a->pos - c)) * arc_length(arc)),
LinkCurve {c, glm::length(ends[0].node->pos - c), arc}
@@ -156,25 +156,25 @@ RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, glm::vec3
const auto & e1p {ends[1].node->pos};
const auto slength = round_sleepers(length / 2.F);
const auto segs = std::round(15.F * slength / std::pow(radius, 0.7F));
- const auto step {glm::vec3 {arc_length(arc), e1p.z - e0p.z, slength} / segs};
+ const auto step {Position3D {arc_length(arc), e1p.z - e0p.z, slength} / segs};
const auto trans {glm::translate(centreBase)};
auto segCount = static_cast<std::size_t>(std::lround(segs)) + 1;
std::vector<Vertex> vertices;
vertices.reserve(segCount * railCrossSection.size());
- for (glm::vec3 swing = {arc.first, centreBase.z - e0p.z, 0.F}; segCount; swing += step, --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(glm::vec3 {radius, 0.F, swing.y})};
+ trans * glm::rotate(half_pi - swing.x, up) * glm::translate(Position3D {radius, 0.F, swing.y})};
for (const auto & rcs : railCrossSection) {
- const glm::vec3 m {(t * glm::vec4 {rcs.first, 1})};
- vertices.emplace_back(m, glm::vec2 {rcs.second, swing.z}, up);
+ const Position3D m {(t * glm::vec4 {rcs.first, 1})};
+ vertices.emplace_back(m, Position2D {rcs.second, swing.z}, up);
}
}
mesh = defaultMesh(vertices);
}
}
-glm::vec3
+Position3D
RailLink::vehiclePositionOffset() const
{
return RAIL_HEIGHT;
diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp
index 2d820b6..fc43995 100644
--- a/game/vehicles/railVehicle.cpp
+++ b/game/vehicles/railVehicle.cpp
@@ -14,8 +14,8 @@
RailVehicle::RailVehicle(RailVehicleClassPtr rvc) :
RailVehicleClass::Instance {rvc->instances.acquire()}, rvClass {std::move(rvc)}, location {&LV::body, *this},
bogies {{
- {&LV::front, *this, glm::vec3 {0, rvClass->wheelBase / 2.F, 0}},
- {&LV::back, *this, glm::vec3 {0, -rvClass->wheelBase / 2.F, 0}},
+ {&LV::front, *this, Position3D {0, rvClass->wheelBase / 2.F, 0}},
+ {&LV::back, *this, Position3D {0, -rvClass->wheelBase / 2.F, 0}},
}}
{
}
@@ -32,13 +32,13 @@ RailVehicle::move(const Train * t, float & trailBy)
}
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;
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 {{
+ const std::array<Position3D, 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
@@ -48,7 +48,7 @@ RailVehicle::intersectRay(const Ray & ray, glm::vec2 * baryPos, float * distance
moveBy * glm::vec4 {-X, -Y, Z, 1}, // LBT
moveBy * glm::vec4 {X, -Y, Z, 1}, // 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 +66,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/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/gfx/gl/bufferedLocation.cpp b/gfx/gl/bufferedLocation.cpp
index eb3dac3..62cadef 100644
--- a/gfx/gl/bufferedLocation.cpp
+++ b/gfx/gl/bufferedLocation.cpp
@@ -3,7 +3,7 @@
#include "maths.h"
#include <glm/gtx/transform.hpp>
-BufferedLocation::BufferedLocation(glm::vec3 p, glm::vec3 r) : BufferedLocation {Location {p, r}} { }
+BufferedLocation::BufferedLocation(Position3D p, Rotation3D r) : BufferedLocation {Location {p, r}} { }
BufferedLocation::BufferedLocation(const Location & l) : loc {l} { }
@@ -20,20 +20,20 @@ BufferedLocation::operator=(const Location & l)
return *this;
}
-glm::vec3
+Position3D
BufferedLocation::position() const
{
return loc.pos;
}
-glm::vec3
+Position3D
BufferedLocation::rotation() const
{
return loc.rot;
}
void
-BufferedLocation::setPosition(glm::vec3 p, bool update)
+BufferedLocation::setPosition(Position3D p, bool update)
{
loc.pos = p;
if (update) {
@@ -42,7 +42,7 @@ BufferedLocation::setPosition(glm::vec3 p, bool update)
}
void
-BufferedLocation::setRotation(glm::vec3 r, bool update)
+BufferedLocation::setRotation(Position3D r, bool update)
{
loc.rot = r;
if (update) {
@@ -51,7 +51,7 @@ BufferedLocation::setRotation(glm::vec3 r, bool update)
}
void
-BufferedLocation::setLocation(glm::vec3 p, glm::vec3 r)
+BufferedLocation::setLocation(Position3D p, Rotation3D r)
{
loc.pos = p;
loc.rot = r;
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index 80feab4..6a0359c 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -2,6 +2,7 @@
#include <collections.h>
#include <glm/gtx/intersect.hpp> // IWYU pragma: keep
#include <glm/gtx/transform.hpp> // IWYU pragma: keep
+#include <math.h>
#include <maths.h>
#include <ray.h>
@@ -28,8 +29,8 @@ Camera::updateView()
inverseViewProjection = glm::inverse(viewProjection);
}
-glm::vec3
-Camera::upFromForward(const glm::vec3 & forward)
+Direction3D
+Camera::upFromForward(const Direction3D & forward)
{
const auto right = glm::cross(forward, ::down);
return glm::cross(forward, right);
@@ -38,11 +39,11 @@ Camera::upFromForward(const glm::vec3 & forward)
std::array<glm::vec4, 4>
Camera::extentsAtDist(const float dist) const
{
- const auto clampToSeaFloor = [this, dist](const glm::vec3 & target) {
+ const auto clampToSeaFloor = [this, dist](const Position3D & target) {
if (target.z < -1.5F) {
const auto vec = glm::normalize(target - position);
- constexpr glm::vec3 seafloor {0, 0, -1.5F};
- float outdist;
+ constexpr Position3D seafloor {0, 0, -1.5F};
+ float outdist {};
if (glm::intersectRayPlane(position, vec, seafloor, ::up, outdist)) {
return (vec * outdist + position) ^ outdist;
}
diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp
index 218cf6d..6965175 100644
--- a/gfx/gl/sceneRenderer.cpp
+++ b/gfx/gl/sceneRenderer.cpp
@@ -97,7 +97,7 @@ SceneRenderer::render(const SceneProvider & scene) const
}
void
-SceneRenderer::setAmbientLight(const glm::vec3 & colour) const
+SceneRenderer::setAmbientLight(const RGB & colour) const
{
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
glClearColor(colour.r, colour.g, colour.b, 1.0F);
@@ -105,8 +105,7 @@ SceneRenderer::setAmbientLight(const glm::vec3 & colour) const
}
void
-SceneRenderer::setDirectionalLight(
- const glm::vec3 & colour, const glm::vec3 & direction, const SceneProvider & scene) const
+SceneRenderer::setDirectionalLight(const RGB & colour, const Direction3D & direction, const SceneProvider & scene) const
{
if (colour.r > 0 || colour.g > 0 || colour.b > 0) {
const auto lvp = shadowMapper.update(scene, direction, camera);
@@ -135,7 +134,7 @@ SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() :
}
void
-SceneRenderer::DirectionalLightProgram::setDirectionalLight(const glm::vec3 & c, const glm::vec3 & d,
+SceneRenderer::DirectionalLightProgram::setDirectionalLight(const RGB & c, const Direction3D & d,
const std::span<const glm::mat4x4> lvp, const std::span<const glm::vec4> shadowMapRegions,
std::size_t maps) const
{
diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp
index 1354611..04b6d9e 100644
--- a/gfx/gl/sceneShader.cpp
+++ b/gfx/gl/sceneShader.cpp
@@ -81,25 +81,25 @@ void
SceneShader::WaterProgram::use(float waveCycle) const
{
Program::use();
- glm::vec3 waves {waveCycle, 0.F, 0.F};
+ Position3D waves {waveCycle, 0.F, 0.F};
glUniform3fv(waveLoc, 1, glm::value_ptr(waves));
}
SceneShader::PointLightShader::PointLightShader() :
SceneProgram {pointLight_vs, pointLight_gs, pointLight_fs}, colourLoc {*this, "colour"}, kqLoc {*this, "kq"}
{
- VertexArrayObject {va}.addAttribs<glm::vec3>(b);
+ VertexArrayObject {va}.addAttribs<Position3D>(b);
}
void
-SceneShader::PointLightShader::add(const glm::vec3 & position, const glm::vec3 & colour, const float kq) const
+SceneShader::PointLightShader::add(const Position3D & position, const RGB & colour, const float kq) const
{
Program::use();
glBindVertexArray(va);
glBindBuffer(GL_ARRAY_BUFFER, b);
glUniform3fv(colourLoc, 1, glm::value_ptr(colour));
glUniform1f(kqLoc, kq);
- glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3), glm::value_ptr(position), GL_DYNAMIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(Position3D), glm::value_ptr(position), GL_DYNAMIC_DRAW);
glDrawArrays(GL_POINTS, 0, 1);
}
@@ -107,12 +107,12 @@ SceneShader::SpotLightShader::SpotLightShader() :
SceneProgram {spotLight_vs, spotLight_gs, spotLight_fs}, directionLoc {*this, "v_direction"},
colourLoc {*this, "colour"}, kqLoc {*this, "kq"}, arcLoc {*this, "arc"}
{
- using v3pair = std::pair<glm::vec3, glm::vec3>;
+ using v3pair = std::pair<Position3D, Direction3D>;
VertexArrayObject {va}.addAttribs<v3pair, &v3pair::first, &v3pair::second>(b);
}
void
-SceneShader::SpotLightShader::add(const glm::vec3 & position, const glm::vec3 & direction, const glm::vec3 & colour,
+SceneShader::SpotLightShader::add(const Position3D & position, const Direction3D & direction, const RGB & colour,
const float kq, const float arc) const
{
Program::use();
@@ -122,6 +122,6 @@ SceneShader::SpotLightShader::add(const glm::vec3 & position, const glm::vec3 &
glUniform3fv(directionLoc, 1, glm::value_ptr(direction));
glUniform1f(kqLoc, kq);
glUniform1f(arcLoc, arc);
- glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3), glm::value_ptr(position), GL_DYNAMIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(Position3D), glm::value_ptr(position), GL_DYNAMIC_DRAW);
glDrawArrays(GL_POINTS, 0, 1);
}
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index 58f65c4..aea5af3 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -104,14 +104,14 @@ struct DefinitionsInserter {
ShadowMapper::Definitions & out;
};
-std::vector<std::array<glm::vec3, 4>>
+std::vector<std::array<Position3D, 4>>
ShadowMapper::getBandViewExtents(const Camera & camera, const glm::mat4 & lightView)
{
- std::vector<std::array<glm::vec3, 4>> bandViewExtents;
+ std::vector<std::array<Position3D, 4>> bandViewExtents;
for (const auto dist : shadowBands) {
const auto extents = camera.extentsAtDist(dist);
- bandViewExtents.emplace_back(extents * [&lightView](const auto & e) -> glm::vec3 {
- return lightView * glm::vec4(glm::vec3 {e}, 1);
+ bandViewExtents.emplace_back(extents * [&lightView](const auto & e) -> Position3D {
+ return lightView * glm::vec4(Position3D {e}, 1);
});
if (std::none_of(extents.begin(), extents.end(), [targetDist = dist * 0.99F](const glm::vec4 & e) {
return e.w > targetDist;
@@ -123,7 +123,7 @@ ShadowMapper::getBandViewExtents(const Camera & camera, const glm::mat4 & lightV
}
ShadowMapper::Definitions
-ShadowMapper::update(const SceneProvider & scene, const glm::vec3 & dir, const Camera & camera) const
+ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const Camera & camera) const
{
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
glClear(GL_DEPTH_BUFFER_BIT);
diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp
index 0b47211..dc4f4dc 100644
--- a/gfx/gl/uiShader.cpp
+++ b/gfx/gl/uiShader.cpp
@@ -23,7 +23,7 @@ UIShader::UIShader(size_t width, size_t height) :
UIShader::UIShader(const glm::mat4 & viewProjection) : icon {viewProjection}, text {viewProjection} { }
void
-UIShader::TextProgram::use(const glm::vec3 & colour) const
+UIShader::TextProgram::use(const RGB & colour) const
{
Program::use();
glUniform3fv(colorLoc, 1, glm::value_ptr(colour));
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp
index f60d158..1685d34 100644
--- a/gfx/models/texture.cpp
+++ b/gfx/models/texture.cpp
@@ -61,10 +61,10 @@ Texture::bind(GLenum unit) const
glBindTexture(type, m_texture);
}
-glm::ivec2
+TextureAbsCoord
Texture::getSize(const glTexture & texture)
{
- glm::ivec2 size;
+ TextureAbsCoord size;
glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_WIDTH, &size.x);
glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_HEIGHT, &size.y);
return size;
@@ -137,7 +137,7 @@ TextureAtlas::bind(GLenum unit) const
}
GLuint
-TextureAtlas::add(glm::ivec2 position, glm::ivec2 size, void * data, TextureOptions to)
+TextureAtlas::add(TextureAbsCoord position, TextureAbsCoord size, void * data, TextureOptions to)
{
glTextureSubImage2D(m_texture, 0, position.x, position.y, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, data);
diff --git a/lib/geometricPlane.cpp b/lib/geometricPlane.cpp
index ea4f02d..567f98a 100644
--- a/lib/geometricPlane.cpp
+++ b/lib/geometricPlane.cpp
@@ -4,10 +4,10 @@
#include <glm/gtx/intersect.hpp>
GeometricPlane::PlaneRelation
-GeometricPlane::getRelation(glm::vec3 p) const
+GeometricPlane::getRelation(Position3D p) const
{
const auto d = glm::dot(normal, p - origin);
- return d < 0.f ? PlaneRelation::Below : d > 0.f ? PlaneRelation::Above : PlaneRelation::On;
+ return d < 0.F ? PlaneRelation::Below : d > 0.F ? PlaneRelation::Above : PlaneRelation::On;
}
bool
diff --git a/lib/maths.cpp b/lib/maths.cpp
index 7594b59..5430ef6 100644
--- a/lib/maths.cpp
+++ b/lib/maths.cpp
@@ -6,7 +6,7 @@
#include <stdexcept>
glm::mat4
-flat_orientation(const glm::vec3 & diff)
+flat_orientation(const Direction3D & diff)
{
static const auto oneeighty {glm::rotate(pi, up)};
const auto flatdiff {glm::normalize(!!diff)};
@@ -16,17 +16,17 @@ flat_orientation(const glm::vec3 & diff)
}
// Helper to lookup into a matrix given an xy vector coordinate
-template<typename M>
+template<typename M, typename I>
inline auto &
-operator^(M & m, glm::ivec2 xy)
+operator^(M & m, glm::vec<2, I> xy)
{
return m[xy.x][xy.y];
}
// Create a matrix for the angle, given the targets into the matrix
-template<typename M>
+template<typename M, typename I>
inline auto
-rotation(typename M::value_type a, glm::ivec2 c1, glm::ivec2 s1, glm::ivec2 c2, glm::ivec2 ms2)
+rotation(typename M::value_type a, glm::vec<2, I> c1, glm::vec<2, I> s1, glm::vec<2, I> c2, glm::vec<2, I> ms2)
{
M m(1);
sincosf(a, m ^ s1, m ^ c1);
@@ -39,51 +39,51 @@ rotation(typename M::value_type a, glm::ivec2 c1, glm::ivec2 s1, glm::ivec2 c2,
glm::mat2
rotate_flat(float a)
{
- return rotation<glm::mat2>(a, {0, 0}, {0, 1}, {1, 1}, {1, 0});
+ return rotation<glm::mat2, glm::length_t>(a, {0, 0}, {0, 1}, {1, 1}, {1, 0});
}
// Create a yaw transformation matrix
glm::mat4
rotate_yaw(float a)
{
- return rotation<glm::mat4>(a, {0, 0}, {1, 0}, {1, 1}, {0, 1});
+ return rotation<glm::mat4, glm::length_t>(a, {0, 0}, {1, 0}, {1, 1}, {0, 1});
}
// Create a roll transformation matrix
glm::mat4
rotate_roll(float a)
{
- return rotation<glm::mat4>(a, {0, 0}, {2, 0}, {2, 2}, {0, 2});
+ return rotation<glm::mat4, glm::length_t>(a, {0, 0}, {2, 0}, {2, 2}, {0, 2});
}
// Create a pitch transformation matrix
glm::mat4
rotate_pitch(float a)
{
- return rotation<glm::mat4>(a, {1, 1}, {1, 2}, {2, 2}, {2, 1});
+ return rotation<glm::mat4, glm::length_t>(a, {1, 1}, {1, 2}, {2, 2}, {2, 1});
}
// Create a combined yaw, pitch, roll transformation matrix
glm::mat4
-rotate_ypr(glm::vec3 a)
+rotate_ypr(Rotation3D a)
{
return rotate_yaw(a.y) * rotate_pitch(a.x) * rotate_roll(a.z);
}
glm::mat4
-rotate_yp(glm::vec2 a)
+rotate_yp(Rotation2D a)
{
return rotate_yaw(a.y) * rotate_pitch(a.x);
}
float
-vector_yaw(const glm::vec3 & diff)
+vector_yaw(const Direction3D & diff)
{
return std::atan2(diff.x, diff.y);
}
float
-vector_pitch(const glm::vec3 & diff)
+vector_pitch(const Direction3D & diff)
{
return std::atan(diff.z);
}
@@ -106,7 +106,7 @@ normalize(float ang)
return ang;
}
-Arc::Arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p) :
+Arc::Arc(const Position3D & centre3, const Position3D & e0p, const Position3D & e1p) :
Arc([&]() -> Arc {
const auto diffa = e0p - centre3;
const auto diffb = e1p - centre3;
@@ -120,8 +120,8 @@ Arc::Arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p
{
}
-std::pair<glm::vec2, bool>
-find_arc_centre(glm::vec2 as, float entrys, glm::vec2 bs, float entrye)
+std::pair<Position2D, bool>
+find_arc_centre(Position2D as, float entrys, Position2D bs, float entrye)
{
if (as == bs) {
return {as, false};
@@ -129,8 +129,8 @@ find_arc_centre(glm::vec2 as, float entrys, glm::vec2 bs, float entrye)
return find_arc_centre(as, sincosf(entrys + half_pi), bs, sincosf(entrye - half_pi));
}
-std::pair<glm::vec2, bool>
-find_arc_centre(glm::vec2 as, glm::vec2 ad, glm::vec2 bs, glm::vec2 bd)
+std::pair<Position2D, bool>
+find_arc_centre(Position2D as, Position2D ad, Position2D bs, Position2D bd)
{
const auto det = bd.x * ad.y - bd.y * ad.x;
if (det != 0) { // near parallel line will yield noisy results
@@ -142,7 +142,7 @@ find_arc_centre(glm::vec2 as, glm::vec2 ad, glm::vec2 bs, glm::vec2 bd)
}
std::pair<float, float>
-find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye)
+find_arcs_radius(Position2D start, float entrys, Position2D end, float entrye)
{
const auto getrad = [&](float leftOrRight) {
return find_arcs_radius(start, sincosf(entrys + leftOrRight), end, sincosf(entrye + leftOrRight));
@@ -151,7 +151,7 @@ find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye)
}
float
-find_arcs_radius(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd)
+find_arcs_radius(Position2D start, Position2D ad, Position2D end, Position2D bd)
{
// Short name functions for big forula
auto sqrt = [](float v) {
diff --git a/lib/ray.cpp b/lib/ray.cpp
index c4e0d8c..9fb3648 100644
--- a/lib/ray.cpp
+++ b/lib/ray.cpp
@@ -2,13 +2,13 @@
#include <algorithm>
Ray
-Ray::fromPoints(glm::vec3 start, glm::vec3 p)
+Ray::fromPoints(Position3D start, Position3D p)
{
return {start, glm::normalize(p - start)};
}
float
-Ray::distanceToLine(const glm::vec3 & p1, const glm::vec3 & e1) const
+Ray::distanceToLine(const Position3D & p1, const Position3D & e1) const
{
// https://en.wikipedia.org/wiki/Skew_lines
const auto diff = p1 - e1;
@@ -25,10 +25,10 @@ Ray::distanceToLine(const glm::vec3 & p1, const glm::vec3 & e1) const
}
bool
-Ray::passesCloseToEdges(const std::span<const glm::vec3> positions, float distance) const
+Ray::passesCloseToEdges(const std::span<const Position3D> positions, float distance) const
{
return std::adjacent_find(positions.begin(), positions.end(),
- [this, distance](const glm::vec3 & a, const glm::vec3 & b) {
+ [this, distance](const Position3D & a, const Position3D & b) {
return distanceToLine(a, b) <= distance;
})
!= positions.end();
diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp
index 177ab6a..9af08cb 100644
--- a/test/test-assetFactory.cpp
+++ b/test/test-assetFactory.cpp
@@ -25,7 +25,7 @@ BOOST_GLOBAL_FIXTURE(TestMainWindow);
const std::filesystem::path TMP {"/tmp"};
-class FactoryFixture : public TestRenderOutputSize<glm::ivec2 {2048, 1024}>, public SceneProvider {
+class FactoryFixture : public TestRenderOutputSize<TextureAbsCoord {2048, 1024}>, public SceneProvider {
public:
FactoryFixture() : sceneRenderer {size, output} { }
diff --git a/test/testRenderOutput.cpp b/test/testRenderOutput.cpp
index 464b0b3..9af4451 100644
--- a/test/testRenderOutput.cpp
+++ b/test/testRenderOutput.cpp
@@ -1,7 +1,7 @@
#include "testRenderOutput.h"
#include <stdexcept>
-TestRenderOutput::TestRenderOutput(glm::ivec2 s) : size {s}
+TestRenderOutput::TestRenderOutput(TextureAbsCoord s) : size {s}
{
glBindFramebuffer(GL_FRAMEBUFFER, output);
const auto configuregdata
diff --git a/ui/builders/straight.cpp b/ui/builders/straight.cpp
index 4fa9585..9b262bb 100644
--- a/ui/builders/straight.cpp
+++ b/ui/builders/straight.cpp
@@ -47,7 +47,7 @@ BuilderStraight::click(Network * network, const GeoData * geoData, const SDL_Mou
}
void
-BuilderStraight::create(Network * network, glm::vec3 p1, glm::vec3 p2) const
+BuilderStraight::create(Network * network, Position3D p1, Position3D p2) const
{
network->addStraight(p1, p2);
}
diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp
index 808e0e4..a451ee1 100644
--- a/ui/gameMainSelector.cpp
+++ b/ui/gameMainSelector.cpp
@@ -8,6 +8,7 @@
#include <game/selectable.h>
#include <game/worldobject.h> // IWYU pragma: keep
#include <gfx/gl/camera.h>
+#include <math.h>
#include <optional>
#include <span>
#include <stream_support.h>
@@ -16,7 +17,7 @@
GameMainSelector::GameMainSelector(const Camera * c, ScreenAbsCoord size) : UIComponent {{{}, size}}, camera {c} { }
-constexpr glm::vec2 TargetPos {5, 45};
+constexpr ScreenAbsCoord TargetPos {5, 45};
void
GameMainSelector::render(const UIShader & shader, const Position & parentPos) const
@@ -41,7 +42,7 @@ bool
GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos)
{
const auto getRay = [this](const auto & e) {
- const auto mouse = glm::vec2 {e.x, e.y} / position.size;
+ const auto mouse = ScreenRelCoord {e.x, e.y} / position.size;
return camera->unProject(mouse);
};
if (target) {
@@ -72,8 +73,8 @@ GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos)
void
GameMainSelector::defaultClick(const Ray & ray)
{
- glm::vec2 baryPos {};
- float distance;
+ Position2D baryPos {};
+ float distance {};
if (const auto selected
= gameState->world.applyOne<Selectable>(&Selectable::intersectRay, ray, &baryPos, &distance);
diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp
index b94accd..15f1e07 100644
--- a/ui/gameMainWindow.cpp
+++ b/ui/gameMainWindow.cpp
@@ -31,8 +31,8 @@ public:
GameMainWindow::GameMainWindow(size_t w, size_t h) :
Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {Window::size, 0}
{
- uiComponents.create<ManualCameraController>(glm::vec2 {-1150, -1150});
- auto gms = uiComponents.create<GameMainSelector>(&camera, glm::vec2 {w, h});
+ uiComponents.create<ManualCameraController>(Position2D {-1150, -1150});
+ auto gms = uiComponents.create<GameMainSelector>(&camera, ScreenAbsCoord {w, h});
uiComponents.create<GameMainToolbar>(gms.get());
}
diff --git a/ui/manualCameraController.cpp b/ui/manualCameraController.cpp
index 8e52b0e..05c1fc5 100644
--- a/ui/manualCameraController.cpp
+++ b/ui/manualCameraController.cpp
@@ -59,7 +59,7 @@ ManualCameraController::handleInput(const SDL_Event & e, const Position &)
pitch = std::clamp(pitch - 0.01F * static_cast<float>(e.motion.yrel), 0.1F, half_pi);
}
else {
- focus += rotate_flat(-direction) * glm::vec2 {-e.motion.xrel, e.motion.yrel};
+ focus += rotate_flat(-direction) * Position2D {-e.motion.xrel, e.motion.yrel};
}
}
return true;