-
Notifications
You must be signed in to change notification settings - Fork 3
/
Frustum.h
70 lines (43 loc) · 1.25 KB
/
Frustum.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include "Dependencies/DependenciesMath.h"
//Frustum, for frustum culling
//uses a geometric aproach
//based on http://www.lighthouse3d.com/tutorials/view-frustum-culling/
namespace Open7Days {
enum FrustumPlanes {
Top, Bottom, Left,
Right, Near, Far
};
struct FrustumAABB {
Vector3f Min, Max;
FrustumAABB(Vector3f Min, Vector3f Max) : Min(Min), Max(Max) {}
Vector3f GetMinPointFromNormal(Vector3f Normal) {
Vector3f Result = Max;
for (int i = 0; i < 3; i++)
if (Normal[i] >= 0)
Result[i] = Min[i];
return Result;
}
Vector3f GetMaxPointFromNormal(Vector3f Normal) {
Vector3f Result = Min;
for (int i = 0; i < 3; i++)
if (Normal[i] >= 0)
Result[i] = Max[i];
return Result;
}
};
struct FrustumPlane {
float DistToOrig;
Vector3f Normal;
FrustumPlane(float DistToOrig = 0.0, Vector3f Normal = Vector3f(0.)):
DistToOrig(DistToOrig), Normal(Normal) {}
float DistanceToPoint(Vector3f Point) {
return glm::dot(Normal, Point) + DistToOrig;
}
};
struct Frustum {
FrustumPlane Planes[6] = { FrustumPlane(),FrustumPlane(),FrustumPlane(),FrustumPlane(),FrustumPlane(),FrustumPlane() };
void Update(Matrix4f Matrix);
bool InFrustum(FrustumAABB Box);
};
}