summaryrefslogtreecommitdiff
path: root/gfx/models/mesh.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-08-11 19:32:23 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-08-11 19:32:23 +0100
commit064864eac61e936af909470fcccc5c67ef6d3169 (patch)
tree079ebd953589207cf70b87648eedd543013b078a /gfx/models/mesh.cpp
parentUse texture alpha in shadow stencil (diff)
downloadilt-064864eac61e936af909470fcccc5c67ef6d3169.tar.bz2
ilt-064864eac61e936af909470fcccc5c67ef6d3169.tar.xz
ilt-064864eac61e936af909470fcccc5c67ef6d3169.zip
Calculate centre and size of mesh, wrap it all in a Dimensions object
Diffstat (limited to 'gfx/models/mesh.cpp')
-rw-r--r--gfx/models/mesh.cpp27
1 files changed, 25 insertions, 2 deletions
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<RelativePosition3D, RelativePosition3D> minmax) :
- m_numIndices {m_numIndices}, mode {mode}, min {minmax.first}, max {minmax.second}
+MeshBase::MeshBase(GLsizei m_numIndices, GLenum mode, const std::vector<RelativePosition3D> & positions) :
+ m_numIndices {m_numIndices}, mode {mode}, dimensions {positions}
{
}
+MeshBase::Dimensions::Dimensions(const std::span<const RelativePosition3D> positions) :
+ Dimensions {positions, {extents(positions, 0), extents(positions, 1), extents(positions, 2)}}
+{
+}
+
+MeshBase::Dimensions::Dimensions(
+ const std::span<const RelativePosition3D> positions, const std::array<Extents1D, 3> & 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<const RelativePosition3D> positions, glm::length_t D)
+{
+ return std::ranges::minmax(positions | std::views::transform([D](const auto & v) {
+ return v[D];
+ }));
+}
+
void
MeshBase::Draw() const
{