Back to index

extremetuxracer  0.5beta
Public Member Functions | Public Attributes | Static Public Attributes
model_hndl Class Reference

#include <model_hndl.h>

Collaboration diagram for model_hndl:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 model_hndl ()
void adjust_tux_joints (double turnFact, bool isBraking, double paddling_factor, double speed, pp::Vec3d net_force, double jump_factor)
void load_model (int model)
void load_model ()
void init_models ()
void draw_tux ()
char * get_tux_root_node ()
char * get_tux_left_shoulder_joint ()
char * get_tux_right_shoulder_joint ()
char * get_tux_left_hip_joint ()
char * get_tux_right_hip_joint ()
char * get_tux_left_knee_joint ()
char * get_tux_right_knee_joint ()
char * get_tux_left_ankle_joint ()
char * get_tux_right_ankle_joint ()
char * get_tux_tail_joint ()
char * get_tux_neck ()
char * get_tux_head ()

Public Attributes

std::list< model_tl_models
int num_models
int cur_model

Static Public Attributes

static bool tuxLoaded = false
static char * tuxRootNode
static char * tuxLeftShoulderJoint
static char * tuxRightShoulderJoint
static char * tuxLeftHipJoint
static char * tuxRightHipJoint
static char * tuxLeftKneeJoint
static char * tuxRightKneeJoint
static char * tuxLeftAnkleJoint
static char * tuxRightAnkleJoint
static char * tuxTailJoint
static char * tuxNeck
static char * tuxHead

Detailed Description

Definition at line 35 of file model_hndl.h.


Constructor & Destructor Documentation

Definition at line 164 of file model_hndl.cpp.

                       {
       cur_model=0;
       num_models=0;
}

Member Function Documentation

void model_hndl::adjust_tux_joints ( double  turnFact,
bool  isBraking,
double  paddling_factor,
double  speed,
pp::Vec3d  net_force,
double  jump_factor 
)

Definition at line 59 of file model_hndl.cpp.

{
    double turning_angle[2] = {0., 0.};
    double paddling_angle = 0.;
    double ext_paddling_angle = 0.;  /* arm extension during paddling */
    double kick_paddling_angle = 0.;  /* leg kicking during paddling */
    double braking_angle = 0.;
    double force_angle = 0.; /* amount that legs move because of force */
    double turn_leg_angle = 0.; /* amount legs move when turning */
    double flap_angle = 0.;

    /* move arms */
    reset_scene_node( tuxLeftShoulderJoint );
    reset_scene_node( tuxRightShoulderJoint );

    if ( isBraking ) {
       braking_angle = MAX_ARM_ANGLE;
    }

    paddling_angle = MAX_PADDLING_ANGLE * sin(paddling_factor * M_PI);
    ext_paddling_angle = MAX_EXT_PADDLING_ANGLE * sin(paddling_factor * M_PI);
    kick_paddling_angle = MAX_KICK_PADDLING_ANGLE * 
       sin(paddling_factor * M_PI * 2.0);

    turning_angle[0] = MAX(-turnFact,0.0) * MAX_ARM_ANGLE;
    turning_angle[1] = MAX(turnFact,0.0) * MAX_ARM_ANGLE;

    flap_angle = MAX_ARM_ANGLE * (0.5 + 0.5*sin(M_PI*flap_factor*6-M_PI/2));

    /* Adjust arms for turning */
    rotate_scene_node( tuxLeftShoulderJoint, 'z', 
                     MIN( braking_angle + paddling_angle + turning_angle[0],
                         MAX_ARM_ANGLE ) + flap_angle );
    rotate_scene_node( tuxRightShoulderJoint, 'z',
                     MIN( braking_angle + paddling_angle + turning_angle[1], 
                         MAX_ARM_ANGLE ) + flap_angle );


    /* Adjust arms for paddling */
    rotate_scene_node( tuxLeftShoulderJoint, 'y', -ext_paddling_angle );
    rotate_scene_node( tuxRightShoulderJoint, 'y', ext_paddling_angle );

    force_angle = MAX( -20.0, MIN( 20.0, -net_force.z / 300.0 ) );
    turn_leg_angle = turnFact * 10;
    
       /* Adjust hip joints */
    reset_scene_node( tuxLeftHipJoint );
    rotate_scene_node( tuxLeftHipJoint, 'z', -20 + turn_leg_angle
                     + force_angle );
    reset_scene_node( tuxRightHipJoint );
    rotate_scene_node( tuxRightHipJoint, 'z', -20 - turn_leg_angle
                     + force_angle );
       
    /* Adjust knees */
    reset_scene_node( tuxLeftKneeJoint );
    rotate_scene_node( tuxLeftKneeJoint, 'z', -10 + turn_leg_angle
                     - MIN( 35, speed ) + kick_paddling_angle
                     + force_angle );
    reset_scene_node( tuxRightKneeJoint );
    rotate_scene_node( tuxRightKneeJoint, 'z', -10 - turn_leg_angle
                     - MIN( 35, speed ) - kick_paddling_angle 
                     + force_angle );

    /* Adjust ankles */
    reset_scene_node( tuxLeftAnkleJoint );
    rotate_scene_node( tuxLeftAnkleJoint, 'z', -20 + MIN(50, speed ) );
    reset_scene_node( tuxRightAnkleJoint );
    rotate_scene_node( tuxRightAnkleJoint, 'z', -20 + MIN(50, speed ) );

       /* Turn tail */
    reset_scene_node( tuxTailJoint );
    rotate_scene_node( tuxTailJoint, 'z', turnFact * 20 );

       /* Adjust head and neck */
    reset_scene_node( tuxNeck );
    rotate_scene_node( tuxNeck, 'z', -50 );
    reset_scene_node( tuxHead );
    rotate_scene_node( tuxHead, 'z', -30 );

       /* Turn head when turning */
    rotate_scene_node( tuxHead, 'y', -turnFact * 70 );

}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 146 of file model_hndl.cpp.

{
    GLfloat dummyColor[]  = { 0.0, 0.0, 0.0, 1.0 };

    /* XXX: For some reason, inserting this call here makes Tux render
     * with correct lighting under Mesa 3.1. I'm guessing it's a Mesa bug.
     */
    glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dummyColor );

    set_gl_options( TUX );

    /* Turn on lights
     */
    setup_course_lighting();

    draw_scene_graph( tuxRootNode );
} 

Here is the call graph for this function:

Here is the caller graph for this function:

char* model_hndl::get_tux_head ( ) [inline]

Definition at line 78 of file model_hndl.h.

{ return tuxHead; } 

Here is the caller graph for this function:

Definition at line 74 of file model_hndl.h.

{ return tuxLeftAnkleJoint; } 

Here is the caller graph for this function:

Definition at line 70 of file model_hndl.h.

{ return tuxLeftHipJoint; } 

Here is the caller graph for this function:

Definition at line 72 of file model_hndl.h.

{ return tuxLeftKneeJoint; } 

Here is the caller graph for this function:

Definition at line 68 of file model_hndl.h.

Here is the caller graph for this function:

char* model_hndl::get_tux_neck ( ) [inline]

Definition at line 77 of file model_hndl.h.

{ return tuxNeck; } 

Here is the caller graph for this function:

Definition at line 75 of file model_hndl.h.

{ return tuxRightAnkleJoint; } 

Here is the caller graph for this function:

Definition at line 71 of file model_hndl.h.

{ return tuxRightHipJoint; } 

Here is the caller graph for this function:

Definition at line 73 of file model_hndl.h.

{ return tuxRightKneeJoint; } 

Here is the caller graph for this function:

Definition at line 69 of file model_hndl.h.

Here is the caller graph for this function:

char* model_hndl::get_tux_root_node ( ) [inline]

Definition at line 67 of file model_hndl.h.

{ return tuxRootNode; } 

Here is the caller graph for this function:

char* model_hndl::get_tux_tail_joint ( ) [inline]

Definition at line 76 of file model_hndl.h.

{ return tuxTailJoint; } 

Here is the caller graph for this function:

Definition at line 169 of file model_hndl.cpp.

                             {
       //Load modellist from data/models.tcl
       char buff[BUFF_LEN];
     
       sprintf(buff, "%s/models.tcl", getparam_data_dir());
                     
       registerHierCallbacks( tclInterp );
     register_tux_callbacks( tclInterp );
     
       if ( Tcl_EvalFile( tclInterp , buff ) != TCL_OK) {
              std::cerr << " error evalating model list file " << buff
                            << " : " << Tcl_GetStringResult (tclInterp ) << std::endl;
       }
       
       /*
       *Debug stuff:
       for(std::list<model_t>::iterator it=l_models.begin();it!=l_models.end();++it) {
              std::cout<<(*it).name<<": "<<(*it).filename<<std::endl;
       }
       */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void model_hndl::load_model ( int  model = 0)

Definition at line 199 of file model_hndl.cpp.

{      
    //Loads a model.
    char cwd[BUFF_LEN];
    char buff[BUFF_LEN];


    std::list<model_t>::iterator c_model=l_models.begin();
    if(model!=0) {
       for(int i=0;i<model;i++) {
              c_model++;
       }
    }


    if ( tuxLoaded == true && cur_model==model) 
        return;
    cur_model=model;
    tuxLoaded = true;
    initialize_scene_graph();

    if ( getcwd( cwd, BUFF_LEN ) == NULL ) {
       handle_system_error( 1, "getcwd failed" );
    }
    if ( chdir( getparam_data_dir() ) != 0 ) {
       /* Print a more informative warning since this is a common error */
       handle_system_error( 
           1, "Can't find the etracer data "
           "directory.  Please check the\nvalue of `data_dir' in "
           "~/.etracer/options and set it to the location where you\n"
           "installed the etracer-data files.\n\n"
           "Couldn't chdir to %s", getparam_data_dir() );
       /*
        handle_system_error( 1, "couldn't chdir to %s", getparam_data_dir() );
       */
    } 
    
    
    //std::cout<<"Loading model "<< (*c_model).name<<std::endl;
    if ( Tcl_EvalFile( tclInterp, (*c_model).filename.c_str()) == TCL_ERROR ) {
        handle_error( 1, "error evalating %s/%s: %s\n"
                    "Please check the value of `data_dir' in ~/.etracer/options "
                    "and make sure it\npoints to the location of the "
                    "latest version of the etracer-data files.", 
                    getparam_data_dir(),(*c_model).filename.c_str(),
                    Tcl_GetStringResult( tclInterp ) );
    } 
    check_assertion( !Tcl_InterpDeleted( tclInterp ),
                   "Tcl interpreter deleted" );

    if ( chdir( cwd ) != 0 ) {
       handle_system_error( 1, "couldn't chdir to %s", cwd );
    } 
} 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 192 of file model_hndl.cpp.


Member Data Documentation

Definition at line 42 of file model_hndl.h.

Definition at line 40 of file model_hndl.h.

Definition at line 41 of file model_hndl.h.

char * model_hndl::tuxHead [static]

Definition at line 56 of file model_hndl.h.

Definition at line 52 of file model_hndl.h.

char * model_hndl::tuxLeftHipJoint [static]

Definition at line 48 of file model_hndl.h.

Definition at line 50 of file model_hndl.h.

Definition at line 46 of file model_hndl.h.

bool model_hndl::tuxLoaded = false [static]

Definition at line 44 of file model_hndl.h.

char * model_hndl::tuxNeck [static]

Definition at line 55 of file model_hndl.h.

Definition at line 53 of file model_hndl.h.

Definition at line 49 of file model_hndl.h.

Definition at line 51 of file model_hndl.h.

Definition at line 47 of file model_hndl.h.

char * model_hndl::tuxRootNode [static]

Definition at line 45 of file model_hndl.h.

char * model_hndl::tuxTailJoint [static]

Definition at line 54 of file model_hndl.h.


The documentation for this class was generated from the following files: