From 582ac127f763f512c45f35e17b768487e3b51796 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Nov 2023 17:07:58 +0000 Subject: Rename TerrainMesh to GeoData to drop inplace --- game/terrain2.h | 93 --------------------------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 game/terrain2.h (limited to 'game/terrain2.h') diff --git a/game/terrain2.h b/game/terrain2.h deleted file mode 100644 index eda56d0..0000000 --- a/game/terrain2.h +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once - -#include "collections.h" // IWYU pragma: keep IterableCollection -#include "ray.h" -#include -#include -#include -#include -#include - -struct TerrainTraits : public OpenMesh::DefaultTraits { - FaceAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status); - EdgeAttributes(OpenMesh::Attributes::Status); - VertexAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status); - HalfedgeAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status); - using Point = glm::vec3; - using Normal = glm::vec3; -}; - -class TerrainMesh : public OpenMesh::TriMesh_ArrayKernelT { -private: - TerrainMesh() = default; - -public: - static TerrainMesh loadFromAsciiGrid(const std::filesystem::path &); - - struct PointFace { - // NOLINTNEXTLINE(hicpp-explicit-conversions) - PointFace(const glm::vec2 p) : point {p} { } - - PointFace(const glm::vec2 p, FaceHandle face) : point {p}, _face {face} { } - - PointFace(const glm::vec2 p, const TerrainMesh *); - PointFace(const glm::vec2 p, const TerrainMesh *, FaceHandle start); - - const glm::vec2 point; - [[nodiscard]] FaceHandle face(const TerrainMesh *) const; - [[nodiscard]] FaceHandle face(const TerrainMesh *, FaceHandle start) const; - - [[nodiscard]] bool - isLocated() const - { - return _face.is_valid(); - } - - private: - mutable FaceHandle _face {}; - }; - - template struct Triangle : public glm::vec<3, glm::vec> { - using base = glm::vec<3, glm::vec>; - using base::base; - - template Triangle(const TerrainMesh * m, Range range) - { - assert(std::distance(range.begin(), range.end()) == 3); - std::transform(range.begin(), range.end(), &base::operator[](0), [m](auto vh) { - return m->point(vh); - }); - } - - glm::vec - operator*(glm::vec2 bari) const - { - const auto & t {*this}; - return t[0] + ((t[1] - t[0]) * bari.x) + ((t[2] - t[1]) * bari.y); - } - }; - - [[nodiscard]] FaceHandle findPoint(glm::vec2) const; - [[nodiscard]] FaceHandle findPoint(glm::vec2, FaceHandle start) const; - - [[nodiscard]] glm::vec3 positionAt(const PointFace &) const; - [[nodiscard]] std::optional intersectRay(const Ray &) const; - [[nodiscard]] std::optional intersectRay(const Ray &, FaceHandle start) const; - - void walk(const PointFace & from, const glm::vec2 to, const std::function & op) const; - void walkUntil(const PointFace & from, const glm::vec2 to, const std::function & op) const; - - [[nodiscard]] auto - getExtents() const - { - return std::tie(lowerExtent, upperExtent); - } - -protected: - [[nodiscard]] static bool triangleContainsPoint(const glm::vec2, const glm::vec2, const glm::vec2, const glm::vec2); - [[nodiscard]] bool triangleContainsPoint(const glm::vec2, FaceHandle) const; - [[nodiscard]] bool triangleContainsPoint(const glm::vec2, ConstFaceVertexIter) const; - -private: - glm::vec3 lowerExtent {}, upperExtent {}; -}; -- cgit v1.2.3