From 4102debac6fc9bcc58091ead007dbce47b42c712 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jul 2024 12:19:12 +0100 Subject: Calculate and store the extents of a mesh --- gfx/models/mesh.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gfx/models/mesh.cpp') diff --git a/gfx/models/mesh.cpp b/gfx/models/mesh.cpp index e7474ca..1b6ecda 100644 --- a/gfx/models/mesh.cpp +++ b/gfx/models/mesh.cpp @@ -1,6 +1,9 @@ #include "mesh.h" -MeshBase::MeshBase(GLsizei m_numIndices, GLenum mode) : m_numIndices {m_numIndices}, mode {mode} { } +MeshBase::MeshBase(GLsizei m_numIndices, GLenum mode, std::pair minmax) : + m_numIndices {m_numIndices}, mode {mode}, min {minmax.first}, max {minmax.second} +{ +} void MeshBase::Draw() const -- cgit v1.2.3 From 064864eac61e936af909470fcccc5c67ef6d3169 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 11 Aug 2024 19:32:23 +0100 Subject: Calculate centre and size of mesh, wrap it all in a Dimensions object --- gfx/models/mesh.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'gfx/models/mesh.cpp') diff --git a/gfx/models/mesh.cpp b/gfx/models/mesh.cpp index 1b6ecda..2eae160 100644 --- a/gfx/models/mesh.cpp +++ b/gfx/models/mesh.cpp @@ -1,10 +1,33 @@ #include "mesh.h" -MeshBase::MeshBase(GLsizei m_numIndices, GLenum mode, std::pair minmax) : - m_numIndices {m_numIndices}, mode {mode}, min {minmax.first}, max {minmax.second} +MeshBase::MeshBase(GLsizei m_numIndices, GLenum mode, const std::vector & positions) : + m_numIndices {m_numIndices}, mode {mode}, dimensions {positions} { } +MeshBase::Dimensions::Dimensions(const std::span positions) : + Dimensions {positions, {extents(positions, 0), extents(positions, 1), extents(positions, 2)}} +{ +} + +MeshBase::Dimensions::Dimensions( + const std::span positions, const std::array & extents1ds) : + minExtent(extents1ds[0].min, extents1ds[1].min, extents1ds[2].min), + maxExtent(extents1ds[0].max, extents1ds[1].max, extents1ds[2].max), centre {(minExtent + maxExtent) / 2.0F}, + size {std::ranges::max(positions | std::views::transform([this](const auto & v) { + return glm::distance(v, centre); + }))} +{ +} + +MeshBase::Dimensions::Extents1D +MeshBase::Dimensions::extents(const std::span positions, glm::length_t D) +{ + return std::ranges::minmax(positions | std::views::transform([D](const auto & v) { + return v[D]; + })); +} + void MeshBase::Draw() const { -- cgit v1.2.3