Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
Frustum.cpp
1/*
2Copyright (C) 2015-2019,2025 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#include "3DMath.h"
17#include "aeongames/Plane.hpp"
18#include "aeongames/Frustum.hpp"
19#include "aeongames/AABB.hpp"
21#include <iostream>
22
23namespace AeonGames
24{
25 Frustum::Frustum() = default;
26 Frustum::Frustum ( const Matrix4x4 & aMatrix ) :
27 mPlanes
28 {
29 {
30 // Left clipping plane
31 Plane
32 {
33 - ( aMatrix[3] + aMatrix[0] ),
34 - ( aMatrix[7] + aMatrix[4] ),
35 - ( aMatrix[11] + aMatrix[8] ),
36 ( aMatrix[15] + aMatrix[12] )
37 },
38 // Right clipping plane
39 Plane
40 {
41 - ( aMatrix[3] - aMatrix[0] ),
42 - ( aMatrix[7] - aMatrix[4] ),
43 - ( aMatrix[11] - aMatrix[8] ),
44 ( aMatrix[15] - aMatrix[12] )
45 },
46 // Top clipping plane
47 Plane
48 {
49 - ( aMatrix[3] + aMatrix[1] ),
50 - ( aMatrix[7] + aMatrix[5] ),
51 - ( aMatrix[11] + aMatrix[9] ),
52 ( aMatrix[15] + aMatrix[13] )
53 },
54 // Bottom clipping plane
55 Plane
56 {
57 - ( aMatrix[3] - aMatrix[1] ),
58 - ( aMatrix[7] - aMatrix[5] ),
59 - ( aMatrix[11] - aMatrix[9] ),
60 ( aMatrix[15] - aMatrix[13] )
61 },
62 // Near clipping plane
63 Plane
64 {
65 - ( aMatrix[3] + aMatrix[2] ),
66 - ( aMatrix[7] + aMatrix[6] ),
67 - ( aMatrix[11] + aMatrix[10] ),
68 ( aMatrix[15] + aMatrix[14] )
69 },
70 // Far clipping plane
71 Plane
72 {
73 - ( aMatrix[3] - aMatrix[2] ),
74 - ( aMatrix[7] - aMatrix[6] ),
75 - ( aMatrix[11] - aMatrix[10] ),
76 ( aMatrix[15] - aMatrix[14] )
77 }
78 }
79 }
80 {
81 }
83 = default;
84 bool Frustum::Intersects ( const AABB & aAABB ) const
85 {
86 for ( auto& plane : mPlanes )
87 {
88 if ( aAABB.GetDistanceToPlane ( plane ) > 0.0f )
89 {
90 return false;
91 }
92 }
93 return true;
94 }
95}
Inline functions related to 3D Math.
Header for the axis aligned bounding box class.
Header for the frustum class.
Header for 4x4 matrix class.
Header for the plane class.
Axis Aligned Bounding Box class.
Definition AABB.hpp:34
DLL float GetDistanceToPlane(const Plane &aPlane) const
Returns the shortest distance from any point in the plane's surface to the support point of the AABB ...
Definition AABB.cpp:67
DLL Frustum()
Default constructor.
DLL bool Intersects(const AABB &aAABB) const
Tests whether an axis-aligned bounding box intersects or is inside the frustum.
Definition Frustum.cpp:84
DLL ~Frustum()
destructor.
4 by 4 matrix in colum mayor order.
Definition Matrix4x4.hpp:35
Plane class.
Definition Plane.hpp:33
<- This is here just for the literals
Definition AABB.hpp:31