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
31 inline AABB& merge(AABB const& a) noexcept {
32 *this = AABB{ll::math::min(a.min, min), ll::math::max(a.max, max)};
33 return *this;
34 }
35
36 inline AABB& merge(Vec3 const& a) noexcept {
37 *this = AABB{ll::math::min(a, min), ll::math::max(a, max)};
38 return *this;
39 }
40
41 template <typename T, size_t N>
42 [[nodiscard]] constexpr T& get() noexcept {
43 if constexpr (N == 0) {
44 return x;
45 } else if constexpr (N == 1) {
46 return y;
47 } else {
48 static_assert(ll::traits::always_false<T>);
49 }
50 }
51
52 template <typename T, size_t N>
53 [[nodiscard]] constexpr T const& get() const noexcept {
54 if constexpr (N == 0) {
55 return x;
56 } else if constexpr (N == 1) {
57 return y;
58 } else {
59 static_assert(ll::traits::always_false<T>);
60 }
61 }
62
63 [[nodiscard]] constexpr bool contains(Vec3 const& a) const noexcept { return a.ge(min).all() && a.le(max).all(); }
64
65 [[nodiscard]] constexpr bool contains(AABB const& a) const noexcept {
66 return a.min.ge(min).all() && a.max.le(max).all();
67 }
68
69 LLAPI explicit operator BoundingBox() const;
70
71 LLAPI bool intersects(::AABB const& c) const;
72
73 [[nodiscard]] constexpr Vec3 center() const noexcept { return (min + max) * 0.5f; }
74
75 [[nodiscard]] constexpr AABB& shrink(float f) noexcept {
76 min += f;
77 max -= f;
78 return *this;
79 }
80
81 [[nodiscard]] constexpr AABB& shrink(Vec3 const& offset) noexcept {
82 min += offset;
83 max -= offset;
84
85 Vec3::forEachComponent([&]<typename axis_type, size_t iter> {
86 auto& newMin = min.get<axis_type, iter>();
87 auto& newMax = max.get<axis_type, iter>();
88
89 if (newMin > newMax) {
90 auto mid = (newMin + newMax) * 0.5f;
91 newMin = mid;
92 newMax = mid;
93 }
94 });
95
96 return *this;
97 }
98
99public:
100 // member functions
101 // NOLINTBEGIN
102#ifdef LL_PLAT_C
103 MCAPI float _clipAxisCollide(::AABB const& c, float vAxis, int axisIndex, bool oneway) const;
104#endif
105
106 MCAPI ::AABBHitResult clip(::Vec3 const& a, ::Vec3 const& b) const;
107
108 MCAPI ::AABB cloneAndFloor(float offsetMin, float offsetMax) const;
109
110 MCAPI ::AABB cloneAndFloorMinAndCeilingMax() const;
111
112 MCAPI ::AABB cloneAndGrow(::Vec3 const& distance) const;
113
114 MCAPI ::AABB cloneAndShrink(::Vec3 const& offset) const;
115
116 MCAPI ::AABB cloneAndTransformByMatrix(::Matrix const& transform) const;
117
118 MCAPI float distanceTo(::Vec3 const& pos) const;
119
120 MCAPI float distanceToSqr(::AABB const& aabb) const;
121
122#ifdef LL_PLAT_C
123 MCAPI ::std::array<::Vec3, 8> getCorners() const;
124#endif
125
126 MCAPI bool intersectSegment(
127 ::Vec3 const& segmentBegin,
128 ::Vec3 const& segmentEnd,
129 ::Vec3& intersectPoint,
130 ::Vec3& intersectNorm
131 ) const;
132
133 MCAPI bool intersects(::Vec3 const& segmentBegin, ::Vec3 const& segmentEnd) const;
134 // NOLINTEND
135
136public:
137 // static functions
138 // NOLINTBEGIN
139 MCAPI static ::ClipCollideResult
140 clipCollide(::AABB const& stationary, ::AABB const& moving, ::Vec3 const& velocity);
141 // NOLINTEND
142
143public:
144 // static variables
145 // NOLINTBEGIN
146 MCAPI static ::AABB const& BLOCK_SHAPE();
147
148 MCAPI static ::AABB const& BOX_AT_ORIGIN_WITH_NO_VOLUME();
149 // NOLINTEND
150};
Definition BoundingBox.h:13
Definition Matrix.h:10
Definition Vec3.h:10
Definition AABBHitResult.h:8
Definition ClipCollideResult.h:8
Definition CommutativeGroup.h:17