From 68a23b27925142fed3b1e53b2f17ad2c90878e21 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 12 Feb 2024 23:25:00 +0000 Subject: Add helpers for testing for triangle overlap/containedness --- game/geoData.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index e234bfe..2fd3aa5 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -103,6 +103,8 @@ protected: [[nodiscard]] static bool triangleContainsPoint(const GlobalPosition2D, const Triangle<2> &); [[nodiscard]] bool triangleContainsPoint(const GlobalPosition2D, FaceHandle) const; + [[nodiscard]] static bool triangleOverlapsTriangle(const Triangle<2> &, const Triangle<2> &); + [[nodiscard]] static bool triangleContainsTriangle(const Triangle<2> &, const Triangle<2> &); [[nodiscard]] HalfedgeHandle findBoundaryStart() const; void update_vertex_normals_only(); -- cgit v1.2.3 From 849f4aa735352704995ffb51bf23dadf795bb119 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 13 Feb 2024 01:36:42 +0000 Subject: Include face handle in intersectRay result --- game/geoData.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 2fd3aa5..f599552 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -74,8 +74,10 @@ public: [[nodiscard]] FaceHandle findPoint(GlobalPosition2D, FaceHandle start) const; [[nodiscard]] GlobalPosition3D positionAt(const PointFace &) const; - [[nodiscard]] std::optional intersectRay(const Ray &) const; - [[nodiscard]] std::optional intersectRay(const Ray &, FaceHandle start) const; + using IntersectionLocation = std::pair; + using IntersectionResult = std::optional; + [[nodiscard]] IntersectionResult intersectRay(const Ray &) const; + [[nodiscard]] IntersectionResult intersectRay(const Ray &, FaceHandle start) const; void walk(const PointFace & from, const GlobalPosition2D to, const std::function & op) const; void walkUntil(const PointFace & from, const GlobalPosition2D to, const std::function & op) const; -- cgit v1.2.3 From 6535a9c7f4e8fec978c079d45c0349a004b73241 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 14 Feb 2024 02:04:44 +0000 Subject: Fix getting cartesian coords from triangle baripos --- game/geoData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index f599552..6c6ae26 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -66,7 +66,7 @@ public: { const auto & t {*this}; return t[0] + GlobalPosition(RelativePosition(t[1] - t[0]) * bari.x) - + GlobalPosition(RelativePosition(t[2] - t[1]) * bari.y); + + GlobalPosition(RelativePosition(t[2] - t[0]) * bari.y); } }; -- cgit v1.2.3 From 3770b101cfc5ad37a069850b422f0098ade7fc08 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 22 Feb 2024 01:16:29 +0000 Subject: First cut of terrain deformation This "works" for some definition of works... But it's flawed in many ways, not least the following: * It's glitchy for no obvious reason * It's unreliable; fails if you tweak the parameters * The sides of the modified area are triangulated in the dumbest possible fashion, which results in ill-formed polygons * Probably other things, but... It works, remember... --- game/geoData.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 6c6ae26..4d8e11c 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -89,6 +89,8 @@ public: [[nodiscard]] HalfedgeHandle findEntry(const GlobalPosition2D from, const GlobalPosition2D to) const; + void setHeights(const std::span triangleStrip); + [[nodiscard]] auto getExtents() const { -- cgit v1.2.3 From 6810d01af98a67f39a7698f7d16339eb58dbef25 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 31 Mar 2024 21:58:18 +0100 Subject: Factor out some helper lambdas into members --- game/geoData.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 5671954..88eb304 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -109,6 +109,9 @@ protected: [[nodiscard]] static bool triangleOverlapsTriangle(const Triangle<2> &, const Triangle<2> &); [[nodiscard]] static bool triangleContainsTriangle(const Triangle<2> &, const Triangle<2> &); [[nodiscard]] HalfedgeHandle findBoundaryStart() const; + [[nodiscard]] RelativePosition3D difference(const HalfedgeHandle) const; + [[nodiscard]] RelativeDistance length(const HalfedgeHandle) const; + [[nodiscard]] GlobalPosition3D centre(const HalfedgeHandle) const; void update_vertex_normals_only(); -- cgit v1.2.3 From a4b3f04803aceb9c750d4317a3e7cf3e56996518 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 1 Apr 2024 20:07:00 +0100 Subject: Replace face 4-way split Fixes integer rounding issue and returns the new face handles --- game/geoData.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 88eb304..6dacd9a 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -115,6 +115,9 @@ protected: void update_vertex_normals_only(); + using OpenMesh::TriMesh_ArrayKernelT::split; + std::array split(FaceHandle); + private: GlobalPosition3D lowerExtent {}, upperExtent {}; }; -- cgit v1.2.3 From d384c5dc548cf6d6a0cce0db744fc3b168d7be96 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 1 Apr 2024 20:08:56 +0100 Subject: Add lots of simple triangle property helpers --- game/geoData.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 6dacd9a..03bc159 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -61,11 +61,69 @@ public: }); } + [[nodiscard]] glm::vec operator*(BaryPosition bari) const { - const auto & t {*this}; - return t[0] + (RelativePosition(t[1] - t[0]) * bari.x) + (RelativePosition(t[2] - t[0]) * bari.y); + return p(0) + (difference(p(0), p(1)) * bari.x) + (difference(p(0), p(2)) * bari.y); + } + + [[nodiscard]] + auto + area() const + requires(Dim == 3) + { + return glm::length(crossProduct(difference(p(0), p(1)), difference(p(0), p(2)))) / 2.F; + } + + [[nodiscard]] + Normal3D + normal() const + requires(Dim == 3) + { + return crossProduct(difference(p(0), p(1)), difference(p(0), p(2))); + } + + [[nodiscard]] + Normal3D + nnormal() const + requires(Dim == 3) + { + return glm::normalize(normal()); + } + + [[nodiscard]] + auto + angle(glm::length_t c) const + { + return Arc {P(c), P(c + 2), P(c + 1)}.length(); + } + + template + [[nodiscard]] + auto + angleAt(const GlobalPosition pos) const + requires(D <= Dim) + { + for (glm::length_t i {}; i < 3; ++i) { + if (GlobalPosition {p(i)} == pos) { + return angle(i); + } + } + return 0.F; + } + + [[nodiscard]] + inline auto + p(const glm::length_t i) const + { + return base::operator[](i); + } + + [[nodiscard]] inline auto + P(const glm::length_t i) const + { + return base::operator[](i % 3); } }; @@ -110,6 +168,14 @@ protected: [[nodiscard]] static bool triangleContainsTriangle(const Triangle<2> &, const Triangle<2> &); [[nodiscard]] HalfedgeHandle findBoundaryStart() const; [[nodiscard]] RelativePosition3D difference(const HalfedgeHandle) const; + + template + [[nodiscard]] static RelativePosition + difference(const GlobalPosition a, const GlobalPosition b) + { + return b - a; + } + [[nodiscard]] RelativeDistance length(const HalfedgeHandle) const; [[nodiscard]] GlobalPosition3D centre(const HalfedgeHandle) const; -- cgit v1.2.3 From 666f4603ee94148e41b4433a7f7a02d2f79d4651 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 4 Apr 2024 19:57:41 +0100 Subject: Update normals only as required --- game/geoData.h | 1 + 1 file changed, 1 insertion(+) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 03bc159..021b4c7 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -180,6 +180,7 @@ protected: [[nodiscard]] GlobalPosition3D centre(const HalfedgeHandle) const; void update_vertex_normals_only(); + void update_vertex_normals_only(VertexIter start); using OpenMesh::TriMesh_ArrayKernelT::split; std::array split(FaceHandle); -- cgit v1.2.3