mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-20 07:23:27 +00:00
added new methods
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
|
||||
namespace omath::primitives
|
||||
{
|
||||
enum class UpAxis { X, Y, Z };
|
||||
|
||||
template<class Type>
|
||||
struct Aabb final
|
||||
{
|
||||
@@ -24,6 +26,37 @@ namespace omath::primitives
|
||||
{
|
||||
return (max - min) / static_cast<Type>(2);
|
||||
}
|
||||
|
||||
template<UpAxis Up = UpAxis::Y>
|
||||
[[nodiscard]]
|
||||
constexpr Vector3<Type> top() const noexcept
|
||||
{
|
||||
const auto aabb_center = center();
|
||||
if constexpr (Up == UpAxis::Z)
|
||||
return {aabb_center.x, aabb_center.y, max.z};
|
||||
else if constexpr (Up == UpAxis::X)
|
||||
return {max.x, aabb_center.y, aabb_center.z};
|
||||
else if constexpr (Up == UpAxis::Y)
|
||||
return {aabb_center.x, max.y, aabb_center.z};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
template<UpAxis Up = UpAxis::Y>
|
||||
[[nodiscard]]
|
||||
constexpr Vector3<Type> bottom() const noexcept
|
||||
{
|
||||
const auto aabb_center = center();
|
||||
if constexpr (Up == UpAxis::Z)
|
||||
return {aabb_center.x, aabb_center.y, min.z};
|
||||
else if constexpr (Up == UpAxis::X)
|
||||
return {min.x, aabb_center.y, aabb_center.z};
|
||||
else if constexpr (Up == UpAxis::Y)
|
||||
return {aabb_center.x, min.y, aabb_center.z};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool is_collide(const Aabb& other) const noexcept
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user