DeferredRenderer 1.0

Frustum Class Reference

A generic frustum class that can be generated from any Projview, contains basic point and Bbox culling methods. More...

#include <Frustum.h>

Collaboration diagram for Frustum:

List of all members.

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

Detailed Description

A generic frustum class that can be generated from any Projview, contains basic point and Bbox culling methods.

Definition at line 15 of file Frustum.h.


Member Enumeration Documentation

enum Frustum::planeSides [private]

enum for identifying the 6 sides of the frustum

Enumerator:
e_left 
e_right 
e_bottom 
e_top 
e_near 
e_far 

Definition at line 27 of file Frustum.h.

                   {
        e_left = 0,
        e_right = 1,
        e_bottom = 2,
        e_top = 3,
        e_near = 4,
        e_far = 5
    };
enum Frustum::planeSign [private]

enum used to denote which way the plane is facing

Enumerator:
e_minus 
e_plus 

Definition at line 38 of file Frustum.h.

                  {
        e_minus = -1,
        e_plus = 1
    };

Constructor & Destructor Documentation

Frustum::Frustum ( ) [inline]

empty ctor

Definition at line 59 of file Frustum.h.

{}

Member Function Documentation

void Frustum::buildPlane ( Plane io_plane,
const ngl::Matrix &  _mat,
int  _row,
int  _sign 
) [private]

build a plane

Parameters:
[inout]_plane the plane to buil
[in]_matthe matrix to build it from
[in]_rowthe matrix row to build from
[in]_signthe 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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Frustum::generate ( const ngl::Matrix &  _mat)

method to generate the frustum from a projView matrix

Parameters:
[in]_matthe 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.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Frustum::isAbovePlane ( unsigned int  _planeSide,
const ngl::Vector &  _point 
) const

collision check for a point against a frustum plane

Parameters:
[in]_planeSidethe side of the frustum to check
[in]_pointthe 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;
}

Here is the caller graph for this function:

bool Frustum::isInFrustum ( const ngl::Vector &  _min,
const ngl::Vector &  _max 
) const

bbox check inside frustum

Parameters:
[in]_minthe lower extent of bbox
[in]_maxthe 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;

}

Here is the call graph for this function:

bool Frustum::isInFrustum ( const ngl::Vector &  _point) const

point check inside frustum

Parameters:
[in]_pointthe 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;
}

Here is the call graph for this function:

void Frustum::normalizePlane ( Plane _plane) [private]

normalise the plane

Parameters:
[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;

}

Here is the caller graph for this function:


Member Data Documentation

Plane Frustum::m_planes[6] [private]

the 6 sides of the frustum

Definition at line 44 of file Frustum.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines