summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-11-03 14:13:00 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-11-03 14:13:00 +0000
commit1572e1ed7173d139df03df93bd6423ffdcc9e757 (patch)
treec764338bfd7bc57f30a21ce16a7fe298f0653b53 /game
parentFix pruning of link history (diff)
downloadilt-1572e1ed7173d139df03df93bd6423ffdcc9e757.tar.bz2
ilt-1572e1ed7173d139df03df93bd6423ffdcc9e757.tar.xz
ilt-1572e1ed7173d139df03df93bd6423ffdcc9e757.zip
Reuse close vertices when deforming terrain
Diffstat (limited to 'game')
-rw-r--r--game/geoData.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index d212651..8975d46 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -524,21 +524,29 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const
const auto doExtrusion = [this](VertexHandle & extrusionVertex, Direction2D direction,
GlobalPosition3D boundaryVertex, RelativeDistance vert) {
const auto extrusionDir = glm::normalize(direction || vert);
+ const auto intersectAsNeeded = [this, &extrusionVertex](FaceHandle face, GlobalPosition3D pos) {
+ if (const auto closeVertex = std::find_if(fv_begin(face), fv_end(face),
+ [this, pos](const auto & vertex) {
+ return glm::length(::difference(pos, this->point(vertex))) < 10.F;
+ });
+ closeVertex != fv_end(face)) {
+ extrusionVertex = *closeVertex;
+ return;
+ }
+ extrusionVertex = split(face, pos);
+ };
if (!extrusionVertex.is_valid()) {
if (const auto intersect = intersectRay({boundaryVertex, extrusionDir})) {
- auto splitVertex = split(intersect->second, intersect->first);
- extrusionVertex = splitVertex;
+ intersectAsNeeded(intersect->second, intersect->first);
}
else if (const auto intersect
= intersectRay({boundaryVertex + GlobalPosition3D {1, 1, 0}, extrusionDir})) {
- auto splitVertex = split(intersect->second, intersect->first);
- extrusionVertex = splitVertex;
+ intersectAsNeeded(intersect->second, intersect->first);
}
else if (const auto intersect
= intersectRay({boundaryVertex + GlobalPosition3D {1, 0, 0}, extrusionDir})) {
- auto splitVertex = split(intersect->second, intersect->first);
- extrusionVertex = splitVertex;
+ intersectAsNeeded(intersect->second, intersect->first);
}
}