Add operator
This commit is contained in:
@@ -14,12 +14,12 @@ namespace OpenVulkano::Math
|
|||||||
/**
|
/**
|
||||||
* \brief A class that represents an axis aligned bounding box
|
* \brief A class that represents an axis aligned bounding box
|
||||||
*/
|
*/
|
||||||
class AABB final : public Range<Math::Vector3f>
|
class AABB final : public Range<Vector3f>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AABB() : Range(Math::Vector3f(INFINITY), Math::Vector3f(-INFINITY)) {}
|
AABB() : Range(Vector3f(INFINITY), Vector3f(-INFINITY)) {}
|
||||||
|
|
||||||
AABB(const Math::Vector3f& min, const Math::Vector3f& max) : Range(min, max) {}
|
AABB(const Vector3f& min, const Vector3f& max) : Range(min, max) {}
|
||||||
|
|
||||||
AABB(const Vector3f& point) : Range(point, point)
|
AABB(const Vector3f& point) : Range(point, point)
|
||||||
{}
|
{}
|
||||||
@@ -31,18 +31,18 @@ namespace OpenVulkano::Math
|
|||||||
* \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 Vector3f& point)
|
||||||
{
|
{
|
||||||
min = max = point;
|
min = max = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init(const Math::Vector3f& min, const Math::Vector3f& max)
|
void Init(const Vector3f& min, const Vector3f& max)
|
||||||
{
|
{
|
||||||
this->min = min;
|
this->min = min;
|
||||||
this->max = max;
|
this->max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init(const Math::Vector3f& point, float radius)
|
void Init(const Vector3f& point, float radius)
|
||||||
{
|
{
|
||||||
min = point - radius;
|
min = point - radius;
|
||||||
max = point + radius;
|
max = point + radius;
|
||||||
@@ -58,7 +58,7 @@ namespace OpenVulkano::Math
|
|||||||
max = other.GetMax();
|
max = other.GetMax();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grow(const Math::Vector3f& point)
|
void Grow(const Vector3f& point)
|
||||||
{
|
{
|
||||||
min = Math::Utils::min(min, point);
|
min = Math::Utils::min(min, point);
|
||||||
max = Math::Utils::max(max, point);
|
max = Math::Utils::max(max, point);
|
||||||
@@ -75,12 +75,12 @@ namespace OpenVulkano::Math
|
|||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] Math::Vector3f GetDiagonal() const
|
[[nodiscard]] Vector3f GetDiagonal() const
|
||||||
{
|
{
|
||||||
return GetSize();
|
return GetSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] Math::Vector3f GetCenter() const
|
[[nodiscard]] Vector3f GetCenter() const
|
||||||
{
|
{
|
||||||
return min + (GetDiagonal() * 0.5f);
|
return min + (GetDiagonal() * 0.5f);
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ namespace OpenVulkano::Math
|
|||||||
other.max.y < min.y || other.min.z > max.z || other.max.z < min.z);
|
other.max.y < min.y || other.min.z > max.z || other.max.z < min.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool InBounds(const Math::Vector3f& position) const
|
[[nodiscard]] bool InBounds(const Vector3f& position) const
|
||||||
{
|
{
|
||||||
return Math::Utils::all(Math::Utils::lessThanEqual(min, position)) && Math::Utils::all(Math::Utils::lessThanEqual(position, max));
|
return Math::Utils::all(Math::Utils::lessThanEqual(min, position)) && Math::Utils::all(Math::Utils::lessThanEqual(position, max));
|
||||||
}
|
}
|
||||||
@@ -116,8 +116,10 @@ namespace OpenVulkano::Math
|
|||||||
*/
|
*/
|
||||||
void Reset()
|
void Reset()
|
||||||
{
|
{
|
||||||
min = Math::Vector3f(INFINITY);
|
min = Vector3f(INFINITY);
|
||||||
max = Math::Vector3f(-INFINITY);
|
max = Vector3f(-INFINITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AABB& operator +=(const AABB& other) { Grow(other); return *this; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user