LeviLamina
Loading...
Searching...
No Matches
AABB.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4#include "mc/world/phys/AABBHitResult.h"
5
6// auto generated inclusion list
7#include "mc/deps/core/math/Vec3.h"
8
9// auto generated forward declare list
10// clang-format off
11class Matrix;
12struct AABBHitResult;
14// clang-format on
15
16class BoundingBox;
17
18class AABB : public ll::math::CommutativeGroup<AABB, Vec3, Vec3> {
19public:
20 union {
21 Vec3 min, x, r, s;
22 };
23 union {
24 Vec3 max, y, g, t, z, b, p;
25 };
26
27 [[nodiscard]] constexpr AABB() noexcept : min(0), max(0) {}
28 [[nodiscard]] constexpr AABB(class AABB const& k) noexcept : min(k.min), max(k.max) {}
29 [[nodiscard]] constexpr AABB(class Vec3 const& min, class Vec3 const& max) noexcept : min(min), max(max) {}
30 constexpr AABB& operator=(const AABB&) noexcept = default;
31
32 inline AABB& merge(AABB const& a) noexcept {
33 *this = AABB{ll::math::min(a.min, min), ll::math::max(a.max, max)};
34 return *this;
35 }
36
37 inline AABB& merge(Vec3 const& a) noexcept {
38 *this = AABB{ll::math::min(a, min), ll::math::max(a, max)};
39 return *this;
40 }
41
42 template <typename T, size_t N>
43 [[nodiscard]] constexpr T& get() noexcept {
44 if constexpr (N == 0) {
45 return x;
46 } else if constexpr (N == 1) {
47 return y;
48 } else {
49 static_assert(ll::traits::always_false<T>);
50 }
51 }
52
53 template <typename T, size_t N>
54 [[nodiscard]] constexpr T const& get() const noexcept {
55 if constexpr (N == 0) {
56 return x;
57 } else if constexpr (N == 1) {
58 return y;
59 } else {
60 static_assert(ll::traits::always_false<T>);
61 }
62 }
63
64 [[nodiscard]] constexpr bool contains(Vec3 const& a) const noexcept { return a.ge(min).all() && a.le(max).all(); }
65
66 [[nodiscard]] constexpr bool contains(AABB const& a) const noexcept {
67 return a.min.ge(min).all() && a.max.le(max).all();
68 }
69
70 LLAPI explicit operator BoundingBox() const;
71
72 LLAPI bool intersects(::AABB const& c) const;
73
74 [[nodiscard]] constexpr Vec3 center() const noexcept { return (min + max) * 0.5f; }
75
76 [[nodiscard]] constexpr AABB& shrink(float f) noexcept {
77 min += f;
78 max -= f;
79 return *this;
80 }
81
82 [[nodiscard]] constexpr AABB& shrink(Vec3 const& offset) noexcept {
83 min += offset;
84 max -= offset;
85
86 Vec3::forEachComponent([&]<typename axis_type, size_t iter> {
87 auto& newMin = min.get<axis_type, iter>();
88 auto& newMax = max.get<axis_type, iter>();
89
90 if (newMin > newMax) {
91 auto mid = (newMin + newMax) * 0.5f;
92 newMin = mid;
93 newMax = mid;
94 }
95 });
96
97 return *this;
98 }
99
100public:
101 // member functions
102 // NOLINTBEGIN
103 MCAPI ::AABBHitResult clip(::Vec3 const& a, ::Vec3 const& b) const;
104
105 MCAPI ::AABB cloneAndFloor(float offsetMin, float offsetMax) const;
106
107 MCAPI ::AABB cloneAndGrow(::Vec3 const& distance) const;
108
109 MCAPI ::AABB cloneAndGrow(float radius) const;
110
111 MCAPI ::AABB cloneAndShrink(::Vec3 const& offset) const;
112
113 MCAPI ::AABB cloneAndTransformByMatrix(::Matrix const& transform) const;
114
115 MCAPI ::AABB cloneAndTranslate(::Vec3 const& offset) const;
116
117 MCAPI float distanceTo(::AABB const& aabb) const;
118
119 MCAPI bool intersectSegment(
120 ::Vec3 const& segmentBegin,
121 ::Vec3 const& segmentEnd,
122 ::Vec3& intersectPoint,
123 ::Vec3& intersectNorm
124 ) const;
125
126 MCAPI bool intersects(::Vec3 const& segmentBegin, ::Vec3 const& segmentEnd) const;
127
128#ifdef LL_PLAT_C
129 MCAPI bool operator!=(::AABB const& rhs) const;
130#endif
131 // NOLINTEND
132
133public:
134 // static functions
135 // NOLINTBEGIN
136 MCAPI static ::AABB aroundRadius(::Vec3 const& point, float radius);
137
138 MCAPI static ::ClipCollideResult
139 clipCollide(::AABB const& stationary, ::AABB const& moving, ::Vec3 const& velocity);
140 // NOLINTEND
141
142public:
143 // static variables
144 // NOLINTBEGIN
145 MCAPI static ::AABB const& BLOCK_SHAPE();
146
147 MCAPI static ::AABB const& BOX_AT_ORIGIN_WITH_NO_VOLUME();
148 // NOLINTEND
149
150public:
151 // constructor thunks
152 // NOLINTBEGIN
153 MCAPI void* $ctor(::Vec3 const& min, ::Vec3 const& max);
154 // NOLINTEND
155};
Definition BoundingBox.h:13
Definition Matrix.h:10
Definition Vec3.h:10
Definition AABBHitResult.h:8
Definition ClipCollideResult.h:8
Definition CommutativeGroup.h:17