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/BsPlane.h"
7
8namespace bs
9{
10 /** @addtogroup Math
11 * @{
12 */
13
14 /** Clip planes that form the camera frustum (visible area). */
15 enum FrustumPlane
16 {
17 FRUSTUM_PLANE_LEFT = 0,
18 FRUSTUM_PLANE_RIGHT = 1,
19 FRUSTUM_PLANE_TOP = 2,
20 FRUSTUM_PLANE_BOTTOM = 3,
21 FRUSTUM_PLANE_FAR = 4,
22 FRUSTUM_PLANE_NEAR = 5
23 };
24
25 /** Represents a convex volume defined by planes representing the volume border. */
26 class BS_UTILITY_EXPORT ConvexVolume
27 {
28 public:
29 ConvexVolume() = default;
30 ConvexVolume(const Vector<Plane>& planes);
31
32 /** Creates frustum planes from the provided projection matrix. */
33 ConvexVolume(const Matrix4& projectionMatrix, bool useNearPlane = true);
34
35 /**
36 * Checks does the volume intersects the provided axis aligned box.
37 * This will return true if the box is fully inside the volume.
38 */
39 bool intersects(const AABox& box) const;
40
41 /**
42 * Checks does the volume intersects the provided sphere.
43 * This will return true if the sphere is fully inside the volume.
44 */
45 bool intersects(const Sphere& sphere) const;
46
47 /**
48 * Checks if the convex volume contains the provided point.
49 *
50 * @param[in] p Point to check.
51 * @param[in] expand Optional value to expand the size of the convex volume by the specified value during the
52 * check. Negative values shrink the volume.
53 */
54 bool contains(const Vector3& p, float expand = 0.0f) const;
55
56 /** Returns the internal set of planes that represent the volume. */
57 Vector<Plane> getPlanes() const { return mPlanes; }
58
59 /** Returns the specified plane that represents the volume. */
60 const Plane& getPlane(FrustumPlane whichPlane) const;
61
62 private:
63 Vector<Plane> mPlanes;
64 };
65
66 /** @} */
67}
68