Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
BoundingBox.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_CORE_MATH_BOUNDINGVOLUMES_BOUNDINGBOX_H_
34#define DVD_CORE_MATH_BOUNDINGVOLUMES_BOUNDINGBOX_H_
35
37
38namespace Divide {
39
40namespace Attorney {
41 class BoundingBoxEditor;
42}
43
44class OBB;
45class PropertyWindow;
46class BoundingSphere;
49
50 public:
51 BoundingBox() noexcept;
52 explicit BoundingBox(const OBB& obb) noexcept;
53 explicit BoundingBox(const BoundingSphere& bSphere) noexcept;
54 explicit BoundingBox(vec3<F32> min, vec3<F32> max) noexcept;
55 explicit BoundingBox(const vector<vec3<F32>>& points) noexcept;
56 explicit BoundingBox(const std::array<vec3<F32>, 8>& points) noexcept;
57 explicit BoundingBox(F32 minX, F32 minY, F32 minZ, F32 maxX, F32 maxY, F32 maxZ) noexcept;
58
59 BoundingBox(const BoundingBox& b) noexcept;
60 BoundingBox& operator=(const BoundingBox& b) noexcept;
61
62 [[nodiscard]] bool containsPoint(const vec3<F32>& point) const noexcept;
63 [[nodiscard]] bool containsBox(const BoundingBox& AABB2) const noexcept;
64 [[nodiscard]] bool containsSphere(const BoundingSphere& bSphere) const noexcept;
65
66 [[nodiscard]] bool collision(const BoundingBox& AABB2) const noexcept;
67 [[nodiscard]] bool collision(const BoundingSphere& bSphere) const noexcept;
68
69 [[nodiscard]] bool compare(const BoundingBox& bb) const noexcept;
70 [[nodiscard]] bool operator==(const BoundingBox& B) const noexcept;
71 [[nodiscard]] bool operator!=(const BoundingBox& B) const noexcept;
72
74 [[nodiscard]] RayResult intersect(const Ray& r, F32 t0, F32 t1) const noexcept;
75
76 void createFromPoints(const vector<vec3<F32>>& points) noexcept;
77 void createFromPoints(const std::array<vec3<F32>, 8>& points) noexcept;
78 void createFromSphere(const BoundingSphere& bSphere) noexcept;
79 void createFromSphere(const vec3<F32>& center, F32 radius) noexcept;
80 void createFromCenterAndSize(const vec3<F32>& center, const vec3<F32>& size) noexcept;
81 void createFromOBB(const OBB& obb) noexcept;
82
83 void add(const vec3<F32>& v) noexcept;
84 void add(const BoundingBox& bb) noexcept;
85
86 void translate(const vec3<F32>& v) noexcept;
87
88 void multiply(F32 factor) noexcept;
89 void multiply(const vec3<F32>& v) noexcept;
90 void multiplyMax(const vec3<F32>& v) noexcept;
91 void multiplyMin(const vec3<F32>& v) noexcept;
92
93 void transform(vec3<F32> initialMin, vec3<F32> initialMax, const mat4<F32>& mat) noexcept;
94 void transform(const BoundingBox& initialBoundingBox, const mat4<F32>& mat) noexcept;
95 void transform(const mat4<F32>& mat) noexcept;
96
97 [[nodiscard]] const vec3<F32>& getMin() const noexcept;
98 [[nodiscard]] const vec3<F32>& getMax() const noexcept;
99
100 [[nodiscard]] vec3<F32> getCenter() const noexcept;
101 [[nodiscard]] vec3<F32> getExtent() const noexcept;
102 [[nodiscard]] vec3<F32> getHalfExtent() const noexcept;
103
104 [[nodiscard]] F32 getWidth() const noexcept;
105 [[nodiscard]] F32 getHeight() const noexcept;
106 [[nodiscard]] F32 getDepth() const noexcept;
107
108 void set(const BoundingBox& bb) noexcept;
109 void set(const vec3<F32>& min, const vec3<F32>& max) noexcept;
110 void setMin(const vec3<F32>& min) noexcept;
111 void setMax(const vec3<F32>& max) noexcept;
112
113 void set(F32 min, F32 max) noexcept;
114 void set(F32 minX, F32 minY, F32 minZ, F32 maxX, F32 maxY, F32 maxZ) noexcept;
115 void setMin(F32 min) noexcept;
116 void setMin(F32 minX, F32 minY, F32 minZ) noexcept;
117 void setMax(F32 max) noexcept;
118 void setMax(F32 maxX, F32 maxY, F32 maxZ) noexcept;
119
120 void reset() noexcept;
121
122 [[nodiscard]] vec3<F32> cornerPoint(U8 cornerIndex) const noexcept;
123 [[nodiscard]] std::array<vec3<F32>, 8> getPoints() const noexcept;
124
125 // Returns the closest point inside this AABB to the given point
126 [[nodiscard]] vec3<F32> nearestPoint(const vec3<F32>& pos) const noexcept;
127
128 [[nodiscard]] inline vec3<F32> getPVertex(const vec3<F32>& normal) const noexcept;
129 [[nodiscard]] inline vec3<F32> getNVertex(const vec3<F32>& normal) const noexcept;
130
131 private:
133};
134
135namespace Attorney {
137 static F32* min(BoundingBox& bb) noexcept {
138 return bb._min._v;
139 }
140 static F32* max(BoundingBox& bb) noexcept {
141 return bb._max._v;
142 }
144 };
145} //namespace Attorney
146
147} // namespace Divide
148
149#endif //DVD_CORE_MATH_BOUNDINGVOLUMES_BOUNDINGBOX_H_
150
151#include "BoundingBox.inl"
static F32 * max(BoundingBox &bb) noexcept
Definition: BoundingBox.h:140
static F32 * min(BoundingBox &bb) noexcept
Definition: BoundingBox.h:137
void setMin(const vec3< F32 > &min) noexcept
void createFromSphere(const BoundingSphere &bSphere) noexcept
Definition: BoundingBox.cpp:61
vec3< F32 > nearestPoint(const vec3< F32 > &pos) const noexcept
void set(const BoundingBox &bb) noexcept
void createFromCenterAndSize(const vec3< F32 > &center, const vec3< F32 > &size) noexcept
Definition: BoundingBox.cpp:65
bool compare(const BoundingBox &bb) const noexcept
Definition: BoundingBox.inl:42
vec3< F32 > _min
Definition: BoundingBox.h:132
void add(const vec3< F32 > &v) noexcept
Definition: BoundingBox.inl:72
std::array< vec3< F32 >, 8 > getPoints() const noexcept
vec3< F32 > getCenter() const noexcept
void createFromPoints(const vector< vec3< F32 > > &points) noexcept
Definition: BoundingBox.inl:55
bool containsBox(const BoundingBox &AABB2) const noexcept
Definition: BoundingBox.cpp:80
bool collision(const BoundingBox &AABB2) const noexcept
Definition: BoundingBox.cpp:96
BoundingBox() noexcept
Definition: BoundingBox.cpp:9
void transform(vec3< F32 > initialMin, vec3< F32 > initialMax, const mat4< F32 > &mat) noexcept
vec3< F32 > getNVertex(const vec3< F32 > &normal) const noexcept
const vec3< F32 > & getMax() const noexcept
F32 getDepth() const noexcept
const vec3< F32 > & getMin() const noexcept
void createFromOBB(const OBB &obb) noexcept
Definition: BoundingBox.cpp:71
void reset() noexcept
bool containsPoint(const vec3< F32 > &point) const noexcept
Definition: BoundingBox.inl:37
bool containsSphere(const BoundingSphere &bSphere) const noexcept
Definition: BoundingBox.cpp:84
F32 getHeight() const noexcept
void multiply(F32 factor) noexcept
void translate(const vec3< F32 > &v) noexcept
void setMax(const vec3< F32 > &max) noexcept
void multiplyMin(const vec3< F32 > &v) noexcept
F32 getWidth() const noexcept
vec3< F32 > cornerPoint(U8 cornerIndex) const noexcept
void multiplyMax(const vec3< F32 > &v) noexcept
RayResult intersect(const Ray &r, F32 t0, F32 t1) const noexcept
Optimized method.
vec3< F32 > _max
Definition: BoundingBox.h:132
vec3< F32 > getPVertex(const vec3< F32 > &normal) const noexcept
vec3< F32 > getHalfExtent() const noexcept
vec3< F32 > getExtent() const noexcept
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42