Back to index

extremetuxracer  0.5beta
Enumerations | Functions
viewfrustum.h File Reference
#include "pp_types.h"
#include "player.h"
#include "ppgltk/alg/plane.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  clip_result_t { NoClip, SomeClip, NotVisible }

Functions

void setup_view_frustum (Player &plyr, double near, double far)
clip_result_t clip_aabb_to_view_frustum (const pp::Vec3d &min, const pp::Vec3d &max)
 View frustum clipping for AABB (axis-aligned bounding box).
pp::Plane get_far_clip_plane ()
pp::Plane get_left_clip_plane ()
pp::Plane get_right_clip_plane ()
pp::Plane get_bottom_clip_plane ()

Enumeration Type Documentation

Enumerator:
NoClip 
SomeClip 
NotVisible 

Definition at line 31 of file viewfrustum.h.


Function Documentation

clip_result_t clip_aabb_to_view_frustum ( const pp::Vec3d min,
const pp::Vec3d max 
)

View frustum clipping for AABB (axis-aligned bounding box).

See Assarsson, Ulf and Tomas M"oller, "Optimized View Frustum Culling Algorithms", unpublished, http://www.ce.chalmers.se/staff/uffe/ .

Definition at line 115 of file viewfrustum.cpp.

{
    pp::Vec3d n, p;
    clip_result_t intersect = NoClip;

    for (int i=5; i>=0; i--) {
              p = min;
              n = max;
              
              if ( p_vertex_code_x[i]) {
                  p.x = max.x;
                  n.x = min.x;
              }

              if ( p_vertex_code_y[i]) {
                  p.y = max.y;
                  n.y = min.y;
              }

              if ( p_vertex_code_z[i]) {
                  p.z = max.z;
                  n.z = min.z;
              }

              if ( DOT_PRODUCT( n, frustum_planes[i].nml ) +
                   frustum_planes[i].d > 0 )
              {
                  return NotVisible;
              }

              if ( DOT_PRODUCT( p, frustum_planes[i].nml ) +
                   frustum_planes[i].d > 0 )
              {
                     intersect = SomeClip;
              }

    }  
    return intersect;
}

Here is the caller graph for this function:

Definition at line 170 of file viewfrustum.cpp.

{
    return frustum_planes[5];
}

Here is the caller graph for this function:

Definition at line 155 of file viewfrustum.cpp.

{
    return frustum_planes[1];
}

Here is the caller graph for this function:

Definition at line 160 of file viewfrustum.cpp.

{
    return frustum_planes[2];
}

Here is the caller graph for this function:

Definition at line 165 of file viewfrustum.cpp.

{
    return frustum_planes[3];
}

Here is the caller graph for this function:

void setup_view_frustum ( Player plyr,
double  near,
double  far 
)

Definition at line 42 of file viewfrustum.cpp.

{
    double aspect = (double) getparam_x_resolution() /
       getparam_y_resolution();

    int i;
    pp::Vec3d pt;
    pp::Vec3d origin(0., 0., 0.);
    double half_fov = ANGLES_TO_RADIANS( getparam_fov() * 0.5 );
    double half_fov_horiz = atan( tan( half_fov ) * aspect ); 


    /* create frustum in viewing coordinates */

    /* near */
    frustum_planes[0] = pp::Plane(0, 0, 1, near_dist);
    
    /* far */
    frustum_planes[1] = pp::Plane(0, 0, -1, -far_dist);

    /* left */
    frustum_planes[2] = pp::Plane( -cos(half_fov_horiz), 0, 
                                sin(half_fov_horiz), 0 );

    /* right */
    frustum_planes[3] = pp::Plane( cos(half_fov_horiz), 0, 
                                sin(half_fov_horiz), 0 );

    /* top */
    frustum_planes[4] = pp::Plane( 0, cos(half_fov),  
                                sin(half_fov), 0 );

    /* bottom */
    frustum_planes[5] = pp::Plane( 0, -cos(half_fov),  
                                sin(half_fov), 0 );


    /* We now transform frustum to world coordinates */
    for (i=0; i<6; i++) {
       pt = plyr.view.inv_view_mat.transformPoint(
           origin + (-frustum_planes[i].d*frustum_planes[i].nml) );

       frustum_planes[i].nml = plyr.view.inv_view_mat.transformVector( frustum_planes[i].nml );

       frustum_planes[i].d = -( 
           frustum_planes[i].nml*
           (pt-origin));
    }

    for (i=0; i<6; i++) {
              p_vertex_code_x[i] = false;
              p_vertex_code_y[i] = false;
              p_vertex_code_z[i] = false;
              
              
       if ( frustum_planes[i].nml.x > 0 ) {
              p_vertex_code_x[i] = true;
       }
       if ( frustum_planes[i].nml.y > 0 ) {
              p_vertex_code_y[i] = true;
       }
       if ( frustum_planes[i].nml.z > 0 ) {
              p_vertex_code_z[i] = true;
       }

       
    }
}

Here is the call graph for this function:

Here is the caller graph for this function: