LeviLamina
Loading...
Searching...
No Matches
AABB.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4#include "mc/deps/core/math/Vec3.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
81public:
82 // member functions
83 // NOLINTBEGIN
84 MCAPI ::AABBHitResult clip(::Vec3 const& a, ::Vec3 const& b) const;
85
86 MCAPI ::AABB cloneAndExpandAlongDirection(::Vec3 const& direction) const;
87
88 MCAPI ::AABB cloneAndFloor(float offsetMin, float offsetMax) const;
89
90 MCAPI ::AABB cloneAndFloorMinAndCeilingMax() const;
91
92 MCAPI ::AABB cloneAndGrow(::Vec3 const& distance) const;
93
94 MCAPI ::AABB cloneAndGrow(float radius) const;
95
96 MCAPI ::AABB cloneAndShrink(::Vec3 const& offset) const;
97
98 MCAPI ::AABB cloneAndTransformByMatrix(::Matrix const& transform) const;
99
100 MCAPI float distanceTo(::Vec3 const& pos) const;
101
102 MCAPI float distanceToSqr(::AABB const& aabb) const;
103
104 MCAPI bool intersectSegment(
105 ::Vec3 const& segmentBegin,
106 ::Vec3 const& segmentEnd,
107 ::Vec3& intersectPoint,
108 ::Vec3& intersectNorm
109 ) const;
110
111 MCAPI bool intersects(::Vec3 const& segmentBegin, ::Vec3 const& segmentEnd) const;
112
113 MCAPI bool intersectsInner(::AABB const& c) const;
114 // NOLINTEND
115
116public:
117 // static functions
118 // NOLINTBEGIN
119 MCAPI static ::ClipCollideResult
120 clipCollide(::AABB const& stationary, ::AABB const& moving, ::Vec3 const& velocity);
121 // NOLINTEND
122
123public:
124 // static variables
125 // NOLINTBEGIN
126 MCAPI static ::AABB const& BLOCK_SHAPE();
127
128 MCAPI static ::AABB const& BOX_AT_ORIGIN_WITH_NO_VOLUME();
129 // NOLINTEND
130};
Definition AABB.h:18
Definition BoundingBox.h:13
Definition Matrix.h:5
Definition Vec3.h:10
Definition AABBHitResult.h:5
Definition ClipCollideResult.h:5
Definition CommutativeGroup.h:17