Math/Frustum: Add ComputeCorners and GetAABB
This commit is contained in:
parent
d4b2cede15
commit
532b1b2c4d
|
|
@ -37,6 +37,7 @@ namespace Nz
|
|||
constexpr bool ApproxEqual(const Frustum& frustum, T maxDifference = std::numeric_limits<T>::epsilon()) const;
|
||||
|
||||
constexpr Vector3<T> ComputeCorner(BoxCorner corner) const;
|
||||
constexpr EnumArray<BoxCorner, Vector3<T>> ComputeCorners() const;
|
||||
|
||||
constexpr bool Contains(const BoundingVolume<T>& volume) const;
|
||||
constexpr bool Contains(const Box<T>& box) const;
|
||||
|
|
@ -45,6 +46,7 @@ namespace Nz
|
|||
constexpr bool Contains(const Vector3<T>& point) const;
|
||||
constexpr bool Contains(const Vector3<T>* points, std::size_t pointCount) const;
|
||||
|
||||
constexpr const Box<T>& GetAABB() const;
|
||||
constexpr const Plane<T>& GetPlane(FrustumPlane plane) const;
|
||||
constexpr const EnumArray<FrustumPlane, Plane<T>>& GetPlanes() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,21 @@ namespace Nz
|
|||
return Vector3<T>();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr EnumArray<BoxCorner, Vector3<T>> Frustum<T>::ComputeCorners() const
|
||||
{
|
||||
return {
|
||||
ComputeCorner(BoxCorner::FarLeftBottom),
|
||||
ComputeCorner(BoxCorner::FarLeftTop),
|
||||
ComputeCorner(BoxCorner::FarRightBottom),
|
||||
ComputeCorner(BoxCorner::FarRightTop),
|
||||
ComputeCorner(BoxCorner::NearLeftBottom),
|
||||
ComputeCorner(BoxCorner::NearLeftTop),
|
||||
ComputeCorner(BoxCorner::NearRightBottom),
|
||||
ComputeCorner(BoxCorner::NearRightTop)
|
||||
};
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not a bounding volume is contained in the frustum
|
||||
* \return true if the bounding volume is entirely in the frustum
|
||||
|
|
@ -229,6 +244,22 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr const Box<T>& Frustum<T>::GetAABB() const
|
||||
{
|
||||
EnumArray<BoxCorner, Vector3<T>> corners = ComputeCorners();
|
||||
|
||||
Vector3f max = corners.front();
|
||||
Vector3f min = corners.front();
|
||||
for (std::size_t i = 1; i < corners.size(); ++i)
|
||||
{
|
||||
max.Maximize(corners[static_cast<BoxCorner>(i)]);
|
||||
min.Minimize(corners[static_cast<BoxCorner>(i)]);
|
||||
}
|
||||
|
||||
return Box<T>::FromExtends(min, max);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the Plane for the face
|
||||
* \return The face of the frustum according to enum FrustumPlane
|
||||
|
|
|
|||
Loading…
Reference in New Issue