Back to index

extremetuxracer  0.5beta
Defines | Functions
phys_sim.h File Reference
#include "course_load.h"
#include "player.h"
#include "ppgltk/alg/plane.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define EARTH_GRAV   9.81
#define M_PER_SEC_TO_KM_PER_H   3.6
#define KM_PER_H_TO_M_PER_SEC   ( 1.0 / M_PER_SEC_TO_KM_PER_H )
#define MAX_PADDLING_SPEED   ( 60.0 * KM_PER_H_TO_M_PER_SEC )
#define JUMP_FORCE_DURATION   0.20

Functions

void set_wind_velocity (pp::Vec3d velocity, float scale)
void increment_turn_fact (Player &plyr, float amt)
void set_friction_coeff (const float fric[3])
float get_min_y_coord ()
pp::Vec3d find_course_normal (const float x, const float z)
float find_y_coord (float x, float z)
void get_surface_type (float x, float z, float weights[])
pp::Plane get_local_course_plane (pp::Vec3d pt)
float get_compression_depth (const int terrain)
void set_tux_pos (Player &plyr, pp::Vec3d newPos)
void update_player_pos (Player &plyr, float dtime)
void init_physical_simulation ()

Define Documentation

#define EARTH_GRAV   9.81

Definition at line 32 of file phys_sim.h.

#define JUMP_FORCE_DURATION   0.20

Definition at line 42 of file phys_sim.h.

Definition at line 36 of file phys_sim.h.

#define M_PER_SEC_TO_KM_PER_H   3.6

Definition at line 34 of file phys_sim.h.

#define MAX_PADDLING_SPEED   ( 60.0 * KM_PER_H_TO_M_PER_SEC )

Definition at line 39 of file phys_sim.h.


Function Documentation

pp::Vec3d find_course_normal ( const float  x,
const float  z 
)

Definition at line 454 of file phys_sim.cpp.

{
    pp::Vec3d *course_nmls;
    pp::Vec3d tri_nml;
    float xidx, yidx;
    int nx, ny;
    int x0, x1, y0, y1;
    pp::Vec3d p0, p1, p2;
    Index2d idx0, idx1, idx2;
    pp::Vec3d n0, n1, n2;
    float course_width, course_length;
    float u, v;
    float min_bary, interp_factor;
    pp::Vec3d smooth_nml;
    pp::Vec3d interp_nml;
    float *elevation;

    elevation = get_course_elev_data();
    get_course_dimensions( &course_width, &course_length );
    get_course_divisions( &nx, &ny );
    course_nmls = get_course_normals();

    get_indices_for_point( x, z, &x0, &y0, &x1, &y1 );
    
    xidx = x / course_width * ( (float) nx - 1. );
    yidx = -z / course_length * ( (float) ny - 1. );

    find_barycentric_coords( x, z, &idx0, &idx1, &idx2, &u, &v );

    n0 = course_nmls[ idx0.i + nx * idx0.j ];
    n1 = course_nmls[ idx1.i + nx * idx1.j ];
    n2 = course_nmls[ idx2.i + nx * idx2.j ];

    p0 = COURSE_VERTEX( idx0.i, idx0.j );
    p1 = COURSE_VERTEX( idx1.i, idx1.j );
    p2 = COURSE_VERTEX( idx2.i, idx2.j );
    
    smooth_nml = (u*n0)+(v*n1+( 1.-u-v)*n2);

    tri_nml = (p1-p0)^(p2-p0);
    tri_nml.normalize();

    min_bary = MIN( u, MIN( v, 1. - u - v ) );
    interp_factor = MIN( min_bary / NORMAL_INTERPOLATION_LIMIT, 1.0 );

    interp_nml = (interp_factor*tri_nml)+
       ((1.-interp_factor)*smooth_nml);
    interp_nml.normalize();

    return interp_nml;
}

Here is the call graph for this function:

Here is the caller graph for this function:

float find_y_coord ( float  x,
float  z 
)

Definition at line 506 of file phys_sim.cpp.

{
    float ycoord;
    pp::Vec3d p0, p1, p2;
    Index2d idx0, idx1, idx2;
    float u, v;
    int nx, ny;
    float *elevation;
    float course_width, course_length;

    /* cache last request */
    static float last_x, last_z, last_y;
    static bool cache_full = false;

    if ( cache_full && last_x == x && last_z == z ) {
       return last_y;
    }

    get_course_divisions( &nx, &ny );
    get_course_dimensions( &course_width, &course_length );
    elevation = get_course_elev_data();

    find_barycentric_coords( x, z, &idx0, &idx1, &idx2, &u, &v );

    p0 = COURSE_VERTEX( idx0.i, idx0.j );
    p1 = COURSE_VERTEX( idx1.i, idx1.j );
    p2 = COURSE_VERTEX( idx2.i, idx2.j );

    ycoord = u * p0.y + v * p1.y + ( 1. - u - v ) * p2.y;

    last_x = x;
    last_z = z;
    last_y = ycoord;
    cache_full = true;

    return ycoord;
} 

Here is the call graph for this function:

Here is the caller graph for this function:

float get_compression_depth ( const int  terrain)

Definition at line 830 of file phys_sim.cpp.

Here is the caller graph for this function:

Definition at line 573 of file phys_sim.cpp.

{
    pp::Plane plane;

    pt.y = find_y_coord( pt.x, pt.z );

    plane.nml = find_course_normal( pt.x, pt.z );
    plane.d = -( plane.nml.x * pt.x + 
               plane.nml.y * pt.y +
               plane.nml.z * pt.z );

    return plane;
}

Here is the call graph for this function:

Here is the caller graph for this function:

float get_min_y_coord ( )

Definition at line 302 of file phys_sim.cpp.

{
    float courseWidth, courseLength;
    float angle;
    float minY;

    get_course_dimensions( &courseWidth, &courseLength );
    angle = get_course_angle();

    minY = -courseLength * tan( ANGLES_TO_RADIANS( angle ) );
    return minY;
} 

Here is the call graph for this function:

void get_surface_type ( float  x,
float  z,
float  weights[] 
)

Definition at line 544 of file phys_sim.cpp.

{
    int *terrain;
    float courseWidth, courseLength;
    int nx, ny;
    Index2d idx0, idx1, idx2;
    float u, v;
    unsigned int i;

    find_barycentric_coords( x, z, &idx0, &idx1, &idx2, &u, &v );

    terrain = get_course_terrain_data();
    get_course_dimensions( &courseWidth, &courseLength );
    get_course_divisions( &nx, &ny );

    for (i=0; i<num_terrains; i++) {
       weights[i] = 0;
       if ( terrain[ idx0.i + nx*idx0.j ] == int(i) ) {
           weights[i] += u;
       }
       if ( terrain[ idx1.i + nx*idx1.j ] == int(i) ) {
           weights[i] += v;
       }
       if ( terrain[ idx2.i + nx*idx2.j ] == int(i) ) {
           weights[i] += 1.0 - u - v;
       }
    }
} 

Here is the call graph for this function:

Here is the caller graph for this function:

void increment_turn_fact ( Player plyr,
float  amt 
)

Definition at line 1774 of file phys_sim.cpp.

{
    pp::Vec3d nml;
    pp::Matrix rotMat;
    float ycoord;
    Player* plyr;
    pp::Vec3d init_vel;
    pp::Vec3d init_f;
    int i;

    for ( i=0; i<gameMgr->numPlayers; i++ ) {
              plyr = &players[i];

       ycoord = find_y_coord( plyr->pos.x, plyr->pos.z );
       nml = find_course_normal(plyr->pos.x, plyr->pos.z );
       rotMat.makeRotation( -90., 'x' );
       init_vel = rotMat.transformVector( nml );
       init_vel = INIT_TUX_SPEED*init_vel;
       init_f = pp::Vec3d( 0., 0., 0. );

       plyr->pos.y = ycoord;
       plyr->vel = init_vel;
       plyr->net_force = init_f;
       plyr->control.turn_fact = 0.0;
       plyr->control.turn_animation = 0.0;
       plyr->control.barrel_roll_factor = 0.0;
       plyr->control.flip_factor = 0.0;
       plyr->control.is_braking = false;
       plyr->orientation_initialized = false;
       plyr->plane_nml = nml;
       plyr->direction = init_vel;
       plyr->normal_force = pp::Vec3d(0,0,0);
       plyr->airborne = false;
       plyr->collision = false;
       plyr->control.jump_amt = 0;
       plyr->control.is_paddling = false;
       plyr->control.jumping = false;
       plyr->control.jump_charging = false;
       plyr->control.barrel_roll_left = false;
       plyr->control.barrel_roll_right = false;
       plyr->control.barrel_roll_factor = 0;
       plyr->control.front_flip = false;
       plyr->control.back_flip = false;
    }

    ode_time_step = -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_friction_coeff ( const float  fric[3])

Definition at line 294 of file phys_sim.cpp.

{
    fricCoeff[0] = fric[0];
    fricCoeff[1] = fric[1];
    fricCoeff[2] = fric[2];
       fricCoeff[3] = fric[3];
} 

Here is the caller graph for this function:

void set_tux_pos ( Player plyr,
pp::Vec3d  newPos 
)

Definition at line 597 of file phys_sim.cpp.

{
    char *tuxRoot;
    float playWidth, playLength;
    float courseWidth, courseLength;
    float boundaryWidth;
    float disp_y;

    get_play_dimensions( &playWidth, &playLength );
    get_course_dimensions( &courseWidth, &courseLength );
    boundaryWidth = ( courseWidth - playWidth ) / 2; 


    if ( new_pos.x < boundaryWidth ) {
        new_pos.x = boundaryWidth;
    } else if ( new_pos.x > courseWidth - boundaryWidth ) {
        new_pos.x = courseWidth - boundaryWidth;
    } 

    if ( new_pos.z > 0 ) {
        new_pos.z = 0;
    } else if ( -new_pos.z >= playLength ) {
        new_pos.z = -playLength;
        set_game_mode( GAME_OVER );
    } 

    plyr.pos = new_pos;

    disp_y = new_pos.y + TUX_Y_CORRECTION_ON_STOMACH; 

    tuxRoot = ModelHndl->get_tux_root_node();
    reset_scene_node( tuxRoot );
    translate_scene_node( tuxRoot, 
                       pp::Vec3d( new_pos.x, disp_y, new_pos.z ) );
} 

Here is the call graph for this function:

Here is the caller graph for this function:

void set_wind_velocity ( pp::Vec3d  velocity,
float  scale 
)

Definition at line 277 of file phys_sim.cpp.

{
       wind_vel = velocity;
       wind_scale = scale;                                            
}

Here is the caller graph for this function:

void update_player_pos ( Player plyr,
float  dtime 
)

Definition at line 1712 of file phys_sim.cpp.

{
    pp::Vec3d surf_nml;   /* normal vector of terrain */
    pp::Vec3d tmp_vel;
    float speed;
    float paddling_factor; 
    pp::Vec3d local_force;
    float flap_factor;
    pp::Plane surf_plane;
    float dist_from_surface;

    if ( dtime > 2. * EPS ) {
       solve_ode_system( plyr, dtime );
    }

    tmp_vel = plyr.vel;

    /*
     * Set position, orientation, generate particles
     */
    surf_plane = get_local_course_plane( plyr.pos );
    surf_nml = surf_plane.nml;
    dist_from_surface = surf_plane.distance( plyr.pos );
    adjust_velocity( &plyr.vel, plyr.pos, surf_plane, 
                   dist_from_surface );
    adjust_position( &plyr.pos, surf_plane, dist_from_surface );

    speed = tmp_vel.normalize();

    set_tux_pos( plyr, plyr.pos );
    adjust_orientation( plyr, dtime, plyr.pos, plyr.vel, 
                     dist_from_surface, surf_nml );

    flap_factor = 0;

    if ( plyr.control.is_paddling ) {
       double factor;
       factor = (gameMgr->time - plyr.control.paddle_time) / PADDLING_DURATION;
       if ( plyr.airborne ) {
           paddling_factor = 0;
           flap_factor = factor;
       } else {
           paddling_factor = factor;
           flap_factor = 0;
       }
    } else {
       paddling_factor = 0.0;
    }

    /* calculate force in Tux's local coordinate system */
    local_force = plyr.orientation.conjugate().rotate(plyr.net_force);

    if (plyr.control.jumping) {
       flap_factor = (gameMgr->time - plyr.control.jump_start_time) / 
           JUMP_FORCE_DURATION;
    } 

    ModelHndl->adjust_tux_joints( plyr.control.turn_animation, plyr.control.is_braking,
                     paddling_factor, speed, local_force, flap_factor );
}

Here is the call graph for this function:

Here is the caller graph for this function: