Plasma Engine  2.0
Loading...
Searching...
No Matches
Frustum.h
1#pragma once
2
3#include <Foundation/Math/Mat4.h>
4#include <Foundation/Math/Plane.h>
5#include <Foundation/SimdMath/SimdBBox.h>
6#include <Foundation/SimdMath/SimdBSphere.h>
7#include <Foundation/SimdMath/SimdVec4b.h>
8#include <Foundation/SimdMath/SimdVec4f.h>
9
12{
14 enum Enum
15 {
16 Outside, //< means an object is ENTIRELY inside a volume
17 Inside, //< means an object is outside a volume
18 Intersecting, //< means an object is PARTIALLY inside/outside a volume
19 };
20};
21
31class PL_FOUNDATION_DLL plFrustum
32{
33public:
34 enum PlaneType : plUInt8
35 {
36 NearPlane,
37 LeftPlane,
38 RightPlane,
39 FarPlane,
40 BottomPlane,
41 TopPlane,
42
43 PLANE_COUNT
44 };
45
46 enum FrustumCorner : plUInt8
47 {
48 NearTopLeft,
49 NearTopRight,
50 NearBottomLeft,
51 NearBottomRight,
52 FarTopLeft,
53 FarTopRight,
54 FarBottomLeft,
55 FarBottomRight,
56
57 CORNER_COUNT = 8
58 };
59
62 ~plFrustum();
63
67 [[nodiscard]] static plFrustum MakeFromPlanes(const plPlane* pPlanes); // [tested]
68
74 [[nodiscard]] static plResult TryMakeFromPlanes(plFrustum& out_frustum, const plPlane* pPlanes);
75
81 [[nodiscard]] static plFrustum MakeFromMVP(const plMat4& mModelViewProjection, plClipSpaceDepthRange::Enum depthRange = plClipSpaceDepthRange::Default, plHandedness::Enum handedness = plHandedness::Default); // [tested]
82
90 [[nodiscard]] static plResult TryMakeFromMVP(plFrustum& out_frustum, const plMat4& mModelViewProjection, plClipSpaceDepthRange::Enum depthRange = plClipSpaceDepthRange::Default, plHandedness::Enum handedness = plHandedness::Default);
91
96 [[nodiscard]] static plFrustum MakeFromFOV(const plVec3& vPosition, const plVec3& vForwards, const plVec3& vUp, plAngle fovX, plAngle fovY, float fNearPlane, float fFarPlane); // [tested]
97
104 [[nodiscard]] static plResult TryMakeFromFOV(plFrustum& out_frustum, const plVec3& vPosition, const plVec3& vForwards, const plVec3& vUp, plAngle fovX, plAngle fovY, float fNearPlane, float fFarPlane);
105
109 [[nodiscard]] static plFrustum MakeFromCorners(const plVec3 pCorners[FrustumCorner::CORNER_COUNT]);
110
114 [[nodiscard]] static plResult TryMakeFromCorners(plFrustum& out_frustum, const plVec3 pCorners[FrustumCorner::CORNER_COUNT]);
115
117 const plPlane& GetPlane(plUInt8 uiPlane) const; // [tested]
118
120 plPlane& AccessPlane(plUInt8 uiPlane);
121
123 bool IsValid() const;
124
127 void TransformFrustum(const plMat4& mTransform); // [tested]
128
130 plFrustum GetTransformedFrustum(const plMat4& mTransform) const; // [tested]
131
133 void InvertFrustum(); // [tested]
134
139 plResult ComputeCornerPoints(plVec3 out_pPoints[FrustumCorner::CORNER_COUNT]) const; // [tested]
140
145 plVolumePosition::Enum GetObjectPosition(const plVec3* pVertices, plUInt32 uiNumVertices) const; // [tested]
146
149 plVolumePosition::Enum GetObjectPosition(const plVec3* pVertices, plUInt32 uiNumVertices, const plMat4& mObjectTransform) const; // [tested]
150
152 plVolumePosition::Enum GetObjectPosition(const plBoundingSphere& sphere) const; // [tested]
153
155 plVolumePosition::Enum GetObjectPosition(const plBoundingBox& box) const; // [tested]
156
161 bool Overlaps(const plSimdBBox& object) const; // [tested]
162
167 bool Overlaps(const plSimdBSphere& object) const; // [tested]
168
169private:
170 plPlane m_Planes[PLANE_COUNT];
171};
172
173#include <Foundation/Math/Implementation/Frustum_inl.h>
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
Represents the frustum of some camera and can be used for culling objects.
Definition Frustum.h:32
plFrustum()
The constructor does NOT initialize the frustum planes, make sure to call SetFrustum() before trying ...
Definition SimdBBox.h:6
Definition SimdBSphere.h:6
Enum
Definition Declarations.h:79
static PL_FOUNDATION_DLL Enum Default
Holds the default value for the projection depth range on each platform. This can be overridden by re...
Definition Declarations.h:87
static PL_FOUNDATION_DLL Enum Default
Holds the default handedness value to use. pl uses 'LeftHanded' by default.
Definition Declarations.h:124
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Enum that describes where in a volume another object is located.
Definition Frustum.h:12
Enum
Enum that describes where in a volume another object is located.
Definition Frustum.h:15