From 5b6a6f3b241fea6d19521ddbb705e27d5e4c0268 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 20 Oct 2024 16:24:14 +0100 Subject: Move lots of maths helpers to inline, constexpr, templates Always for working with different dimensions/types --- game/network/link.cpp | 2 +- game/network/network.cpp | 2 +- game/network/rail.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'game/network') diff --git a/game/network/link.cpp b/game/network/link.cpp index 248fe7d..745896c 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -51,7 +51,7 @@ LinkCurve::positionAt(float dist, unsigned char start) const + RelativePosition3D {0, 0, static_cast(es.first->pos.z - centreBase.z) + (static_cast(es.second->pos.z - es.first->pos.z) * frac)}}; - const auto pitch {vector_pitch({0, 0, static_cast(es.second->pos.z - es.first->pos.z) / length})}; + const auto pitch {vector_pitch(difference(es.second->pos, es.first->pos) / length)}; return Location {GlobalPosition3D(relPos + relClimb) + centreBase, {pitch, normalize(ang + dirOffset[start]), 0}}; } diff --git a/game/network/network.cpp b/game/network/network.cpp index 65b2a62..fa86cb5 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -95,7 +95,7 @@ Network::routeFromTo(const Link::End & end, const Node::Ptr & dest) const GenCurveDef Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir) { - const auto diff {end - start}; + const auto diff = difference(end, start); const auto vy {vector_yaw(diff)}; const auto dir = pi + startDir; const auto flatStart {start.xy()}, flatEnd {end.xy()}; diff --git a/game/network/rail.cpp b/game/network/rail.cpp index fd07ace..c29217a 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -32,7 +32,7 @@ RailLinks::addLinksBetween(GlobalPosition3D start, GlobalPosition3D end) } // Find start link/end - opposite entry dir to existing link; so pi +... const Angle dir = pi + findNodeDirection(node1ins.first); - if (dir == vector_yaw(end - start)) { + if (dir == vector_yaw(difference(end, start))) { return addLink(start, end); } const auto flatStart {start.xy()}, flatEnd {end.xy()}; @@ -62,7 +62,7 @@ RailLinks::addLinksBetween(GlobalPosition3D start, GlobalPosition3D end) return addLink(midh, end, c2); } } - const auto diff {end - start}; + const auto diff = difference(end, start); const auto vy {vector_yaw(diff)}; const auto n2ed {(vy * 2) - dir - pi}; const auto centre {find_arc_centre(flatStart, dir, flatEnd, n2ed)}; -- cgit v1.2.3 From 56100b1c4cb02db7608763dddd77f8052a533dae Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 21 Oct 2024 18:30:16 +0100 Subject: Further template maths functions --- game/network/link.cpp | 4 ++-- game/network/network.cpp | 8 ++++---- game/network/rail.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'game/network') diff --git a/game/network/link.cpp b/game/network/link.cpp index 745896c..79af92a 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -46,7 +46,7 @@ LinkCurve::positionAt(float dist, unsigned char start) const const auto es {std::make_pair(ends[start].node.get(), ends[1 - start].node.get())}; const auto as {std::make_pair(arc[start], arc[1 - start])}; const auto ang {as.first + ((as.second - as.first) * frac)}; - const auto relPos {(sincosf(ang) || 0.F) * radius}; + const auto relPos {(sincos(ang) || 0.F) * radius}; const auto relClimb {vehiclePositionOffset() + RelativePosition3D {0, 0, static_cast(es.first->pos.z - centreBase.z) @@ -69,7 +69,7 @@ LinkCurve::intersectRay(const Ray & ray) const points.reserve(segCount); for (std::remove_const_t swing = {arc.first, centreBase.z - e0p.z}; segCount; swing += step, --segCount) { - points.emplace_back(centreBase + ((sincosf(swing.x) * radius) || swing.y)); + points.emplace_back(centreBase + ((sincos(swing.x) * radius) || swing.y)); } return ray.passesCloseToEdges(points, 1.F); } diff --git a/game/network/network.cpp b/game/network/network.cpp index fa86cb5..6ba3ed6 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -121,16 +121,16 @@ Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & en }; if (const auto radii = find_arcs_radius(flatStart, startDir, flatEnd, endDir); radii.first < radii.second) { const auto radius {radii.first}; - const auto c1 = flatStart + (sincosf(startDir + half_pi) * radius); - const auto c2 = flatEnd + (sincosf(endDir + half_pi) * radius); + const auto c1 = flatStart + (sincos(startDir + half_pi) * radius); + const auto c2 = flatEnd + (sincos(endDir + half_pi) * radius); const auto mid = (c1 + c2) / 2; const auto midh = mid || midheight(mid); return {{start, midh, c1}, {end, midh, c2}}; } else { const auto radius {radii.second}; - const auto c1 = flatStart + (sincosf(startDir - half_pi) * radius); - const auto c2 = flatEnd + (sincosf(endDir - half_pi) * radius); + const auto c1 = flatStart + (sincos(startDir - half_pi) * radius); + const auto c2 = flatEnd + (sincos(endDir - half_pi) * radius); const auto mid = (c1 + c2) / 2; const auto midh = mid || midheight(mid); return {{midh, start, c1}, {midh, end, c2}}; diff --git a/game/network/rail.cpp b/game/network/rail.cpp index c29217a..6f04070 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -45,8 +45,8 @@ RailLinks::addLinksBetween(GlobalPosition3D start, GlobalPosition3D end) const float dir2 = pi + findNodeDirection(node2ins.first); if (const auto radii = find_arcs_radius(flatStart, dir, flatEnd, dir2); radii.first < radii.second) { const auto radius {radii.first}; - const auto c1 = flatStart + (sincosf(dir + half_pi) * radius); - const auto c2 = flatEnd + (sincosf(dir2 + half_pi) * radius); + const auto c1 = flatStart + (sincos(dir + half_pi) * radius); + const auto c2 = flatEnd + (sincos(dir2 + half_pi) * radius); const auto mid = (c1 + c2) / 2; const auto midh = mid || midheight(mid); addLink(start, midh, c1); @@ -54,8 +54,8 @@ RailLinks::addLinksBetween(GlobalPosition3D start, GlobalPosition3D end) } else { const auto radius {radii.second}; - const auto c1 = flatStart + (sincosf(dir - half_pi) * radius); - const auto c2 = flatEnd + (sincosf(dir2 - half_pi) * radius); + const auto c1 = flatStart + (sincos(dir - half_pi) * radius); + const auto c2 = flatEnd + (sincos(dir2 - half_pi) * radius); const auto mid = (c1 + c2) / 2; const auto midh = mid || midheight(mid); addLink(midh, start, c1); -- cgit v1.2.3