Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
OBB.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_OOBB_H_
34#define DVD_CORE_MATH_BOUNDINGVOLUMES_OOBB_H_
35
37
38//ref: https://github.com/juj/MathGeoLib
39namespace Divide {
40
42{
45};
46
47class BoundingSphere;
48class BoundingBox;
49class OBB {
50public:
51 using OBBAxis = std::array<vec3<F32>, 3>;
52 using OOBBEdgeList = std::array<LineSegment, 12>;
53
54 OBB() = default;
55 explicit OBB(vec3<F32> pos, vec3<F32> hExtents, OBBAxis axis) noexcept;
56 explicit OBB(const BoundingBox &aabb) noexcept;
57 explicit OBB(const BoundingSphere &bSphere) noexcept;
58
59 void fromBoundingBox(const BoundingBox& aabb) noexcept;
60 void fromBoundingBox(const BoundingBox& aabb, const mat4<F32>& worldMatrix);
61 void fromBoundingBox(const BoundingBox& aabb, const Quaternion<F32>& orientation);
62 void fromBoundingBox(const BoundingBox& aabb, const vec3<F32>& position, const Quaternion<F32>& rotation, const vec3<F32>& scale);
63 void fromBoundingSphere(const BoundingSphere &sphere) noexcept;
64
65 void translate(const vec3<F32>& offset);
67 void scale(const vec3<F32>& centerPoint, F32 scaleFactor);
69 void scale(const vec3<F32>& centerPoint, const vec3<F32>& scaleFactor);
70 void transform(const mat3<F32>& transform);
71 void transform(const mat4<F32>& transform);
72 void transform(const Quaternion<F32>& rotation);
73
74 [[nodiscard]] BoundingBox toBoundingBox() const noexcept;
75
76 [[nodiscard]] BoundingSphere toEnclosingSphere() const noexcept;
77 [[nodiscard]] BoundingSphere toEnclosedSphere() const noexcept;
78
79 [[nodiscard]] F32 distance(const vec3<F32>& point) const noexcept;
80 [[nodiscard]] vec3<F32> closestPoint(const vec3<F32>& point) const noexcept;
81 [[nodiscard]] vec3<F32> cornerPoint(U8 cornerIndex) const noexcept;
82 [[nodiscard]] vec3<F32> size() const noexcept;
83 [[nodiscard]] vec3<F32> diagonal() const noexcept;
84 [[nodiscard]] vec3<F32> halfDiagonal() const noexcept;
85 [[nodiscard]] LineSegment edge(U8 edgeIndex) const noexcept;
86 [[nodiscard]] OOBBEdgeList edgeList() const noexcept;
87
88 [[nodiscard]] bool containsPoint(const vec3<F32>& point) const noexcept;
89 [[nodiscard]] bool containsBox(const OBB& OBB) const noexcept;
90 [[nodiscard]] bool containsBox(const BoundingBox& AABB) const noexcept;
91 [[nodiscard]] bool containsSphere(const BoundingSphere& bSphere) const noexcept;
92
93 [[nodiscard]] RayResult intersect(const Ray& ray, F32 t0In, F32 t1In) const noexcept;
94
98};
99
100} // namespace Divide
101
102#endif //DVD_CORE_MATH_BOUNDINGVOLUMES_OOBB_H_
#define PROPERTY_RW(...)
Convenience method to add a class member with public read access and write access.
LineSegment edge(U8 edgeIndex) const noexcept
Definition: OBB.cpp:133
vec3< F32 > size() const noexcept
Definition: OBB.cpp:119
F32 distance(const vec3< F32 > &point) const noexcept
Definition: OBB.cpp:171
void transform(const mat3< F32 > &transform)
Definition: OBB.cpp:88
bool containsPoint(const vec3< F32 > &point) const noexcept
Definition: OBB.cpp:175
BoundingSphere toEnclosedSphere() const noexcept
Definition: OBB.cpp:115
vec3< F32 > closestPoint(const vec3< F32 > &point) const noexcept
Definition: OBB.cpp:161
bool containsBox(const OBB &OBB) const noexcept
Definition: OBB.cpp:182
RayResult intersect(const Ray &ray, F32 t0In, F32 t1In) const noexcept
Definition: OBB.cpp:206
vec3< F32 > cornerPoint(U8 cornerIndex) const noexcept
Definition: OBB.cpp:26
void fromBoundingSphere(const BoundingSphere &sphere) noexcept
Definition: OBB.cpp:70
void translate(const vec3< F32 > &offset)
Definition: OBB.cpp:76
std::array< LineSegment, 12 > OOBBEdgeList
Definition: OBB.h:52
bool containsSphere(const BoundingSphere &bSphere) const noexcept
Definition: OBB.cpp:202
OBB()=default
OOBBEdgeList edgeList() const noexcept
Definition: OBB.cpp:152
void fromBoundingBox(const BoundingBox &aabb) noexcept
Definition: OBB.cpp:41
BoundingSphere toEnclosingSphere() const noexcept
Definition: OBB.cpp:111
void scale(const vec3< F32 > &centerPoint, F32 scaleFactor)
Uniform scaling.
Definition: OBB.cpp:80
std::array< vec3< F32 >, 3 > OBBAxis
Definition: OBB.h:51
vec3< F32 > halfDiagonal() const noexcept
Definition: OBB.cpp:127
BoundingBox toBoundingBox() const noexcept
Definition: OBB.cpp:107
vec3< F32 > diagonal() const noexcept
Definition: OBB.cpp:123
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
uint8_t U8
static const vec3< F32 > VECTOR3_UNIT
Definition: MathVectors.h:1437
static const vec3< F32 > VECTOR3_ZERO
Definition: MathVectors.h:1434
vec3< F32 > _start
Definition: OBB.h:43
vec3< F32 > _end
Definition: OBB.h:44