Back to index

extremetuxracer  0.5beta
Defines | Functions | Variables
course_quad.cpp File Reference
#include "course_load.h"
#include "quadtree.h"
#include "ppgltk/alg/defs.h"

Go to the source code of this file.

Defines

#define CULL_DETAIL_FACTOR   25

Functions

void reset_course_quadtree ()
static int get_root_level (int nx, int nz)
static void Vec3fo_float_array (float dest[3], pp::Vec3d src)
void init_course_quadtree (float *elevation, int nx, int nz, double scalex, double scalez, pp::Vec3d view_pos, double detail)
void update_course_quadtree (const pp::Vec3d view_pos, const float detail)
void render_course_quadtree ()

Variables

static quadsquareroot = (quadsquare*) NULL
static quadcornerdata root_corner_data = { (quadcornerdata*)NULL }

Define Documentation

#define CULL_DETAIL_FACTOR   25

Definition at line 27 of file course_quad.cpp.


Function Documentation

static int get_root_level ( int  nx,
int  nz 
) [static]

Definition at line 39 of file course_quad.cpp.

{
    int xlev, zlev;

    check_assertion( nx > 0, "heightmap has x dimension of 0 size" );
    check_assertion( nz > 0, "heightmap has z dimension of 0 size" );

    xlev = (int) ( log((double) nx ) / log ((double) 2.0 ) );
    zlev = (int) ( log((double) nz ) / log ((double) 2.0 ) );

    /* Check to see if nx, nz are powers of 2 
     */

    if ( ( nx >> xlev ) << xlev == nx ) {
       /* do nothing */
    } else {
       nx += 1;
    }

    if ( ( nz >> zlev ) << zlev == nz ) {
       /* do nothing */
    } else {
       nz += 1;
    }

    return MAX( xlev, zlev );
}

Here is the caller graph for this function:

void init_course_quadtree ( float *  elevation,
int  nx,
int  nz,
double  scalex,
double  scalez,
pp::Vec3d  view_pos,
double  detail 
)

Definition at line 75 of file course_quad.cpp.

{
    HeightMapInfo hm;
    int i;

    hm.Data = elevation;
    hm.XOrigin = 0;
    hm.ZOrigin = 0;
    hm.XSize = nx;
    hm.ZSize = nz;
    hm.RowWidth = hm.XSize;
    hm.Scale = 0;

    root_corner_data.Square = (quadsquare*)NULL;
    root_corner_data.ChildIndex = 0;
    root_corner_data.Level = get_root_level( nx, nz );
    root_corner_data.xorg = 0;
    root_corner_data.zorg = 0;

    for (i=0; i<4; i++) {
       root_corner_data.Verts[i] = 0;
       root_corner_data.Verts[i] = 0;
    }

    root = new quadsquare( &root_corner_data );

    root->AddHeightMap( root_corner_data, hm );
    root->SetScale( scalex, scalez );
    root->SetTerrain( get_course_terrain_data() );

    // Debug info.
    //print_debug( DEBUG_QUADTREE, "nodes = %d\n", root->CountNodes());
    print_debug( DEBUG_QUADTREE, "max error = %g\n", 
               root->RecomputeError(root_corner_data));

    // Get rid of unnecessary nodes in flat-ish areas.
    print_debug( DEBUG_QUADTREE, 
               "Culling unnecessary nodes (detail factor = %d)...\n",
               CULL_DETAIL_FACTOR);
    root->StaticCullData(root_corner_data, CULL_DETAIL_FACTOR);

    // Post-cull debug info.
    print_debug( DEBUG_QUADTREE, "nodes = %d\n", root->CountNodes());
    print_debug( DEBUG_QUADTREE, "max error = %g\n", 
               root->RecomputeError(root_corner_data));


    // Run the update function a few times before we start rendering
    // to disable unnecessary quadsquares, so the first frame won't
    // be overloaded with tons of triangles.

    float ViewerLoc[3];
    Vec3fo_float_array( ViewerLoc, view_pos );

    for (i = 0; i < 10; i++) {
       root->Update(root_corner_data, (const float*) ViewerLoc, 
                   detail);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 147 of file course_quad.cpp.

{
    GLubyte *vnc_array;

    get_gl_arrays( &vnc_array );

    root->Render( root_corner_data, vnc_array );
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 33 of file course_quad.cpp.

{
    delete root;
    root = (quadsquare*)NULL;
}

Here is the caller graph for this function:

void update_course_quadtree ( const pp::Vec3d  view_pos,
const float  detail 
)

Definition at line 138 of file course_quad.cpp.

{
    float ViewerLoc[3];

    Vec3fo_float_array( ViewerLoc, view_pos );

    root->Update( root_corner_data, ViewerLoc, detail );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void Vec3fo_float_array ( float  dest[3],
pp::Vec3d  src 
) [static]

Definition at line 67 of file course_quad.cpp.

{
    dest[0] = src.x;
    dest[1] = src.y;
    dest[2] = src.z;
}

Here is the caller graph for this function:


Variable Documentation

quadsquare* root = (quadsquare*) NULL [static]

Definition at line 29 of file course_quad.cpp.

Definition at line 30 of file course_quad.cpp.