DeferredRenderer 1.0
|
A generic frustum class that can be generated from any Projview, contains basic point and Bbox culling methods. More...
#include <Frustum.h>
Classes | |
struct | Plane |
a basic structure for plane equation ax+by+cz+d = 0 More... | |
Public Member Functions | |
Frustum () | |
empty ctor | |
void | generate (const ngl::Matrix &_mat) |
method to generate the frustum from a projView matrix | |
bool | isAbovePlane (unsigned int _planeSide, const ngl::Vector &_point) const |
collision check for a point against a frustum plane | |
bool | isInFrustum (const ngl::Vector &_min, const ngl::Vector &_max) const |
bbox check inside frustum | |
bool | isInFrustum (const ngl::Vector &_point) const |
point check inside frustum | |
Private Types | |
enum | planeSides { e_left = 0, e_right = 1, e_bottom = 2, e_top = 3, e_near = 4, e_far = 5 } |
enum for identifying the 6 sides of the frustum More... | |
enum | planeSign { e_minus = -1, e_plus = 1 } |
enum used to denote which way the plane is facing More... | |
Private Member Functions | |
void | buildPlane (Plane &io_plane, const ngl::Matrix &_mat, int _row, int _sign) |
build a plane | |
void | normalizePlane (Plane &_plane) |
normalise the plane | |
Private Attributes | |
Plane | m_planes [6] |
the 6 sides of the frustum |
A generic frustum class that can be generated from any Projview, contains basic point and Bbox culling methods.
enum Frustum::planeSides [private] |
enum Frustum::planeSign [private] |
void Frustum::buildPlane | ( | Plane & | io_plane, |
const ngl::Matrix & | _mat, | ||
int | _row, | ||
int | _sign | ||
) | [private] |
build a plane
[inout] | _plane the plane to buil | |
[in] | _mat | the matrix to build it from |
[in] | _row | the matrix row to build from |
[in] | _sign | the direction of the plane normal |
Definition at line 4 of file Frustum.cpp.
References Frustum::Plane::a, Frustum::Plane::b, Frustum::Plane::c, Frustum::Plane::d, and normalizePlane().
{ _plane.a = _mat.m_m[0][3] + _sign * _mat.m_m[0][_row]; _plane.b = _mat.m_m[1][3] + _sign * _mat.m_m[1][_row]; _plane.c = _mat.m_m[2][3] + _sign * _mat.m_m[2][_row]; _plane.d = _mat.m_m[3][3] + _sign * _mat.m_m[3][_row]; normalizePlane(_plane); }
void Frustum::generate | ( | const ngl::Matrix & | _mat | ) |
method to generate the frustum from a projView matrix
[in] | _mat | the matrix to build from |
Definition at line 14 of file Frustum.cpp.
References buildPlane(), e_bottom, e_far, e_left, e_minus, e_near, e_plus, e_right, e_top, and m_planes.
{ buildPlane(m_planes[e_left],_mat,0,e_plus); buildPlane(m_planes[e_right],_mat,0,e_minus); buildPlane(m_planes[e_bottom],_mat,1,e_plus); buildPlane(m_planes[e_top],_mat,1,e_minus); buildPlane(m_planes[e_near],_mat,2,e_plus); buildPlane(m_planes[e_far],_mat,2,e_minus); }
bool Frustum::isAbovePlane | ( | unsigned int | _planeSide, |
const ngl::Vector & | _point | ||
) | const |
collision check for a point against a frustum plane
[in] | _planeSide | the side of the frustum to check |
[in] | _point | the point to check |
Definition at line 24 of file Frustum.cpp.
References Frustum::Plane::a, Frustum::Plane::b, Frustum::Plane::c, Frustum::Plane::d, and m_planes.
{ return m_planes[_planeSide].a*_point.m_x + m_planes[_planeSide].b*_point.m_y + m_planes[_planeSide].c*_point.m_z + m_planes[_planeSide].d >= 0; }
bool Frustum::isInFrustum | ( | const ngl::Vector & | _min, |
const ngl::Vector & | _max | ||
) | const |
bbox check inside frustum
[in] | _min | the lower extent of bbox |
[in] | _max | the upper extent of bbox |
Definition at line 38 of file Frustum.cpp.
References isAbovePlane(), and m_planes.
{ ngl::Vector vmin, vmax; for (unsigned int i=0;i<6;i++) { if (m_planes[i].a>0) { vmin.m_x=_min.m_x; vmax.m_x=_max.m_x; } else { vmin.m_x=_max.m_x; vmax.m_x=_min.m_x; } if (m_planes[i].b>0) { vmin.m_y=_min.m_y; vmax.m_y=_max.m_y; } else { vmin.m_y=_max.m_y; vmax.m_y=_min.m_y; } if (m_planes[i].c>0) { vmin.m_z=_min.m_z; vmax.m_z=_max.m_z; } else { vmin.m_z=_max.m_z; vmax.m_z=_min.m_z; } if (!isAbovePlane(i,vmax)) return false; } return true; }
bool Frustum::isInFrustum | ( | const ngl::Vector & | _point | ) | const |
point check inside frustum
[in] | _point | the point to check |
Definition at line 29 of file Frustum.cpp.
References isAbovePlane().
{ for (unsigned int i=0;i<6;i++) { if (!isAbovePlane(i,_point)) return false; } return true; }
void Frustum::normalizePlane | ( | Plane & | _plane | ) | [private] |
normalise the plane
[inout] | the plane to be normalised |
Definition at line 70 of file Frustum.cpp.
References Frustum::Plane::a, Frustum::Plane::b, Frustum::Plane::c, and Frustum::Plane::d.
{
float mag;
mag = sqrt(_plane.a * _plane.a + _plane.b * _plane.b + _plane.c * _plane.c);
_plane.a = _plane.a / mag;
_plane.b = _plane.b / mag;
_plane.c = _plane.c / mag;
_plane.d = _plane.d / mag;
}
Plane Frustum::m_planes[6] [private] |