summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game/geoData.cpp5
-rw-r--r--game/geoData.h3
-rw-r--r--game/network/link.cpp5
-rw-r--r--game/network/network.cpp8
-rw-r--r--game/network/rail.cpp8
-rw-r--r--game/vehicles/railVehicle.cpp2
-rw-r--r--gfx/followCameraController.cpp4
-rw-r--r--gfx/gl/camera.cpp2
-rw-r--r--lib/maths.h28
-rw-r--r--test/test-geoData.cpp4
-rw-r--r--ui/manualCameraController.cpp2
11 files changed, 48 insertions, 23 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index 86b9152..1f6768a 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -227,8 +227,7 @@ GeoData::intersectRay(const Ray<GlobalPosition3D> & ray, FaceHandle face) const
{
GeoData::IntersectionResult out;
walkUntil(PointFace {ray.start, face},
- ray.start.xy()
- + GlobalPosition2D(ray.direction.xy() * RelativePosition2D(upperExtent.xy() - lowerExtent.xy())),
+ ray.start.xy() + (ray.direction.xy() * RelativePosition2D(upperExtent.xy() - lowerExtent.xy())),
[&out, &ray, this](FaceHandle face) {
BaryPosition bari {};
RelativeDistance dist {};
@@ -436,7 +435,7 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip)
const auto extrusion
= extrusionDir * std::max(0.F, RelativeDistance(limit - p1.z) / extrusionDir.z);
- return p1 + GlobalPosition3D(extrusion);
+ return p1 + extrusion;
};
return std::make_pair(doExtrusion(-2, lowerExtent.z - 100), doExtrusion(2, upperExtent.z + 100));
});
diff --git a/game/geoData.h b/game/geoData.h
index 4d8e11c..5671954 100644
--- a/game/geoData.h
+++ b/game/geoData.h
@@ -65,8 +65,7 @@ public:
operator*(BaryPosition bari) const
{
const auto & t {*this};
- return t[0] + GlobalPosition<Dim>(RelativePosition<Dim>(t[1] - t[0]) * bari.x)
- + GlobalPosition<Dim>(RelativePosition<Dim>(t[2] - t[0]) * bari.y);
+ return t[0] + (RelativePosition<Dim>(t[1] - t[0]) * bari.x) + (RelativePosition<Dim>(t[2] - t[0]) * bari.y);
}
};
diff --git a/game/network/link.cpp b/game/network/link.cpp
index 932fc67..122eaf4 100644
--- a/game/network/link.cpp
+++ b/game/network/link.cpp
@@ -28,8 +28,7 @@ LinkStraight::positionAt(RelativeDistance dist, unsigned char start) const
const auto es {std::make_pair(ends[start].node.get(), ends[1 - start].node.get())};
const RelativePosition3D diff {es.second->pos - es.first->pos};
const auto dir {glm::normalize(diff)};
- return Location {es.first->pos + GlobalPosition3D(vehiclePositionOffset() + dir * dist),
- {vector_pitch(dir), vector_yaw(dir), 0}};
+ return Location {es.first->pos + (vehiclePositionOffset() + dir * dist), {vector_pitch(dir), vector_yaw(dir), 0}};
}
bool
@@ -70,7 +69,7 @@ LinkCurve::intersectRay(const Ray<GlobalPosition3D> & ray) const
points.reserve(segCount);
for (std::remove_const_t<decltype(step)> swing = {arc.first, centreBase.z - e0p.z}; segCount;
swing += step, --segCount) {
- points.emplace_back(centreBase + GlobalPosition3D((sincosf(swing.x) * radius) || swing.y));
+ points.emplace_back(centreBase + ((sincosf(swing.x) * radius) || swing.y));
}
return ray.passesCloseToEdges(points, 1.F);
}
diff --git a/game/network/network.cpp b/game/network/network.cpp
index b6c52b8..65b2a62 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 + GlobalPosition2D(sincosf(startDir + half_pi) * radius);
- const auto c2 = flatEnd + GlobalPosition2D(sincosf(endDir + half_pi) * radius);
+ const auto c1 = flatStart + (sincosf(startDir + half_pi) * radius);
+ const auto c2 = flatEnd + (sincosf(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 + GlobalPosition2D(sincosf(startDir - half_pi) * radius);
- const auto c2 = flatEnd + GlobalPosition2D(sincosf(endDir - half_pi) * radius);
+ const auto c1 = flatStart + (sincosf(startDir - half_pi) * radius);
+ const auto c2 = flatEnd + (sincosf(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 176a704..34cbceb 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 + GlobalPosition2D(sincosf(dir + half_pi) * radius);
- const auto c2 = flatEnd + GlobalPosition2D(sincosf(dir2 + half_pi) * radius);
+ const auto c1 = flatStart + (sincosf(dir + half_pi) * radius);
+ const auto c2 = flatEnd + (sincosf(dir2 + half_pi) * radius);
const auto mid = (c1 + c2) / 2;
const auto midh = mid || midheight(mid);
addLink<RailLinkCurve>(start, midh, c1);
@@ -54,8 +54,8 @@ RailLinks::addLinksBetween(GlobalPosition3D start, GlobalPosition3D end)
}
else {
const auto radius {radii.second};
- const auto c1 = flatStart + GlobalPosition2D(sincosf(dir - half_pi) * radius);
- const auto c2 = flatEnd + GlobalPosition2D(sincosf(dir2 - half_pi) * radius);
+ const auto c1 = flatStart + (sincosf(dir - half_pi) * radius);
+ const auto c2 = flatEnd + (sincosf(dir2 - half_pi) * radius);
const auto mid = (c1 + c2) / 2;
const auto midh = mid || midheight(mid);
addLink<RailLinkCurve>(midh, start, c1);
diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp
index 4a1fdab..59d1e83 100644
--- a/game/vehicles/railVehicle.cpp
+++ b/game/vehicles/railVehicle.cpp
@@ -51,7 +51,7 @@ RailVehicle::intersectRay(const Ray<GlobalPosition3D> & ray, BaryPosition & bary
constexpr const auto Z = 3900.F;
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);
+ return location.position() + (moveBy * corner);
};
static constexpr const std::array<glm::vec<3, uint8_t>, 10> triangles {{
// Front
diff --git a/gfx/followCameraController.cpp b/gfx/followCameraController.cpp
index 5114840..52dfb35 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 + GlobalPosition3D(up * 4.8F), -sincosf(rot.y) || 0.F);
+ camera->setView(pos + (up * 4.8F), -sincosf(rot.y) || 0.F);
break;
case Mode::ISO:
- camera->setView(pos + GlobalPosition3D((up + north + east) * 40.F), glm::normalize(down + south + west),
+ camera->setView(pos + ((up + north + east) * 40.F), glm::normalize(down + south + west),
glm::normalize(up - north - east));
break;
}
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index fb711dd..82b11a6 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -43,7 +43,7 @@ Camera::extentsAtDist(const GlobalDistance dist) const
if (target.z < -1500) {
const CalcPosition3D diff = target - position;
const CalcDistance limit = -1500 - position.z;
- return {position + GlobalPosition3D((limit * diff) / diff.z), (limit * dist) / diff.z};
+ return {position + ((limit * diff) / diff.z), (limit * dist) / diff.z};
}
return {target, dist};
};
diff --git a/lib/maths.h b/lib/maths.h
index a867c39..5886326 100644
--- a/lib/maths.h
+++ b/lib/maths.h
@@ -32,6 +32,34 @@ constexpr auto quarter_pi {half_pi / 2};
constexpr auto pi {glm::pi<float>()};
constexpr auto two_pi {glm::two_pi<float>()};
+template<glm::length_t D>
+constexpr inline GlobalPosition<D>
+operator+(const GlobalPosition<D> & g, const RelativePosition<D> & r)
+{
+ return g + GlobalPosition<D>(glm::round(r));
+}
+
+template<glm::length_t D>
+constexpr inline GlobalPosition<D>
+operator+(const GlobalPosition<D> & g, const CalcPosition<D> & r)
+{
+ return g + GlobalPosition<D>(r);
+}
+
+template<glm::length_t D>
+constexpr inline GlobalPosition<D>
+operator-(const GlobalPosition<D> & g, const RelativePosition<D> & r)
+{
+ return g - GlobalPosition<D>(glm::round(r));
+}
+
+template<glm::length_t D>
+constexpr inline GlobalPosition<D>
+operator-(const GlobalPosition<D> & g, const CalcPosition<D> & r)
+{
+ return g - GlobalPosition<D>(r);
+}
+
glm::mat4 flat_orientation(const Rotation3D & diff);
// C++ wrapper for C's sincosf, but with references, not pointers
diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp
index 6602b05..ac1d668 100644
--- a/test/test-geoData.cpp
+++ b/test/test-geoData.cpp
@@ -114,8 +114,8 @@ using FindRayIntersectData = std::tuple<GlobalPosition3D, Direction3D, GlobalPos
BOOST_DATA_TEST_CASE(findRayIntersect,
boost::unit_test::data::make<FindRayIntersectData>({
- {{310000000, 490000000, 50000}, {1, 1, -2}, {310008582, 490008582, 32834}},
- {{310000000, 490000000, 50000}, {1, 1, -1}, {310017131, 490017131, 32868}},
+ {{310000000, 490000000, 50000}, {1, 1, -2}, {310008583, 490008583, 32834}},
+ {{310000000, 490000000, 50000}, {1, 1, -1}, {310017131, 490017131, 32869}},
}),
p, d, i)
{
diff --git a/ui/manualCameraController.cpp b/ui/manualCameraController.cpp
index a55b9cc..065e1d8 100644
--- a/ui/manualCameraController.cpp
+++ b/ui/manualCameraController.cpp
@@ -80,5 +80,5 @@ void
ManualCameraController::updateCamera(Camera * camera) const
{
const auto forward = glm::normalize(sincosf(direction) || -sin(pitch));
- camera->setView((focus || 0) - GlobalPosition3D(forward * 3.F * std::pow(dist, 1.3F)), forward);
+ camera->setView((focus || 0) - (forward * 3.F * std::pow(dist, 1.3F)), forward);
}