1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "Prerequisites/BsPrerequisitesUtil.h"
6#include "Math/BsVector3.h"
7#include "Math/BsAABox.h"
8#include "Math/BsSphere.h"
9#include "Math/BsMatrix4.h"
10
11namespace bs
12{
13 /** @addtogroup Math
14 * @{
15 */
16
17 /** Bounds represented by an axis aligned box and a sphere. */
18 class BS_UTILITY_EXPORT Bounds
19 {
20 public:
21 Bounds() = default;
22 Bounds(const AABox& box, const Sphere& sphere);
23 ~Bounds() = default;
24
25 /** Returns the axis aligned box representing the bounds. */
26 const AABox& getBox() const { return mBox; }
27
28 /** Returns the sphere representing the bounds. */
29 const Sphere& getSphere() const { return mSphere; }
30
31 /** Updates the bounds by setting the new bounding box and sphere. */
32 void setBounds(const AABox& box, const Sphere& sphere);
33
34 /** Merges the two bounds, creating a new bounds that encapsulates them both. */
35 void merge(const Bounds& rhs);
36
37 /** Expands the bounds so it includes the provided point. */
38 void merge(const Vector3& point);
39
40 /**
41 * Transforms the bounds by the given matrix.
42 *
43 * @note
44 * As the resulting box will no longer be axis aligned, an axis align box
45 * is instead created by encompassing the transformed oriented bounding box.
46 * Retrieving the value as an actual OBB would provide a tighter fit.
47 */
48 void transform(const Matrix4& matrix);
49
50 /**
51 * Transforms the bounds by the given matrix.
52 *
53 * @note
54 * As the resulting box will no longer be axis aligned, an axis align box
55 * is instead created by encompassing the transformed oriented bounding box.
56 * Retrieving the value as an actual OBB would provide a tighter fit.
57 *
58 * @note
59 * Provided matrix must be affine.
60 */
61 void transformAffine(const Matrix4& matrix);
62
63 protected:
64 AABox mBox;
65 Sphere mSphere;
66 };
67
68 /** @} */
69
70 BS_ALLOW_MEMCPY_SERIALIZATION(Bounds)
71}
72