summaryrefslogtreecommitdiff
path: root/game/geoData.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-11-26 14:20:28 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-11-26 14:20:28 +0000
commit3abe940a22d99939b666bd806214c8b986cb3ed9 (patch)
treebba599f39e8b328c3d4911a940a4263781e74a77 /game/geoData.cpp
parentMerge branch 'ints' into terrain (diff)
downloadilt-3abe940a22d99939b666bd806214c8b986cb3ed9.tar.bz2
ilt-3abe940a22d99939b666bd806214c8b986cb3ed9.tar.xz
ilt-3abe940a22d99939b666bd806214c8b986cb3ed9.zip
Calculate vertex normals only
Doesn't require half edge normals or face normals, which uses Newell's method, which results in integer overflow... Not to mention we don't need all the other normals.
Diffstat (limited to 'game/geoData.cpp')
-rw-r--r--game/geoData.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index 7710efe..70133a9 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -57,8 +57,7 @@ GeoData::loadFromAsciiGrid(const std::filesystem::path & input)
});
}
}
- mesh.update_face_normals();
- mesh.update_vertex_normals();
+ mesh.update_vertex_normals_only();
return mesh;
};
@@ -77,8 +76,7 @@ GeoData::createFlat(GlobalPosition2D lower, GlobalPosition2D upper, GlobalDistan
mesh.add_face(ll, uu, lu);
mesh.add_face(ll, ul, uu);
- mesh.update_face_normals();
- mesh.update_vertex_normals();
+ mesh.update_vertex_normals_only();
return mesh;
}
@@ -317,3 +315,13 @@ GeoData::findBoundaryStart() const
return is_boundary(heh);
});
}
+
+void
+GeoData::update_vertex_normals_only()
+{
+ for (auto vh : all_vertices()) {
+ Normal3D n;
+ calc_vertex_normal_correct(vh, n);
+ this->set_normal(vh, glm::normalize(n));
+ }
+}