-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFrustum.cpp
53 lines (43 loc) · 1.23 KB
/
Frustum.cpp
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
#include "Precompiled.hpp"
#include "Frustum.hpp"
#include "Matrix.hpp"
namespace Math
{
Frustum::Frustum()
{
}
void Frustum::set_from(const Matrix& matrix)
{
const Vector4 m1 = matrix.column(0);
const Vector4 m2 = matrix.column(1);
const Vector4 m3 = matrix.column(2);
const Vector4 m4 = matrix.column(3);
planes_[FRUSTUM_PLANE_NEAR] = Plane(m3);
planes_[FRUSTUM_PLANE_FAR] = Plane(m4 - m3);
planes_[FRUSTUM_PLANE_LEFT] = Plane(m4 + m1);
planes_[FRUSTUM_PLANE_TOP] = Plane(m4 - m2);
planes_[FRUSTUM_PLANE_RIGHT] = Plane(m4 - m1);
planes_[FRUSTUM_PLANE_BOTTOM] = Plane(m4 + m2);
}
const Plane& Frustum::get_plane(FrustumPlane plane_enum) const
{
return planes_[plane_enum];
}
template <class Object> Intersect::PlaneResult Frustum::test(const Object& object) const
{
uint_t inside_count = 0;
for (uint_t plane = 0; plane < FRUSTUM_PLANE_COUNT; ++plane)
{
const Intersect::PlaneResult result = Intersect::test(planes_[plane], object);
if (result == Intersect::OUTSIDE_PLANE)
{
return Intersect::OUTSIDE_PLANE;
}
if (result == Intersect::INSIDE_PLANE)
{
++inside_count;
}
}
return (inside_count == FRUSTUM_PLANE_COUNT) ? Intersect::INSIDE_PLANE : Intersect::INTERSECTS_PLANE;
}
}