Move AABB class and base it on top of Range

This commit is contained in:
2021-02-21 02:10:11 +01:00
parent 5dd56847d8
commit 5cc0ce9433
4 changed files with 134 additions and 113 deletions

View File

@@ -0,0 +1,96 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "Math.hpp"
#include "Range.hpp"
namespace openVulkanoCpp::Math
{
/**
* \brief A class that represents an axis aligned bounding box
*/
class AABB final : Range<Math::Vector3f>
{
public:
AABB() : Range(Math::Vector3f(INFINITY), Math::Vector3f(-INFINITY)) {}
AABB(const Math::Vector3f& min, const Math::Vector3f& max) : Range(min, max) {}
/**
* \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;
}
void Init(const Math::Vector3f& min, const Math::Vector3f& max)
{
this->min = min;
this->max = max;
}
/**
* \brief Initiates the AABB from some other AABB
* \param other The other AABB that should be copied
*/
void Init(const AABB& other)
{
min = other.GetMin();
max = other.GetMax();
}
void Grow(const Math::Vector3f& point)
{
min = Math::Utils::min(min, point);
max = Math::Utils::max(max, point);
}
void Grow(const AABB& otherAABB)
{
min = Math::Utils::min(min, otherAABB.GetMin());
max = Math::Utils::max(max, otherAABB.GetMax());
}
void Grow(const AABB& otherAABB, Math::Matrix4f transformation)
{
//TODO
}
[[nodiscard]] Math::Vector3f GetDiagonal() const
{
return GetSize();
}
[[nodiscard]] Math::Vector3f GetCenter() const
{
return min + (GetDiagonal() * 0.5f);
}
/**
* \brief Checks if the AABB overlaps with an other AABB
* \param other The other AABB that should be checked
* \return true if the AABB overlaps with the other, false if not
*/
[[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);
}
/**
* \brief Resets the AABB to min=Inf, max=-Inf, same as Init()
*/
void Reset()
{
min = Math::Vector3f(INFINITY);
max = Math::Vector3f(-INFINITY);
}
};
}