Back to index

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

Go to the source code of this file.

Functions

void create_new_particles (pp::Vec3d loc, pp::Vec3d vel, int num, GLuint particle_binding)
void update_particles (double time_step)
void clear_particles ()
void reset_particles ()
void draw_particles (Player &plyr)
void register_particle_callbacks (Tcl_Interp *ip)

Variables

GLfloat particleColor [4]

Function Documentation

void clear_particles ( )

Definition at line 210 of file part_sys.cpp.

{
    Particle *p, *q;

    p = head;
    for (;;) {
        if (p == NULL ) break;
        q=p;
        p=p->next;
        free(q);
    } 
    head = NULL;
    num_particles = 0;
}

Here is the caller graph for this function:

void create_new_particles ( pp::Vec3d  loc,
pp::Vec3d  vel,
int  num,
GLuint  particle_binding 
)

Definition at line 71 of file part_sys.cpp.

{
    Particle *newp;
    int i;
    double speed;

    speed = vel.normalize();

    /* Debug check to track down infinite particle bug */
    if ( num_particles + num > MAX_PARTICLES ) {
       check_assertion( 0, "maximum number of particles exceeded" );
    } 

    for (i=0; i<num; i++) {

        newp = (Particle*)malloc( sizeof( Particle) );

        if ( newp == NULL ) {
            handle_system_error( 1, "out of memory" );
        } 

        num_particles += 1;

        newp->next = head;
        head = newp;

        newp->pt.x = loc.x + 2.*(frand() - 0.5) * START_RADIUS;
        newp->pt.y = loc.y;
        newp->pt.z = loc.z + 2.*(frand() - 0.5) * START_RADIUS;

       newp->type = (int) (frand() * (4.0 - EPS));
              
       //get_texture_binding( "snow_particle", &(newp->particle_binding) );  
       newp->particle_binding = particle_binding;       
       
       newp->base_size = ( frand() + 0.5 ) * OLD_PART_SIZE;
       newp->cur_size = NEW_PART_SIZE;

        newp->age = frand() * MIN_AGE;
        newp->death = frand() * MAX_AGE;


        newp->vel =(speed*vel)+
           pp::Vec3d( VARIANCE_FACTOR * (frand() - 0.5) * speed, 
                      VARIANCE_FACTOR * (frand() - 0.5) * speed,
                      VARIANCE_FACTOR * (frand() - 0.5) * speed  );
    }
} 

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_particles ( Player plyr)

Definition at line 157 of file part_sys.cpp.

{
    Particle *p;
    //GLuint   texture_id;
    //char *binding;
    pp::Vec2d min_tex_coord, max_tex_coord;

    set_gl_options( PARTICLES );

 /*
       binding = "snow_particle";
    if (!get_texture_binding( "snow_particle", &texture_id ) ) {
       print_warning( IMPORTANT_WARNING,
                     "Couldn't get texture for binding %s", 
                     binding );
       texture_id = 0;
       } 
 */

    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

    //glBindTexture( GL_TEXTURE_2D, texture_id );
       
    for (p=head; p!=NULL; p = p->next) {
        if ( p->age < 0 ) continue;
       glBindTexture( GL_TEXTURE_2D, p->particle_binding);
       if ( p->type == 0 || p->type == 1 ) {
           min_tex_coord.y = 0;
           max_tex_coord.y = 0.5;
       } else {
           min_tex_coord.y = 0.5;
           max_tex_coord.y = 1.0;
       }

       if ( p->type == 0 || p->type == 3 ) {
           min_tex_coord.x = 0;
           max_tex_coord.x = 0.5;
       } else {
           min_tex_coord.x = 0.5;
           max_tex_coord.x = 1.0;
       }

       glColor4f( particleColor[0], 
                 particleColor[1], 
                 particleColor[2],
                 particleColor[3] * p->alpha );

       draw_billboard( plyr, p->pt, p->cur_size, p->cur_size,
                     false, min_tex_coord, max_tex_coord );
    } 

} 

Here is the call graph for this function:

Here is the caller graph for this function:

void register_particle_callbacks ( Tcl_Interp *  ip)

Definition at line 303 of file part_sys.cpp.

{
    Tcl_CreateCommand (ip, "tux_particle_color", particle_color_cb,  0,0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void reset_particles ( )

Definition at line 225 of file part_sys.cpp.

                       {
    particleColor[0] = 1.0;
    particleColor[1] = 1.0;
    particleColor[2] = 1.0;
    particleColor[3] = 1.0;
} 

Here is the caller graph for this function:

void update_particles ( double  time_step)

Definition at line 120 of file part_sys.cpp.

{
    Particle **p, *q;
    double ycoord;

    for (p = &head; *p != NULL; ) {
        (**p).age += time_step;

        if ( (**p).age < 0 ) continue;

       (**p).pt = ( (**p).pt)+(time_step*(**p).vel );

       ycoord = find_y_coord( (**p).pt.x, (**p).pt.z );

       if ( (**p).pt.y < ycoord - 3 ) {
           (**p).age = (**p).death + 1;
       } 

        if ( (**p).age >= (**p).death ) {
            q = *p;
            *p = q->next;
            free(q);
            num_particles -= 1;
            continue;
        } 

        (**p).alpha = ( (**p).death - (**p).age ) / (**p).death;

       (**p).cur_size = NEW_PART_SIZE + 
           ( OLD_PART_SIZE - NEW_PART_SIZE ) * ( (**p).age / (**p).death );

        (**p).vel.y += -EARTH_GRAV * time_step;

        p = &( (**p).next );
    } 
} 

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

GLfloat particleColor[4]

Definition at line 47 of file part_sys.cpp.