HPC_Voxel_Engine 0.2.0
High-Performance C++ Voxel Engine
Loading...
Searching...
No Matches
Frustum.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cmath>
5#include "../core/MathUtils.h"
6#include "../core/Matrix.h"
7#include "../physics/AABB.h"
8
9struct Plane {
10 float a = 0.0f, b = 0.0f, c = 0.0f, d = 0.0f;
11
12 Plane() = default;
13 Plane(float _a, float _b, float _c, float _d) : a(_a), b(_b), c(_c), d(_d) {}
14
15 void Normalize() {
16 float length = std::sqrt(a * a + b * b + c * c);
17 if (length > 0.0f) {
18 float invLength = 1.0f / length;
19 a *= invLength;
20 b *= invLength;
21 c *= invLength;
22 d *= invLength;
23 }
24 }
25
26 float GetSignedDistanceToPlane(const Core::Vec3& point) const {
27 return a * point.x + b * point.y + c * point.z + d;
28 }
29};
30
35class Frustum {
36public:
37 Frustum() = default;
38
43 void Update(const Core::Mat4& viewProjMatrix);
44
49 bool IsBoxInVisibleFrustum(const AABB& box) const;
50
51private:
52 std::array<Plane, 6> m_arrPlanes;
53};
Axis-Aligned Bounding Box for collision detection. Defined by a Minimum and Maximum point in 3D space...
Definition AABB.h:12
Represents the camera's viewing volume. Used for Culling.
Definition Frustum.h:35
std::array< Plane, 6 > m_arrPlanes
Definition Frustum.h:52
void Update(const Core::Mat4 &viewProjMatrix)
Extracts the 6 frustum planes from the View-Projection matrix. Uses the Gribb-Hartmann method.
Definition Frustum.cpp:6
Frustum()=default
bool IsBoxInVisibleFrustum(const AABB &box) const
Checks if an AABB is visible within the frustum. Uses the "Center + Extent" method for high performan...
Definition Frustum.cpp:33
A 4x4 Matrix structure stored in Column-Major order (OpenGL Standard).
Definition Matrix.h:18
A 3-component vector structure (x, y, z) with standard math operations.
Definition MathUtils.h:11
float x
Definition MathUtils.h:12
float z
Definition MathUtils.h:12
float y
Definition MathUtils.h:12
Definition Frustum.h:9
float GetSignedDistanceToPlane(const Core::Vec3 &point) const
Definition Frustum.h:26
void Normalize()
Definition Frustum.h:15
float b
Definition Frustum.h:10
float d
Definition Frustum.h:10
float a
Definition Frustum.h:10
Plane()=default
float c
Definition Frustum.h:10
Plane(float _a, float _b, float _c, float _d)
Definition Frustum.h:13