Back to index

extremetuxracer  0.5beta
Functions | Variables
lights.cpp File Reference
#include "lights.h"
#include "gl_util.h"
#include "tcl_util.h"

Go to the source code of this file.

Functions

light_tget_course_lights ()
void reset_lights ()
void setup_course_lighting ()
static int course_light_cb (ClientData cd, Tcl_Interp *ip, int argc, CONST84 char **argv)
void register_course_light_callbacks (Tcl_Interp *ip)

Variables

static light_t course_lights [NUM_COURSE_LIGHTS]

Function Documentation

static int course_light_cb ( ClientData  cd,
Tcl_Interp *  ip,
int  argc,
CONST84 char **  argv 
) [static]

Definition at line 91 of file lights.cpp.

{
    int light_num;
    double tmp_arr[4];
    double tmp_dbl;
    bool error = false;
    
    if (argc < 3) {
       error = true;
    }

    NEXT_ARG;

    if ( Tcl_GetInt( ip, *argv, &light_num ) == TCL_ERROR ) {
       error = true;
    }

    if ( light_num < 0 || light_num >= NUM_COURSE_LIGHTS ) {
       error = true;
    }

    NEXT_ARG;

    while ( !error && argc > 0 ) {
       if ( strcmp( "-on", *argv ) == 0 ) {
           course_lights[light_num].is_on = true;
       } else if ( strcmp( "-off", *argv ) == 0 ) {
           course_lights[light_num].is_on = false;
       } else if ( strcmp( "-ambient", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( get_tcl_tuple ( ip, *argv, tmp_arr, 4 ) == TCL_ERROR ) {
              error = true;
              break;
           }
           copy_to_glfloat_array( course_lights[light_num].ambient, 
                               tmp_arr, 4 );
       } else if ( strcmp( "-diffuse", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( get_tcl_tuple ( ip, *argv, tmp_arr, 4 ) == TCL_ERROR ) {
              error = true;
              break;
           }
           copy_to_glfloat_array( course_lights[light_num].diffuse, 
                               tmp_arr, 4 );
       } else if ( strcmp( "-specular", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( get_tcl_tuple ( ip, *argv, tmp_arr, 4 ) == TCL_ERROR ) {
              error = true;
              break;
           }
           copy_to_glfloat_array( course_lights[light_num].specular, 
                               tmp_arr, 4 );
       } else if ( strcmp( "-position", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( get_tcl_tuple ( ip, *argv, tmp_arr, 4 ) == TCL_ERROR ) {
              error = true;
              break;
           }
           copy_to_glfloat_array( course_lights[light_num].position, 
                               tmp_arr, 4 );
       } else if ( strcmp( "-spot_direction", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( get_tcl_tuple ( ip, *argv, tmp_arr, 3 ) == TCL_ERROR ) {
              error = true;
              break;
           }
           copy_to_glfloat_array( course_lights[light_num].spot_direction, 
                               tmp_arr, 3 );
       } else if ( strcmp( "-spot_exponent", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( Tcl_GetDouble ( ip, *argv, &tmp_dbl ) == TCL_ERROR ) {
              error = true;
              break;
           }
           course_lights[light_num].spot_exponent = tmp_dbl;
       } else if ( strcmp( "-spot_cutoff", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( Tcl_GetDouble ( ip, *argv, &tmp_dbl ) == TCL_ERROR ) {
              error = true;
              break;
           }
           course_lights[light_num].spot_cutoff = tmp_dbl;
       } else if ( strcmp( "-constant_attenuation", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( Tcl_GetDouble ( ip, *argv, &tmp_dbl ) == TCL_ERROR ) {
              error = true;
              break;
           }
           course_lights[light_num].constant_attenuation = tmp_dbl;
       } else if ( strcmp( "-linear_attenuation", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( Tcl_GetDouble ( ip, *argv, &tmp_dbl ) == TCL_ERROR ) {
              error = true;
              break;
           }
           course_lights[light_num].linear_attenuation = tmp_dbl;
       } else if ( strcmp( "-quadratic_attenuation", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( Tcl_GetDouble ( ip, *argv, &tmp_dbl ) == TCL_ERROR ) {
              error = true;
              break;
           }
           course_lights[light_num].quadratic_attenuation = tmp_dbl;
       } else {
           print_warning( TCL_WARNING, "tux_course_light: unrecognized "
                        "parameter `%s'", *argv );
       }

       NEXT_ARG;
    }

    if ( error ) {
       print_warning( TCL_WARNING, "error in call to tux_course_light" );
       Tcl_AppendResult(
           ip, 
           "\nUsage: tux_course_light <light_number> [-on|-off] "
           "[-ambient { r g b a }] "
           "[-diffuse { r g b a }] "
           "[-specular { r g b a }] "
           "[-position { x y z w }] "
           "[-spot_direction { x y z }] "
           "[-spot_exponent <value>] "
           "[-spot_cutoff <value>] "
           "[-constant_attenuation <value>] "
           "[-linear_attenuation <value>] "
           "[-quadratic_attenuation <value>] ",
           (char *) 0 );
       return TCL_ERROR;
    }
    
    return TCL_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 28 of file lights.cpp.

                             { 
    return course_lights; 
}

Here is the caller graph for this function:

void register_course_light_callbacks ( Tcl_Interp *  ip)

Definition at line 265 of file lights.cpp.

{
    Tcl_CreateCommand (ip, "tux_course_light", course_light_cb, 0,0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void reset_lights ( )

Definition at line 33 of file lights.cpp.

{
    int i;
    GLfloat black[] = { 0., 0., 0., 1. };
    for (i=0; i<NUM_COURSE_LIGHTS; i++) {
       /* Note: we initialize the lights to default OpenGL values
           EXCEPT that light 0 isn't treated differently than the
           others */
       course_lights[i].is_on = false;
       init_glfloat_array( 4, course_lights[i].ambient, 0., 0., 0., 1. );
       init_glfloat_array( 4, course_lights[i].diffuse, 0., 0., 0., 1. );
       init_glfloat_array( 4, course_lights[i].specular, 0., 0., 0., 1. );
       init_glfloat_array( 4, course_lights[i].position, 0., 0., 1., 0. );
       init_glfloat_array( 3, course_lights[i].spot_direction, 0., 0., -1. );
       course_lights[i].spot_exponent = 0.0;
       course_lights[i].spot_cutoff = 180.0;
       course_lights[i].constant_attenuation = 1.0;
       course_lights[i].linear_attenuation = 0.0;
       course_lights[i].quadratic_attenuation = 0.0;
    }

    /* Turn off global ambient light */
    glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 58 of file lights.cpp.

{
    int i;
    light_t *course_lights;

    course_lights = get_course_lights();

    for (i=0; i<NUM_COURSE_LIGHTS; i++) {
       if ( ! course_lights[i].is_on ) {
           glDisable( GL_LIGHT0 + i );
           continue;
       }
       glEnable( GL_LIGHT0 + i );

       glLightfv( GL_LIGHT0 + i, GL_AMBIENT, course_lights[i].ambient );
       glLightfv( GL_LIGHT0 + i, GL_DIFFUSE, course_lights[i].diffuse );
       glLightfv( GL_LIGHT0 + i, GL_SPECULAR, course_lights[i].specular );
       glLightfv( GL_LIGHT0 + i, GL_POSITION, course_lights[i].position );
       glLightfv( GL_LIGHT0 + i, GL_SPOT_DIRECTION, 
                 course_lights[i].spot_direction );
       glLightf( GL_LIGHT0 + i, GL_SPOT_EXPONENT, 
                course_lights[i].spot_exponent );
       glLightf( GL_LIGHT0 + i, GL_SPOT_CUTOFF, 
                course_lights[i].spot_cutoff );
       glLightf( GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 
                course_lights[i].constant_attenuation );
       glLightf( GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, 
                course_lights[i].linear_attenuation );
       glLightf( GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, 
                course_lights[i].quadratic_attenuation );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 26 of file lights.cpp.