Refactor AABB class
This commit is contained in:
@@ -7,7 +7,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Math/Math.hpp"
|
#include "Math/Math.hpp"
|
||||||
#include "Base/IInitable.hpp"
|
#ifdef _MSC_VER
|
||||||
|
#undef min
|
||||||
|
#undef max
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace openVulkanoCpp
|
namespace openVulkanoCpp
|
||||||
{
|
{
|
||||||
@@ -16,30 +19,27 @@ namespace openVulkanoCpp
|
|||||||
/**
|
/**
|
||||||
* \brief A class that represents an axis aligned bounding box
|
* \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:
|
public:
|
||||||
AABB() : min(INFINITY), max(-INFINITY) {}
|
AABB() : m_min(INFINITY), m_max(-INFINITY) {}
|
||||||
~AABB() = default;
|
~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)
|
* \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
|
* \param point The point that should be used as min and max of the AABB
|
||||||
*/
|
*/
|
||||||
void Init(const Math::Vector3f& point)
|
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)
|
void Init(const AABB& other)
|
||||||
{
|
{
|
||||||
min = other.GetMin();
|
m_min = other.GetMin();
|
||||||
max = other.GetMax();
|
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)
|
void Grow(const Math::Vector3f& point)
|
||||||
{
|
{
|
||||||
min = Math::Utils::min(min, point);
|
m_min = Math::Utils::min(m_min, point);
|
||||||
max = Math::Utils::max(max, point);
|
m_max = Math::Utils::max(m_max, point);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grow(const AABB& otherAABB)
|
void Grow(const AABB& otherAABB)
|
||||||
{
|
{
|
||||||
min = Math::Utils::min(min, otherAABB.GetMin());
|
m_min = Math::Utils::min(m_min, otherAABB.GetMin());
|
||||||
max = Math::Utils::max(max, otherAABB.GetMax());
|
m_max = Math::Utils::max(m_max, otherAABB.GetMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grow(const AABB& otherAABB, Math::Matrix4f transformation)
|
void Grow(const AABB& otherAABB, Math::Matrix4f transformation)
|
||||||
@@ -75,12 +79,12 @@ namespace openVulkanoCpp
|
|||||||
|
|
||||||
[[nodiscard]] Math::Vector3f GetDiagonal() const
|
[[nodiscard]] Math::Vector3f GetDiagonal() const
|
||||||
{
|
{
|
||||||
return max - min;
|
return m_max - m_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] Math::Vector3f GetCenter() const
|
[[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
|
[[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()
|
void Reset()
|
||||||
{
|
{
|
||||||
Init();
|
m_min = Math::Vector3f(INFINITY);
|
||||||
|
m_max = Math::Vector3f(-INFINITY);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace openVulkanoCpp::Scene
|
|||||||
void Geometry::Init(aiMesh* mesh)
|
void Geometry::Init(aiMesh* mesh)
|
||||||
{
|
{
|
||||||
#ifdef ASSIMP_AVAILABLE
|
#ifdef ASSIMP_AVAILABLE
|
||||||
aabb.Init();
|
aabb.Reset();
|
||||||
Init(mesh->mNumVertices, mesh->mNumFaces * 3); // Reserve the space for the data
|
Init(mesh->mNumVertices, mesh->mNumFaces * 3); // Reserve the space for the data
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
|
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/IInitable.hpp"
|
||||||
#include "Base/ICloseable.hpp"
|
#include "Base/ICloseable.hpp"
|
||||||
#include "Math/Math.hpp"
|
#include "Math/Math.hpp"
|
||||||
#include "Drawable.hpp"
|
#include "Drawable.hpp"
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ namespace openVulkanoCpp
|
|||||||
{
|
{
|
||||||
namespace Scene
|
namespace Scene
|
||||||
{
|
{
|
||||||
struct Scene : virtual public IInitable, virtual public ICloseable
|
class Scene : virtual public IInitable, virtual public ICloseable
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
Node* root;
|
Node* root;
|
||||||
std::vector<Drawable*> shapeList;
|
std::vector<Drawable*> shapeList;
|
||||||
Shader* shader;
|
Shader* shader;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "DataFormat.hpp"
|
#include "DataFormat.hpp"
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace openVulkanoCpp
|
namespace openVulkanoCpp
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user