Back to index

extremetuxracer  0.5beta
Functions | Variables
hier.cpp File Reference
#include "hier.h"
#include "hier_util.h"
#include "game_config.h"
#include "ppgltk/alg/defs.h"

Go to the source code of this file.

Functions

static int add_scene_node (const char *parent_name, const char *node_name, scene_node_t *node)
int get_scene_node (const char *node_name, scene_node_t **node)
int add_material (const char *mat_name, material_t *mat)
int get_material (const char *mat_name, material_t **mat)
char * create_scene_node (const char *parent_name, const char *child_name, scene_node_t **node)
char * reset_scene_node (char *node)
char * rotate_scene_node (const char *node, char axis, double angle)
char * translate_scene_node (const char *node, pp::Vec3d vec)
char * scale_scene_node (const char *node, pp::Vec3d center, double factor[3])
char * transform_scene_node (char *node, pp::Matrix mat, pp::Matrix invmat)
char * set_scene_node_material (const char *node, const char *mat)
char * set_scene_node_shadow_state (const char *node, const char *state)
char * set_scene_node_eye (const char *node, const char *which_eye)
char * create_tranform_node (const char *parent_name, const char *child_name)
char * create_sphere_node (const char *parent_name, const char *child_name, double resolution)
char * create_material (const char *mat, pp::Color diffuse, pp::Color specular, double specular_exp)
void initialize_scene_graph ()
void draw_scene_graph (char *node)
bool collide (char *node, pp::Polyhedron ph)

Variables

Tcl_HashTable g_hier_node_table
Tcl_HashTable g_hier_material_table
material_t g_hier_default_material

Function Documentation

int add_material ( const char *  mat_name,
material_t mat 
)

Definition at line 105 of file hier.cpp.

{
    Tcl_HashEntry *entry;
    int newEntry;

    entry = Tcl_CreateHashEntry(&g_hier_material_table,mat_name,&newEntry);
    if (newEntry) {
        Tcl_SetHashValue(entry, mat);
    } else {
        return TCL_ERROR;
    }

    return TCL_OK;
}

Here is the caller graph for this function:

static int add_scene_node ( const char *  parent_name,
const char *  node_name,
scene_node_t node 
) [static]

Definition at line 53 of file hier.cpp.

{
    Tcl_HashEntry *entry;
    int newEntry;
    char new_name[1024];

    /* Add the current node to the hash table 
    */
    if (0 == strcmp(parent_name,":")) {
        sprintf(new_name, ":%s", node_name);
    } else {
        sprintf(new_name, "%s:%s", parent_name, node_name);
    }

    node->name = (char*)malloc( strlen(new_name) + 1 );
    node->name = strcpy(node->name, new_name);

    entry = Tcl_CreateHashEntry(&g_hier_node_table,new_name,&newEntry);

    if (newEntry) { 
        Tcl_SetHashValue(entry, node);
    } else {
        return TCL_ERROR;
    }

    return TCL_OK;
}

Here is the caller graph for this function:

bool collide ( char *  node,
pp::Polyhedron  ph 
)

Definition at line 439 of file hier.cpp.

{
    scene_node_t *nodePtr;
    pp::Matrix mat, invmat;

    mat.makeIdentity();
    invmat.makeIdentity();

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        handle_error( 1, "draw_scene_graph: No such node `%s'", node );
    } 

    return check_polyhedron_collision_with_dag( nodePtr, mat, invmat, ph );
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* create_material ( const char *  mat,
pp::Color  diffuse,
pp::Color  specular,
double  specular_exp 
)

Definition at line 380 of file hier.cpp.

{
    material_t *matPtr;

    matPtr = (material_t *)malloc( sizeof( material_t ) );

    matPtr->diffuse.r = diffuse.r;
    matPtr->diffuse.g = diffuse.g;
    matPtr->diffuse.b = diffuse.b;
    matPtr->diffuse.a = 1.0;

    matPtr->specular.r = specular.r;
    matPtr->specular.g = specular.g;
    matPtr->specular.b = specular.b;
    matPtr->specular.a = 1.0;

    matPtr->specular_exp = specular_exp;

    if ( add_material( mat, matPtr ) != TCL_OK ) {
        free( matPtr );
        return "Material already exists";
    } 

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* create_scene_node ( const char *  parent_name,
const char *  child_name,
scene_node_t **  node 
)

Definition at line 139 of file hier.cpp.

{
    scene_node_t *parent, *child;
    if ( get_scene_node( parent_name, &parent ) != TCL_OK ) {
        return "Parent node does not exist";
    } 

    /* Create node */
    child = (scene_node_t *)malloc( sizeof( scene_node_t ) );

    /* Initialize node */
    child->parent = parent;
    child->next = NULL;
    child->child = NULL;
    child->mat = NULL;
    child->render_shadow = true;
    child->eye = false;
    child->trans.makeIdentity();
    child->invtrans.makeIdentity();

    if ( add_scene_node( parent_name, child_name, child ) != TCL_OK ) {
        free( child );
        return "Child already exists";
    } 


    /* Add node to parent's children */
    if ( parent != NULL ) {
        if ( parent->child == NULL ) {
            parent->child = child;
        } else {
            for (parent = parent->child; parent->next != NULL; 
                 parent = parent->next) {/* do nothing */}
            parent->next = child;
        } 
    } 

    *node = child;
    return NULL;
} 

Here is the call graph for this function:

Here is the caller graph for this function:

char* create_sphere_node ( const char *  parent_name,
const char *  child_name,
double  resolution 
)

Definition at line 358 of file hier.cpp.

{
    scene_node_t *node;
    char *msg;

    msg = create_scene_node(parent_name, child_name, &node);
    if ( msg != NULL ) {
        return msg;
    } 

    node->geom = Sphere;
    node->param.sphere.radius = 1.0;
    node->param.sphere.divisions = MIN( 
       MAX_SPHERE_DIVISIONS, MAX( 
           MIN_SPHERE_DIVISIONS, 
           ROUND_TO_NEAREST( getparam_tux_sphere_divisions() * resolution ) 
           ) );

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* create_tranform_node ( const char *  parent_name,
const char *  child_name 
)

Definition at line 342 of file hier.cpp.

{
    scene_node_t *node;
    char *msg;

    msg = create_scene_node(parent_name, child_name, &node);
    if ( msg != NULL ) {
        return msg;
    } 

    node->geom = Empty;

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_scene_graph ( char *  node)

Definition at line 427 of file hier.cpp.

{
    scene_node_t *nodePtr;

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        handle_error( 1, "draw_scene_graph: No such node `%s'", node );
    } 

    traverse_dag( nodePtr, &g_hier_default_material );
    
} 

Here is the call graph for this function:

Here is the caller graph for this function:

int get_material ( const char *  mat_name,
material_t **  mat 
)

Definition at line 122 of file hier.cpp.

{
    Tcl_HashEntry *entry;

    entry = Tcl_FindHashEntry(&g_hier_material_table, mat_name);
    if (0 == entry) {
        return TCL_ERROR;
    } else {
        *mat = (material_t*)Tcl_GetHashValue(entry);
    }

    return TCL_OK;
}

Here is the caller graph for this function:

int get_scene_node ( const char *  node_name,
scene_node_t **  node 
)

Definition at line 83 of file hier.cpp.

{
    Tcl_HashEntry *entry;
  
    entry = Tcl_FindHashEntry(&g_hier_node_table, node_name);
    if (0 == entry) {
        if(0 == strcmp(node_name, ":")) {
            /* the root has been specified 
             */
            *node = 0;
        } else {
            return TCL_ERROR;
        }
    } else {
        *node = (scene_node_t*)Tcl_GetHashValue(entry);
    }

    return TCL_OK;
}

Here is the caller graph for this function:

Definition at line 407 of file hier.cpp.

Here is the caller graph for this function:

char* reset_scene_node ( char *  node)

Definition at line 182 of file hier.cpp.

{  
    scene_node_t *nodePtr;

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        return "No such node";
    } 

    nodePtr->trans.makeIdentity();
    nodePtr->invtrans.makeIdentity();

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* rotate_scene_node ( const char *  node,
char  axis,
double  angle 
)

Definition at line 197 of file hier.cpp.

{
    scene_node_t *nodePtr;
    pp::Matrix rotMatrix;

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        return "No such node";
    } 

    rotMatrix.makeRotation( angle, axis );
    nodePtr->trans=nodePtr->trans*rotMatrix;
       
    rotMatrix.makeRotation( -angle, axis );
    nodePtr->invtrans=rotMatrix*nodePtr->invtrans;

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* scale_scene_node ( const char *  node,
pp::Vec3d  center,
double  factor[3] 
)

Definition at line 235 of file hier.cpp.

{
    scene_node_t *nodePtr;
    pp::Matrix matrix;

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        return "No such node";
    } 

    matrix.makeTranslation( -center.x, -center.y, -center.z );
    nodePtr->trans=nodePtr->trans*matrix;
       
    matrix.makeTranslation( center.x, center.y, center.z );
    nodePtr->invtrans=matrix*nodePtr->invtrans;

    matrix.makeScaling( factor[0], factor[1], factor[2] );
    nodePtr->trans=nodePtr->trans*matrix;
       
    matrix.makeScaling( 1./factor[0], 1./factor[1], 1./factor[2] );
    nodePtr->invtrans=matrix*nodePtr->invtrans;

    matrix.makeTranslation( center.x, center.y, center.z );
    nodePtr->trans=nodePtr->trans*matrix;
       
    matrix.makeTranslation( -center.x, -center.y, -center.z );
    nodePtr->invtrans=matrix*nodePtr->invtrans;

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* set_scene_node_eye ( const char *  node,
const char *  which_eye 
)

Definition at line 320 of file hier.cpp.

{
    scene_node_t *nodePtr;

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        return "No such node";
    } 

    if ( strcmp( which_eye, "right" ) == 0 ) {
       nodePtr->eye = true;
       nodePtr->which_eye = TuxRightEye;
    } else if ( strcmp ( which_eye, "left" ) == 0 ) {
       nodePtr->eye = true;
       nodePtr->which_eye = TuxLeftEye;
    } else {
       return "'eye' must be right or left";
    }

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* set_scene_node_material ( const char *  node,
const char *  mat 
)

Definition at line 281 of file hier.cpp.

{
    material_t *matPtr;
    scene_node_t *nodePtr;

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        return "No such node";
    } 

    if ( get_material( mat, &matPtr ) != TCL_OK ) {
        return "No such material";
    } 

    nodePtr->mat = matPtr;

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* set_scene_node_shadow_state ( const char *  node,
const char *  state 
)

Definition at line 300 of file hier.cpp.

{
    scene_node_t *nodePtr;

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        return "No such node";
    } 

    if ( strcmp( state, "off" ) == 0 ) {
       nodePtr->render_shadow = false;
    } else if ( strcmp ( state, "on" ) == 0 ) {
       nodePtr->render_shadow = true;
    } else {
       return "Shadow state must be 'on' or 'off'";
    }

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* transform_scene_node ( char *  node,
pp::Matrix  mat,
pp::Matrix  invmat 
)

Definition at line 266 of file hier.cpp.

{
    scene_node_t *nodePtr;

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        return "No such node";
    } 

    nodePtr->trans=nodePtr->trans*mat;
    nodePtr->invtrans=invmat*nodePtr->invtrans;

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* translate_scene_node ( const char *  node,
pp::Vec3d  vec 
)

Definition at line 216 of file hier.cpp.

{
    scene_node_t *nodePtr;
    pp::Matrix xlateMatrix;

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        return "No such node";
    } 

    xlateMatrix.makeTranslation( vec.x, vec.y, vec.z );
       nodePtr->trans=nodePtr->trans*xlateMatrix;
       
    xlateMatrix.makeTranslation( -vec.x, -vec.y, -vec.z );
    nodePtr->invtrans=xlateMatrix*nodePtr->invtrans;

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
{ 
                            pp::Color(0., 0., 1.),  
                            pp::Color(0., 0., 0.),  
                            0.0              
                     }

Definition at line 41 of file hier.cpp.

Tcl_HashTable g_hier_material_table

Definition at line 32 of file hier.cpp.

Tcl_HashTable g_hier_node_table

Definition at line 31 of file hier.cpp.