Back to index

extremetuxracer  0.5beta
Functions
tux_shadow.h File Reference
#include "pp_types.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void draw_tux_shadow ()
void traverse_dag_for_shadow (scene_node_t *node, pp::Matrix model_matrix)
void draw_shadow_sphere (pp::Matrix model_matrix)
void draw_shadow_vertex (double x, double y, double z, pp::Matrix model_matrix)

Function Documentation

void draw_shadow_sphere ( pp::Matrix  model_matrix)

Definition at line 87 of file tux_shadow.cpp.

{
    double theta, phi, d_theta, d_phi, eps, twopi;
    double x, y, z;
    int div = getparam_tux_shadow_sphere_divisions();
    
    eps = 1e-15;
    twopi = M_PI * 2.0;

    d_theta = d_phi = M_PI / div;

    for ( phi = 0.0; phi + eps < M_PI; phi += d_phi ) {
       double cos_theta, sin_theta;
       double sin_phi, cos_phi;
       double sin_phi_d_phi, cos_phi_d_phi;

       sin_phi = sin( phi );
       cos_phi = cos( phi );
       sin_phi_d_phi = sin( phi + d_phi );
       cos_phi_d_phi = cos( phi + d_phi );
        
        if ( phi <= eps ) {

            glBegin( GL_TRIANGLE_FAN );
              draw_shadow_vertex( 0., 0., 1., model_matrix );

                for ( theta = 0.0; theta + eps < twopi; theta += d_theta ) {
                  sin_theta = sin( theta );
                  cos_theta = cos( theta );

                    x = cos_theta * sin_phi_d_phi;
                  y = sin_theta * sin_phi_d_phi;
                    z = cos_phi_d_phi;
                  draw_shadow_vertex( x, y, z, model_matrix );
                } 

              x = sin_phi_d_phi;
              y = 0.0;
              z = cos_phi_d_phi;
              draw_shadow_vertex( x, y, z, model_matrix );
            glEnd();

        } else if ( phi + d_phi + eps >= M_PI ) {
            
            glBegin( GL_TRIANGLE_FAN );
              draw_shadow_vertex( 0., 0., -1., model_matrix );

                for ( theta = twopi; theta - eps > 0; theta -= d_theta ) {
                  sin_theta = sin( theta );
                  cos_theta = cos( theta );

                    x = cos_theta * sin_phi;
                    y = sin_theta * sin_phi;
                    z = cos_phi;
                  draw_shadow_vertex( x, y, z, model_matrix );
                } 
                x = sin_phi;
                y = 0.0;
                z = cos_phi;
              draw_shadow_vertex( x, y, z, model_matrix );
            glEnd();

        } else {
            
            glBegin( GL_TRIANGLE_STRIP );
                
                for ( theta = 0.0; theta + eps < twopi; theta += d_theta ) {
                  sin_theta = sin( theta );
                  cos_theta = cos( theta );

                    x = cos_theta * sin_phi;
                    y = sin_theta * sin_phi;
                    z = cos_phi;
                  draw_shadow_vertex( x, y, z, model_matrix );

                    x = cos_theta * sin_phi_d_phi;
                    y = sin_theta * sin_phi_d_phi;
                    z = cos_phi_d_phi;
                  draw_shadow_vertex( x, y, z, model_matrix );
                } 
                x = sin_phi;
                y = 0.0;
                z = cos_phi;
              draw_shadow_vertex( x, y, z, model_matrix );

                x = sin_phi_d_phi;
                y = 0.0;
                z = cos_phi_d_phi;
              draw_shadow_vertex( x, y, z, model_matrix );

            glEnd();

        } 
    } 

} 

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_shadow_vertex ( double  x,
double  y,
double  z,
pp::Matrix  model_matrix 
)

Definition at line 184 of file tux_shadow.cpp.

{
    pp::Vec3d pt;
    double old_y;
    pp::Vec3d nml;

    pt = pp::Vec3d( x, y, z );
    pt = model_matrix.transformPoint( pt );

    old_y = pt.y;
    
    nml = find_course_normal( pt.x, pt.z );
    pt.y = find_y_coord( pt.x, pt.z ) + SHADOW_HEIGHT;

    if ( pt.y > old_y ) 
       pt.y = old_y;

    glNormal3f( nml.x, nml.y, nml.z );
    glVertex3f( pt.x, pt.y, pt.z );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_tux_shadow ( )

Definition at line 33 of file tux_shadow.cpp.

{
    if ( ! getparam_draw_tux_shadow() ) 
       return;
       
       pp::Matrix model_matrix;
    char *tux_root_node_name;
    scene_node_t *tux_root_node;
              
    set_gl_options( TUX_SHADOW ); 
       
       /* 
       * Make the shadow darker if the stencil buffer is active 
       */
       
       if(getparam_stencil_buffer()){
       glColor4f( 0.0,0.0,0.0,0.3 );
       }else{
       glColor4f( 0.0,0.0,0.0,0.1 );
       }
       
    model_matrix.makeIdentity();

    tux_root_node_name = ModelHndl->get_tux_root_node();

    if ( get_scene_node( tux_root_node_name, &tux_root_node ) != TCL_OK ) {
       check_assertion( 0, "couldn't find tux's root node" );
    } 

    traverse_dag_for_shadow( tux_root_node, model_matrix );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void traverse_dag_for_shadow ( scene_node_t node,
pp::Matrix  model_matrix 
)

Definition at line 65 of file tux_shadow.cpp.

{
    pp::Matrix new_model_matrix;
    scene_node_t *child;

    check_assertion( node != NULL, "node is NULL" );

    new_model_matrix=model_matrix*node->trans;

    if ( node->geom == Sphere && node->render_shadow ) {
       draw_shadow_sphere( new_model_matrix );
    } 

    child = node->child;
    while (child != NULL) {

        traverse_dag_for_shadow(child, new_model_matrix);

        child = child->next;
    } 
}

Here is the call graph for this function:

Here is the caller graph for this function: