summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game/geoData.cpp15
-rw-r--r--game/geoData.h11
-rw-r--r--test/test-geoData.cpp2
3 files changed, 18 insertions, 10 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index a63e03b..cc9a056 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -410,10 +410,8 @@ GeoData::triangleContainsTriangle(const Triangle<2> & a, const Triangle<2> & b)
return triangleContainsPoint(a.x, b) && triangleContainsPoint(a.y, b) && triangleContainsPoint(a.z, b);
}
-static constexpr RelativeDistance MAX_SLOPE = .5F;
-
void
-GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const Surface &)
+GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const SetHeightsOpts & opts)
{
if (triangleStrip.size() < 3) {
return;
@@ -434,12 +432,12 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const
std::vector<VertexHandle> newVerts;
newVerts.reserve(newVerts.size());
std::transform(triangleStrip.begin(), triangleStrip.end(), std::back_inserter(newVerts),
- [this, &newVerts, &vertexDistFrom](const auto tsPoint) {
+ [this, &newVerts, &vertexDistFrom, &opts](const auto tsPoint) {
const auto face = findPoint(tsPoint);
if (const auto nearest = std::ranges::min(std::views::iota(fv_begin(face), fv_end(face))
| std::views::transform(vertexDistFrom(tsPoint)),
{}, &std::pair<VertexHandle, float>::second);
- nearest.second < 500.F && !std::ranges::contains(newVerts, nearest.first)) {
+ nearest.second < opts.nearNodeTolerance && !std::ranges::contains(newVerts, nearest.first)) {
point(nearest.first) = tsPoint;
return nearest.first;
}
@@ -466,7 +464,7 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const
// Cut along each edge of triangleStrip AB, AC, BC, BD, CD, CE etc
std::map<VertexHandle, const Triangle<3> *> boundaryTriangles;
- auto doBoundaryPart = [this, &boundaryTriangles, &newVerts, &vertexDistFrom](
+ auto doBoundaryPart = [this, &boundaryTriangles, &newVerts, &vertexDistFrom, &opts](
VertexHandle start, VertexHandle end, const Triangle<3> & triangle) {
boundaryTriangles.emplace(start, &triangle);
const auto endPoint = point(end);
@@ -484,7 +482,8 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const
if (const auto nextDist
= std::ranges::min(nexts | std::views::transform(vertexDistFrom(*intersection)),
{}, &std::pair<VertexHandle, float>::second);
- nextDist.second < 500.F && !boundaryTriangles.contains(nextDist.first)
+ nextDist.second < opts.nearNodeTolerance
+ && !boundaryTriangles.contains(nextDist.first)
&& !std::ranges::contains(newVerts, nextDist.first)) {
start = nextDist.first;
point(start) = positionOnTriangle(*intersection, triangle);
@@ -534,7 +533,7 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const
todoOutHalfEdges(toVertex);
}
else if (!toTriangle) { // point without the new strip, adjust vertically by limit
- const auto maxOffset = static_cast<GlobalDistance>(MAX_SLOPE * glm::length(difference(heh).xy()));
+ const auto maxOffset = static_cast<GlobalDistance>(opts.maxSlope * glm::length(difference(heh).xy()));
const auto newHeight = std::clamp(toPoint.z, fromPoint.z - maxOffset, fromPoint.z + maxOffset);
if (newHeight != toPoint.z) {
toPoint.z = newHeight;
diff --git a/game/geoData.h b/game/geoData.h
index 5daa7a4..51bb28b 100644
--- a/game/geoData.h
+++ b/game/geoData.h
@@ -142,7 +142,16 @@ public:
[[nodiscard]] HalfedgeHandle findEntry(const GlobalPosition2D from, const GlobalPosition2D to) const;
- void setHeights(const std::span<const GlobalPosition3D> triangleStrip, const Surface &);
+ struct SetHeightsOpts {
+ static constexpr auto DEFAULT_NEAR_NODE_TOLERANACE = 500.F;
+ static constexpr auto DEFAULT_MAX_SLOPE = 0.5F;
+
+ const Surface & surface;
+ RelativeDistance nearNodeTolerance = DEFAULT_NEAR_NODE_TOLERANACE;
+ RelativeDistance maxSlope = DEFAULT_MAX_SLOPE;
+ };
+
+ void setHeights(std::span<const GlobalPosition3D> triangleStrip, const SetHeightsOpts &);
[[nodiscard]] auto
getExtents() const
diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp
index 35d6bae..17e1741 100644
--- a/test/test-geoData.cpp
+++ b/test/test-geoData.cpp
@@ -232,7 +232,7 @@ BOOST_DATA_TEST_CASE(deform, loadFixtureJson<DeformTerrainData>("geoData/deform/
Surface surface;
surface.colorBias = RGB {0, 0, 1};
auto gd = std::make_shared<GeoData>(GeoData::createFlat({0, 0}, {1000000, 1000000}, 100));
- BOOST_CHECK_NO_THROW(gd->setHeights(points, surface));
+ BOOST_CHECK_NO_THROW(gd->setHeights(points, {.surface = surface}));
ApplicationBase ab;
TestMainWindow tmw;