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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include "ViewFrustum.hpp"
ViewFrustum::ViewFrustum()
{
//ctor
}
ViewFrustum::~ViewFrustum()
{
//dtor
}
void ViewFrustum::CreateFromCurrentMatrix()
{
CreateFromMatrix(Mrl::GetGLModelViewMatrix()*Mrl::GetGLProjectionMatrix());
}
void ViewFrustum::CreateFromMatrix(Mrl::Matrix Frustum)
{
Frustum.TransposeMatrix();
m_LeftPlane.Set(vec3(Frustum._41+Frustum._11, Frustum._42+Frustum._12, Frustum._43+Frustum._13), Frustum._44+Frustum._14);
m_LeftPlane.Normalize();
m_LeftNP.X=m_LeftPlane.Normal.x>=0; m_LeftNP.Y=m_LeftPlane.Normal.y>=0; m_LeftNP.Z=m_LeftPlane.Normal.z>=0;
m_RightPlane.Set(vec3(Frustum._41-Frustum._11, Frustum._42-Frustum._12, Frustum._43-Frustum._13), Frustum._44-Frustum._14);
m_RightPlane.Normalize();
m_RightNP.X=m_RightPlane.Normal.x>=0; m_RightNP.Y=m_RightPlane.Normal.y>=0; m_RightNP.Z=m_RightPlane.Normal.z>=0;
m_TopPlane.Set(vec3(Frustum._41-Frustum._21, Frustum._42-Frustum._22, Frustum._43-Frustum._23), Frustum._44-Frustum._24);
m_TopPlane.Normalize();
m_TopNP.X=m_TopPlane.Normal.x>=0; m_TopNP.Y=m_TopPlane.Normal.y>=0; m_TopNP.Z=m_TopPlane.Normal.z>=0;
m_BottomPlane.Set(vec3(Frustum._41+Frustum._21, Frustum._42+Frustum._22, Frustum._43+Frustum._23), Frustum._44+Frustum._24);
m_BottomPlane.Normalize();
m_BottomNP.X=m_BottomPlane.Normal.x>=0; m_BottomNP.Y=m_BottomPlane.Normal.y>=0; m_BottomNP.Z=m_BottomPlane.Normal.z>=0;
}
bool ViewFrustum::TestSphere(vec3 Position, float Radius) const
{
if(m_LeftPlane.SignedDistance(Position)<=-Radius)
{
return false;
}
if(m_RightPlane.SignedDistance(Position)<=-Radius)
{
return false;
}
if(m_TopPlane.SignedDistance(Position)<=-Radius)
{
return false;
}
if(m_BottomPlane.SignedDistance(Position)<=-Radius)
{
return false;
}
return true;
}
bool ViewFrustum::TestAABB(const BoundingBox& AABB) const
{
if(TestPlaneBB(m_LeftPlane, m_LeftNP, AABB))
return false;
if(TestPlaneBB(m_RightPlane, m_RightNP, AABB))
return false;
if(TestPlaneBB(m_TopPlane, m_TopNP, AABB))
return false;
if(TestPlaneBB(m_BottomPlane, m_BottomNP, AABB))
return false;
return true;
}
bool ViewFrustum::TestPlaneBB(const Plane3D& Plane, const NPLookUp& LookUp, const BoundingBox& BB) const
{
vec3 N((LookUp.X ? BB.Max.x : BB.Min.x), (LookUp.Y ? BB.Max.y : BB.Min.y), (LookUp.Z ? BB.Max.z : BB.Min.z));
vec3 P((LookUp.X ? BB.Min.x : BB.Max.x), (LookUp.Y ? BB.Min.y : BB.Max.y), (LookUp.Z ? BB.Min.z : BB.Max.z));
if(Plane.SignedDistance(N)<=0)
return true;
//if(Plane.SignedDistance(P)<=0)
// return true;
return false;
}
|