From e871a989b4b55b5eddc7015fc8a5218fe9dd7506 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Mon, 8 Feb 2021 00:14:23 +0100 Subject: [PATCH] Refactor AABB class --- openVulkanoCpp/Scene/AABB.hpp | 58 ++++++++++--------- openVulkanoCpp/Scene/Geometry.cpp | 2 +- openVulkanoCpp/Scene/Node.hpp | 1 + openVulkanoCpp/Scene/Scene.hpp | 3 +- .../Scene/VertexInputDescription.hpp | 2 + 5 files changed, 38 insertions(+), 28 deletions(-) diff --git a/openVulkanoCpp/Scene/AABB.hpp b/openVulkanoCpp/Scene/AABB.hpp index 20966ea..ccec0e9 100644 --- a/openVulkanoCpp/Scene/AABB.hpp +++ b/openVulkanoCpp/Scene/AABB.hpp @@ -7,7 +7,10 @@ #pragma once #include "Math/Math.hpp" -#include "Base/IInitable.hpp" +#ifdef _MSC_VER +#undef min +#undef max +#endif namespace openVulkanoCpp { @@ -16,30 +19,27 @@ namespace openVulkanoCpp /** * \brief A class that represents an axis aligned bounding box */ - class AABB final : public virtual IInitable + class AABB final { - Math::Vector3f min, max; + Math::Vector3f m_min, m_max; public: - AABB() : min(INFINITY), max(-INFINITY) {} + AABB() : m_min(INFINITY), m_max(-INFINITY) {} ~AABB() = default; - /** - * \brief Initiates the AABB to min=Inf, max=-Inf - */ - void Init() override - { - min = Math::Vector3f(INFINITY); - max = Math::Vector3f(-INFINITY); - } - /** * \brief Initiates the AABB to a single point (min=max=point) * \param point The point that should be used as min and max of the AABB */ void Init(const Math::Vector3f& point) { - min = max = point; + m_min = m_max = point; + } + + void Init(const Math::Vector3f& min, const Math::Vector3f& max) + { + m_min = min; + m_max = max; } /** @@ -48,24 +48,28 @@ namespace openVulkanoCpp */ void Init(const AABB& other) { - min = other.GetMin(); - max = other.GetMax(); + m_min = other.GetMin(); + m_max = other.GetMax(); } - [[nodiscard]] inline const Math::Vector3f& GetMin() const { return min; } + [[nodiscard]] inline const Math::Vector3f& GetMin() const { return m_min; } - [[nodiscard]] inline const Math::Vector3f& GetMax() const { return max; } + [[nodiscard]] inline const Math::Vector3f& GetMax() const { return m_max; } + + [[nodiscard]] inline Math::Vector3f& GetMin() { return m_min; } + + [[nodiscard]] inline Math::Vector3f& GetMax() { return m_max; } void Grow(const Math::Vector3f& point) { - min = Math::Utils::min(min, point); - max = Math::Utils::max(max, point); + m_min = Math::Utils::min(m_min, point); + m_max = Math::Utils::max(m_max, point); } void Grow(const AABB& otherAABB) { - min = Math::Utils::min(min, otherAABB.GetMin()); - max = Math::Utils::max(max, otherAABB.GetMax()); + m_min = Math::Utils::min(m_min, otherAABB.GetMin()); + m_max = Math::Utils::max(m_max, otherAABB.GetMax()); } void Grow(const AABB& otherAABB, Math::Matrix4f transformation) @@ -75,12 +79,12 @@ namespace openVulkanoCpp [[nodiscard]] Math::Vector3f GetDiagonal() const { - return max - min; + return m_max - m_min; } [[nodiscard]] Math::Vector3f GetCenter() const { - return min + (GetDiagonal() * 0.5f); + return m_min + (GetDiagonal() * 0.5f); } /** @@ -90,7 +94,8 @@ namespace openVulkanoCpp */ [[nodiscard]] bool IsOverlapping(const AABB& other) const { - return !(other.min.x > max.x || other.max.x < min.x || other.min.y > max.y || other.max.y < min.y || other.min.z > max.z || other.max.z < min.z); + return !(other.m_min.x > m_max.x || other.m_max.x < m_min.x || other.m_min.y > m_max.y || + other.m_max.y < m_min.y || other.m_min.z > m_max.z || other.m_max.z < m_min.z); } /** @@ -98,7 +103,8 @@ namespace openVulkanoCpp */ void Reset() { - Init(); + m_min = Math::Vector3f(INFINITY); + m_max = Math::Vector3f(-INFINITY); } }; } diff --git a/openVulkanoCpp/Scene/Geometry.cpp b/openVulkanoCpp/Scene/Geometry.cpp index df35eb6..67c122f 100644 --- a/openVulkanoCpp/Scene/Geometry.cpp +++ b/openVulkanoCpp/Scene/Geometry.cpp @@ -53,7 +53,7 @@ namespace openVulkanoCpp::Scene void Geometry::Init(aiMesh* mesh) { #ifdef ASSIMP_AVAILABLE - aabb.Init(); + aabb.Reset(); Init(mesh->mNumVertices, mesh->mNumFaces * 3); // Reserve the space for the data for (unsigned int i = 0; i < mesh->mNumVertices; i++) { diff --git a/openVulkanoCpp/Scene/Node.hpp b/openVulkanoCpp/Scene/Node.hpp index 8f82e84..18246d1 100644 --- a/openVulkanoCpp/Scene/Node.hpp +++ b/openVulkanoCpp/Scene/Node.hpp @@ -6,6 +6,7 @@ #pragma once +#include "Base/IInitable.hpp" #include "Base/ICloseable.hpp" #include "Math/Math.hpp" #include "Drawable.hpp" diff --git a/openVulkanoCpp/Scene/Scene.hpp b/openVulkanoCpp/Scene/Scene.hpp index db0dd5b..5863871 100644 --- a/openVulkanoCpp/Scene/Scene.hpp +++ b/openVulkanoCpp/Scene/Scene.hpp @@ -14,8 +14,9 @@ namespace openVulkanoCpp { namespace Scene { - struct Scene : virtual public IInitable, virtual public ICloseable + class Scene : virtual public IInitable, virtual public ICloseable { + public: Node* root; std::vector shapeList; Shader* shader; diff --git a/openVulkanoCpp/Scene/VertexInputDescription.hpp b/openVulkanoCpp/Scene/VertexInputDescription.hpp index f04a58c..74111c2 100644 --- a/openVulkanoCpp/Scene/VertexInputDescription.hpp +++ b/openVulkanoCpp/Scene/VertexInputDescription.hpp @@ -7,6 +7,8 @@ #pragma once #include "DataFormat.hpp" +#include +#include namespace openVulkanoCpp {