Back to index

extremetuxracer  0.5beta
Functions
track_marks.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 init_track_marks (void)
void draw_track_marks (void)
void add_track_mark (Player &plyr)
void break_track_marks (void)

Function Documentation

void add_track_mark ( Player plyr)

Definition at line 670 of file track_marks.cpp.

{
    pp::Vec3d width_vector;
    pp::Vec3d left_vector;
    pp::Vec3d right_vector;
    float magnitude;
    track_quad_t *q, *qprev, *qprevprev;
    pp::Vec3d vel;
    float speed;
    pp::Vec3d left_wing, right_wing;
    float left_y, right_y;
    float dist_from_surface;
    pp::Plane surf_plane;
    float comp_depth;
    float tex_end;
    float terrain_weights[NUM_TERRAIN_TYPES];
    float dist_from_last_mark;
    pp::Vec3d vector_from_last_mark;
       bool break_marks;
       float terrain_compression=0;
       float old_terrain_weight=0;
       unsigned int i;

    if (getparam_track_marks() == false) {
       return;
    }
    
    add_crack(plyr);

    q = &track_marks.quads[track_marks.current_mark%MAX_TRACK_MARKS];
    qprev = &track_marks.quads[(track_marks.current_mark-1)%MAX_TRACK_MARKS];
    qprevprev = &track_marks.quads[(track_marks.current_mark-2)%MAX_TRACK_MARKS];

    vector_from_last_mark = plyr.pos - track_marks.last_mark_pos;
    dist_from_last_mark = vector_from_last_mark.normalize();
       
       
    get_surface_type(plyr.pos.x, plyr.pos.z, terrain_weights);
    
       break_marks=true;
       for (i=0;i<num_terrains;i++){
              if (terrain_texture[i].trackmark.mark !=0){      
                     if (terrain_weights[i] >= 0.5) {
                            if (old_terrain_weight < terrain_weights[i]) {
                                   break_marks=false;
                                   terrain_compression = get_compression_depth(i);
                                   q->terrain=i;
                                   old_terrain_weight = terrain_weights[i];
                            }
              }
              }
       }
       
       if (break_marks==true){
              break_track_marks();
              return;
       }

    vel = plyr.vel;
    speed = vel.normalize();
    if (speed < SPEED_TO_START_TRENCH) {
       break_track_marks();
       return;
    }

    width_vector = plyr.direction^pp::Vec3d( 0, 1, 0 );
    magnitude = width_vector.normalize();
    if ( magnitude == 0 ) {
       break_track_marks();
       return;
    }

    left_vector = (TRACK_WIDTH/2.0)*width_vector;
    right_vector = (-TRACK_WIDTH/2.0)*width_vector;
    left_wing =  plyr.pos - left_vector;
    right_wing = plyr.pos - right_vector;
    left_y = find_y_coord( left_wing.x, left_wing.z );
    right_y = find_y_coord( right_wing.x, right_wing.z );
    if (fabs(left_y-right_y) > MAX_TRACK_DEPTH) {
       break_track_marks();
       return;
    }

    surf_plane = get_local_course_plane( plyr.pos );
    dist_from_surface = surf_plane.distance( plyr.pos );
    comp_depth = terrain_compression;
    if ( dist_from_surface >= (2*comp_depth) ) {
       break_track_marks();
       return;
    }

    if (!continuing_track) {
       break_track_marks();
       q->track_type = TRACK_HEAD;
       q->v1 = pp::Vec3d( left_wing.x, left_y + TRACK_HEIGHT, left_wing.z );
       q->v2 = pp::Vec3d( right_wing.x, right_y + TRACK_HEIGHT, right_wing.z );
       q->n1 = find_course_normal( q->v1.x, q->v1.z);
       q->n2 = find_course_normal( q->v2.x, q->v2.z);
       q->t1 = pp::Vec2d(0.0, 0.0);
       q->t2 = pp::Vec2d(1.0, 0.0);
       track_marks.next_mark = track_marks.current_mark + 1;
    } else {
       if ( track_marks.next_mark == track_marks.current_mark ) {
           q->v1 = qprev->v3;
           q->v2 = qprev->v4;
           q->n1 = qprev->n3;
           q->n2 = qprev->n4;
           q->t1 = qprev->t3; 
           q->t2 = qprev->t4;
           if ( qprev->track_type != TRACK_HEAD ) {
              qprev->track_type = TRACK_MARK;
           }
           q->track_type = TRACK_MARK;
       }
       q->v3 = pp::Vec3d( left_wing.x, left_y + TRACK_HEIGHT, left_wing.z );
       q->v4 = pp::Vec3d( right_wing.x, right_y + TRACK_HEIGHT, right_wing.z );
       q->n3 = find_course_normal( q->v3.x, q->v3.z);
       q->n4 = find_course_normal( q->v4.x, q->v4.z);
       tex_end = speed*gameMgr->getTimeStep()/TRACK_WIDTH;
       if (q->track_type == TRACK_HEAD) {
           q->t3= pp::Vec2d(0.0, 1.0);
           q->t4= pp::Vec2d(1.0, 1.0);
       } else {
           q->t3 = pp::Vec2d(0.0, q->t1.y + tex_end);
           q->t4 = pp::Vec2d(1.0, q->t2.y + tex_end);
       }

#ifdef TRACK_TRIANGLES
       add_tri_tracks_from_quad(q);
#endif
       track_marks.current_mark++;
       track_marks.next_mark = track_marks.current_mark;
    }

    q->alpha = MIN( (2*comp_depth-dist_from_surface)/(4*comp_depth), 1.0 );
              
    track_marks.last_mark_time = gameMgr->time;
    continuing_track = true;

}

Here is the call graph for this function:

Here is the caller graph for this function:

void break_track_marks ( void  )

Definition at line 650 of file track_marks.cpp.

{
    track_quad_t *qprev, *qprevprev;
    qprev = &track_marks.quads[(track_marks.current_mark-1)%MAX_TRACK_MARKS];
    qprevprev = &track_marks.quads[(track_marks.current_mark-2)%MAX_TRACK_MARKS];

    if (track_marks.current_mark > 0) {
       qprev->track_type = TRACK_TAIL;
       qprev->t1 = pp::Vec2d(0.0, 0.0);
       qprev->t2 = pp::Vec2d(1.0, 0.0);
       qprev->t3 = pp::Vec2d(0.0, 1.0);
       qprev->t4 = pp::Vec2d(1.0, 1.0);
       qprevprev->t3.y = MAX((int)(qprevprev->t3.y+0.5), (int)(qprevprev->t1.y+1));
       qprevprev->t4.y = MAX((int)(qprevprev->t3.y+0.5), (int)(qprevprev->t1.y+1));
    }
    track_marks.last_mark_time = -99999;
    track_marks.last_mark_pos = pp::Vec3d(-9999, -9999, -9999);
    continuing_track = false;
}

Here is the caller graph for this function:

void draw_track_marks ( void  )

Definition at line 428 of file track_marks.cpp.

{
#ifdef TRACK_TRIANGLES
    draw_tri_tracks();
#else
    //GLuint texid[NUM_TRACK_TYPES];
    int current_quad, num_quads;
    int first_quad;
    track_quad_t *q, *qnext;
    pp::Color trackColor = pp::Color::white;

    if (getparam_track_marks() == false) {
              return;
    }

    set_gl_options( TRACK_MARKS ); 

    glColor4f( 0, 0, 0, 1);

    //get_texture_binding( "track_head", &texid[TRACK_HEAD] );
    //get_texture_binding( "track_mark", &texid[TRACK_MARK] );
    //get_texture_binding( "track_tail", &texid[TRACK_TAIL] );

    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
    set_material( pp::Color::white, pp::Color::black, 1.0 );
    setup_course_lighting();

    num_quads = MIN( track_marks.current_mark, MAX_TRACK_MARKS -
                   track_marks.next_mark + track_marks.current_mark );
    first_quad = track_marks.current_mark - num_quads;

    for ( current_quad = 0;
         current_quad < num_quads;
         current_quad++ ) 
    {
       q = &track_marks.quads[(first_quad + current_quad)%MAX_TRACK_MARKS];

       trackColor.a = q->alpha;
       set_material( trackColor, pp::Color::black, 1.0 );

       //glBindTexture( GL_TEXTURE_2D, texid[q->track_type] );
       
       switch (q->track_type){
              case TRACK_HEAD:
                     glBindTexture( GL_TEXTURE_2D, terrain_texture[q->terrain].trackmark.head);
                     break;
              case TRACK_MARK:
                     glBindTexture( GL_TEXTURE_2D, terrain_texture[q->terrain].trackmark.mark);
                     break;
              case TRACK_TAIL:
                     glBindTexture( GL_TEXTURE_2D, terrain_texture[q->terrain].trackmark.tail);
                     break;        
              default:
                     glBindTexture( GL_TEXTURE_2D, terrain_texture[q->terrain].trackmark.mark);
                     break; 
       }

       if ((q->track_type == TRACK_HEAD) || (q->track_type == TRACK_TAIL)) { 
           glBegin(GL_QUADS);
           
           glNormal3f( q->n1.x, q->n1.y, q->n1.z );
           glTexCoord2f( q->t1.x, q->t1.y );
           glVertex3f( q->v1.x, q->v1.y, q->v1.z );
       
           glNormal3f( q->n2.x, q->n2.y, q->n2.z );
           glTexCoord2f( q->t2.x, q->t2.y );
           glVertex3f( q->v2.x, q->v2.y, q->v2.z );

           glNormal3f( q->n4.x, q->n4.y, q->n4.z );
           glTexCoord2f( q->t4.x, q->t4.y );
           glVertex3f( q->v4.x, q->v4.y, q->v4.z );
       
           glNormal3f( q->n3.x, q->n3.y, q->n3.z );
           glTexCoord2f( q->t3.x, q->t3.y );
           glVertex3f( q->v3.x, q->v3.y, q->v3.z );
       
           glEnd();

       } else {
             
           glBegin(GL_QUAD_STRIP);

           glNormal3f( q->n2.x, q->n2.y, q->n2.z );
           glTexCoord2f( q->t2.x, q->t2.y );
           glVertex3f( q->v2.x, q->v2.y, q->v2.z );

           glNormal3f( q->n1.x, q->n1.y, q->n1.z );
           glTexCoord2f( q->t1.x, q->t1.y );
           glVertex3f( q->v1.x, q->v1.y, q->v1.z );

           glNormal3f( q->n4.x, q->n4.y, q->n4.z );
           glTexCoord2f( q->t4.x, q->t4.y );
           glVertex3f( q->v4.x, q->v4.y, q->v4.z );

           glNormal3f( q->n3.x, q->n3.y, q->n3.z );
           glTexCoord2f( q->t3.x, q->t3.y );
           glVertex3f( q->v3.x, q->v3.y, q->v3.z );
              glEnd();
              glBegin(GL_QUADS);
              
           qnext = &track_marks.quads[(first_quad+current_quad+1)%MAX_TRACK_MARKS];
           while (( qnext->track_type == TRACK_MARK ) && (current_quad+1 < num_quads)) {
              current_quad++;
              
              if (q->terrain != qnext->terrain){
                     glEnd();
                     glBindTexture( GL_TEXTURE_2D, terrain_texture[qnext->terrain].trackmark.mark);
                     glBegin(GL_QUADS);          
              }
                            
              q = &track_marks.quads[(first_quad+current_quad)%MAX_TRACK_MARKS];
              trackColor.a = qnext->alpha;
              set_material( trackColor, pp::Color::black, 1.0 );
              

           glNormal3f( q->n1.x, q->n1.y, q->n1.z );
           glTexCoord2f( q->t1.x, q->t1.y );
           glVertex3f( q->v1.x, q->v1.y, q->v1.z );
              
              glNormal3f( q->n2.x, q->n2.y, q->n2.z );
           glTexCoord2f( q->t2.x, q->t2.y );
           glVertex3f( q->v2.x, q->v2.y, q->v2.z );     
              
              
                     
              glNormal3f( q->n4.x, q->n4.y, q->n4.z );
              glTexCoord2f( q->t4.x, q->t4.y );
              glVertex3f( q->v4.x, q->v4.y, q->v4.z );

              glNormal3f( q->n3.x, q->n3.y, q->n3.z );
              glTexCoord2f( q->t3.x, q->t3.y );
              glVertex3f( q->v3.x, q->v3.y, q->v3.z );
              
              qnext = &track_marks.quads[(first_quad+current_quad+1)%MAX_TRACK_MARKS];
           }
           glEnd();
       }

    }
#endif

    draw_cracks();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void init_track_marks ( void  )

Definition at line 353 of file track_marks.cpp.

{
    if(gameMgr->doesRaceHaveToBeRetried()) {
    //do nothing, since we want to keep last try's tracks
    } else {

        track_marks.current_mark = 0;
        track_marks.next_mark = 0;
        track_marks.last_mark_time = -99999;
        track_marks.last_mark_pos = pp::Vec3d(-9999, -9999, -9999);
        continuing_track = false;
#ifdef TRACK_TRIANGLES
        track_tris.first_mark = 0;
        track_tris.next_mark = 0;
        track_tris.num_tris = 0;
#endif
        cracks.current_crack = 0;
        cracks.last_pos = pp::Vec3d(-9999, -9999, -9999);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function: