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 AABB(::Vec3 const& min, float side);
104
105 MCAPI AABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
106
107 MCAPI ::Vec3 axisInside(::AABB const& other, ::Vec3 axis) const;
108
109 MCAPI ::AABBHitResult clip(::Vec3 const& a, ::Vec3 const& b) const;
110
111 MCAPI ::Vec3 clipCollide(::AABB const& c, ::Vec3 const& velocity, bool oneWay, float* penetration) const;
112
113#ifdef LL_PLAT_C
114 MCAPI float clipXCollide(::AABB const& c, float ya, bool oneway) const;
115
116 MCAPI float clipYCollide(::AABB const& c, float ya, bool oneway) const;
117
118 MCAPI float clipZCollide(::AABB const& c, float ya, bool oneway) const;
119#endif
120
121 MCAPI ::AABB cloneAndExpandAlongDirection(::Vec3 const& direction) const;
122
123 MCAPI ::AABB cloneAndFloor(float offsetMin, float offsetMax) const;
124
125 MCAPI ::AABB cloneAndFloorMinAndCeilingMax() const;
126
127 MCAPI ::AABB cloneAndGrow(::Vec3 const& distance) const;
128
129 MCAPI ::AABB cloneAndGrow(float radius) const;
130
131 MCAPI ::AABB cloneAndShrink(::Vec3 const& offset) const;
132
133 MCAPI ::AABB cloneAndTransformByMatrix(::Matrix const& transform) const;
134
135 MCAPI ::AABB cloneAndTranslate(::Vec3 const& offset) const;
136
137 MCAPI float distanceTo(::AABB const& aabb) const;
138
139 MCAPI float distanceTo(::Vec3 const& pos) const;
140
141 MCAPI float distanceToSqr(::Vec3 const& pos) const;
142
143 MCAPI ::Vec3 getBottomCenter() const;
144
145 MCAPI ::Vec3 getBounds() const;
146
147 MCAPI ::Vec3 getCenter() const;
148
149#ifdef LL_PLAT_C
150 MCAPI ::std::array<::Vec3, 8> getCorners() const;
151#endif
152
153 MCAPI float getSize() const;
154
155 MCAPI ::Vec3 getTopCenter() const;
156
157 MCAPI float getVolume() const;
158
159 MCAPI bool intersectSegment(
160 ::Vec3 const& segmentBegin,
161 ::Vec3 const& segmentEnd,
162 ::Vec3& intersectPoint,
163 ::Vec3& intersectNorm
164 ) const;
165
166 MCAPI bool intersects(::Vec3 const& segmentBegin, ::Vec3 const& segmentEnd) const;
167
168 MCAPI bool intersectsInner(::AABB const& c) const;
169
170 MCAPI bool isNan() const;
171
172 MCAPI bool isValid() const;
173
174 MCAPI bool operator!=(::AABB const& rhs) const;
175
176 MCAPI bool operator==(::AABB const& rhs) const;
177
178 MCAPI ::AABB& set(::AABB const& b);
179
180 MCFOLD ::AABB& set(::Vec3 const& min, ::Vec3 const& max);
181
182 MCFOLD ::AABB& set(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
183
184#ifdef LL_PLAT_C
185 MCAPI ::AABB& translateCenterTo(::Vec3 const& center);
186#endif
187 // NOLINTEND
188
189public:
190 // static functions
191 // NOLINTBEGIN
192 MCAPI static ::AABB aroundRadius(::Vec3 const& point, float radius);
193
194 MCAPI static ::ClipCollideResult
195 clipCollide(::AABB const& stationary, ::AABB const& moving, ::Vec3 const& velocity);
196 // NOLINTEND
197
198public:
199 // static variables
200 // NOLINTBEGIN
201 MCAPI static ::AABB const& BLOCK_SHAPE();
202
203 MCAPI static ::AABB const& BOX_AT_ORIGIN_WITH_NO_VOLUME();
204 // NOLINTEND
205
206public:
207 // constructor thunks
208 // NOLINTBEGIN
209 MCFOLD void* $ctor(::Vec3 const& min, ::Vec3 const& max);
210
211 MCAPI void* $ctor(::Vec3 const& min, float side);
212
213 MCFOLD void* $ctor(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
214 // NOLINTEND
215};
Definition BoundingBox.h:13
Definition Matrix.h:10
Definition Vec3.h:10
Definition AABBHitResult.h:8
Definition ClipCollideResult.h:8
Definition CommutativeGroup.h:17