Beispiel #1
0
const char*
reset_scene_node( const char *node ) 
{  
    scene_node_t *nodePtr;

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

    make_identity_matrix( nodePtr->trans );
    make_identity_matrix( nodePtr->invtrans );

    return NULL;
}
Beispiel #2
0
bool_t collide(const char *node, polyhedron_t ph )
{
    scene_node_t *nodePtr;
    matrixgl_t mat, invmat;

    make_identity_matrix( mat );
    make_identity_matrix( invmat );

    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 );
    
} 
Beispiel #3
0
Handle<Value> createWindow(const Arguments& args) {
    HandleScope scope;
    int w  = args[0]->ToNumber()->NumberValue();
    int h  = args[1]->ToNumber()->NumberValue();
    width = w;
    height = h;
    if(!glfwOpenWindow(width,height, 8, 8, 8, 0, 24, 8, GLFW_WINDOW)) {
        printf("error. quitting\n");
        glfwTerminate();
        exit(EXIT_FAILURE);        
    }
    
    glfwSetWindowSizeCallback(GLFW_WINDOW_SIZE_CALLBACK_FUNCTION);
    glfwSetWindowCloseCallback(GLFW_WINDOW_CLOSE_CALLBACK_FUNCTION);
    glfwSetMousePosCallback(GLFW_MOUSE_POS_CALLBACK_FUNCTION);
    glfwSetMouseButtonCallback(GLFW_MOUSE_BUTTON_CALLBACK_FUNCTION);
    glfwSetKeyCallback(GLFW_KEY_CALLBACK_FUNCTION);
    
    colorShader = new ColorShader();
    textureShader = new TextureShader();
    fontShader = new FontShader();
    modelView = new GLfloat[16];

    globaltx = new GLfloat[16];
    make_identity_matrix(globaltx);
    

    
    
    glViewport(0,0,width, height);
    return scope.Close(Undefined());
}
Beispiel #4
0
gf2matrix *invert_matrix(gf2matrix *dest, const gf2matrix *m)
{
    if (!m)
        return NULL;
    mzd_t *temp = mzd_inv_m4ri(NULL, (mzd_t*) m, 0);
    if(!temp) {
        dest = NULL;
    }
    else {
        mzd_t *I = make_identity_matrix(m->nrows);
        mzd_t *prod = mul_matrices(NULL, m, temp);
        if(comp_matrices(prod, I) == 0) {
            // inversion was successful
            if (dest) {
                mzd_copy(dest, temp);
                mzd_free(temp);
            }
            else {
                dest = temp;
            }
        }
        else {
            dest = NULL;
        }
        mzd_free(prod);
        mzd_free(I);
    }
    return dest;
}
Beispiel #5
0
static void whittle2 (Array acf, Array Aold, Array Bold, int lag,
		      char *direction, Array A, Array K, Array E)
{

    int d, i, nser=DIM(acf)[1];
    const void *vmax;
    Array beta, tmp, id;

    d = strcmp(direction, "forward") == 0;

    vmax = vmaxget();

    beta = make_zero_matrix(nser,nser);
    tmp = make_zero_matrix(nser, nser);
    id = make_identity_matrix(nser);

    set_array_to_zero(E);
    copy_array(id, subarray(A,0));

    for(i = 0; i < lag; i++) {
       matrix_prod(subarray(acf,lag - i), subarray(Aold,i), d, 1, tmp);
       array_op(beta, tmp, '+', beta);
       matrix_prod(subarray(acf,i), subarray(Bold,i), d, 1, tmp);
       array_op(E, tmp, '+', E);
    }
    qr_solve(E, beta, K);
    transpose_matrix(K,K);
    for (i = 1; i <= lag; i++) {
	matrix_prod(K, subarray(Bold,lag - i), 0, 0, tmp);
	array_op(subarray(Aold,i), tmp, '-', subarray(A,i));
    }

    vmaxset(vmax);
}
Beispiel #6
0
void setup_view_matrix( player_data_t *plyr ) 
{
    vector_t view_x, view_y, view_z;
    matrixgl_t view_mat;
    point_t viewpt_in_view_frame;

    view_z = scale_vector( -1, plyr->view.dir );
    view_x = cross_product( plyr->view.up, view_z );
    view_y = cross_product( view_z, view_x );
    normalize_vector( &view_z );
    normalize_vector( &view_x );
    normalize_vector( &view_y );

    make_identity_matrix( plyr->view.inv_view_mat );

    plyr->view.inv_view_mat[0][0] = view_x.x;
    plyr->view.inv_view_mat[0][1] = view_x.y;
    plyr->view.inv_view_mat[0][2] = view_x.z;

    plyr->view.inv_view_mat[1][0] = view_y.x;
    plyr->view.inv_view_mat[1][1] = view_y.y;
    plyr->view.inv_view_mat[1][2] = view_y.z;

    plyr->view.inv_view_mat[2][0] = view_z.x;
    plyr->view.inv_view_mat[2][1] = view_z.y;
    plyr->view.inv_view_mat[2][2] = view_z.z;

    plyr->view.inv_view_mat[3][0] = plyr->view.pos.x;
    plyr->view.inv_view_mat[3][1] = plyr->view.pos.y;
    plyr->view.inv_view_mat[3][2] = plyr->view.pos.z;
    plyr->view.inv_view_mat[3][3] = 1;
    
    transpose_matrix( plyr->view.inv_view_mat, view_mat );

    view_mat[0][3] = 0;
    view_mat[1][3] = 0;
    view_mat[2][3] = 0;
    
    viewpt_in_view_frame = transform_point( view_mat, plyr->view.pos );
    
    view_mat[3][0] = -viewpt_in_view_frame.x;
    view_mat[3][1] = -viewpt_in_view_frame.y;
    view_mat[3][2] = -viewpt_in_view_frame.z;
    
    glLoadIdentity();
#ifdef __APPLE__DISABLED__
    GLfloat matrix[3][3];
    int i,j;
    for( i = 0; i < 3; i++ )
    {
        for( j = 0; j < 3; j++ )
            matrix[i][j] = view_mat[i][j];
    }
    glMultMatrixf( (GLfloat *) matrix );
#else
    glMultMatrixd( (scalar_t *) view_mat );
#endif

}
Beispiel #7
0
void setup_view_matrix( player_data_t *plyr ) 
{
    GLfloat matrix[4][4];
    int i,j;
    vector_t view_x, view_y, view_z;
    matrixgl_t view_mat;
    point_t viewpt_in_view_frame;

    view_z = scale_vector( -1, plyr->view.dir );
    view_x = cross_product( plyr->view.up, view_z );
    view_y = cross_product( view_z, view_x );
    normalize_vector( &view_z );
    normalize_vector( &view_x );
    normalize_vector( &view_y );

    make_identity_matrix( plyr->view.inv_view_mat );

    plyr->view.inv_view_mat[0][0] = view_x.x;
    plyr->view.inv_view_mat[0][1] = view_x.y;
    plyr->view.inv_view_mat[0][2] = view_x.z;

    plyr->view.inv_view_mat[1][0] = view_y.x;
    plyr->view.inv_view_mat[1][1] = view_y.y;
    plyr->view.inv_view_mat[1][2] = view_y.z;

    plyr->view.inv_view_mat[2][0] = view_z.x;
    plyr->view.inv_view_mat[2][1] = view_z.y;
    plyr->view.inv_view_mat[2][2] = view_z.z;

    plyr->view.inv_view_mat[3][0] = plyr->view.pos.x;
    plyr->view.inv_view_mat[3][1] = plyr->view.pos.y;
    plyr->view.inv_view_mat[3][2] = plyr->view.pos.z;
    plyr->view.inv_view_mat[3][3] = 1;
    
    transpose_matrix( plyr->view.inv_view_mat, view_mat );

    view_mat[0][3] = 0;
    view_mat[1][3] = 0;
    view_mat[2][3] = 0;
    
    viewpt_in_view_frame = transform_point( view_mat, plyr->view.pos );
    
    view_mat[3][0] = -viewpt_in_view_frame.x;
    view_mat[3][1] = -viewpt_in_view_frame.y;
    view_mat[3][2] = -viewpt_in_view_frame.z;
    
    //glLoadIdentity();

	for( i = 0; i < 4; i++ )
    {
        for( j = 0; j < 4; j++ )
            matrix[i][j] = view_mat[i][j];
    }
    util_set_view(matrix);
}
Beispiel #8
0
void make_identity_tbox_mixing_bijections(tbox_mixing_bijections_t tbox_mbs)
{
	int round, row, col;
	for (round = 0; round < NR; ++round) {
		for (row = 0; row < 4; ++row) {
			for (col = 0; col < 4; ++col) {
				tbox_mbs[round][row][col] = make_identity_matrix(8);
			}
		}
	}
}
Beispiel #9
0
/* Creates a new node, add the node to the hash table, and inserts the
   node into the DAG.  Default values are given to all fields except
   the type-specific ones (geom, param).  */
char* create_scene_node( const char *parent_name, const char *child_name, 
			 scene_node_t **node )
{
    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;
    make_identity_matrix( child->trans );
    make_identity_matrix( child->invtrans );

    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;
} 
Beispiel #10
0
static void whittle(Array acf, int nlag, Array *A, Array *B, Array p_forward,
    Array v_forward, Array p_back, Array v_back)
{

    int lag, nser = DIM(acf)[1];
    const void *vmax;
    Array EA, EB;	/* prediction variance */
    Array KA, KB;	/* partial correlation coefficient */
    Array id, tmp;

    vmax = vmaxget();

    KA = make_zero_matrix(nser, nser);
    EA = make_zero_matrix(nser, nser);

    KB = make_zero_matrix(nser, nser);
    EB = make_zero_matrix(nser, nser);

    id = make_identity_matrix(nser);

    copy_array(id, subarray(A[0],0));
    copy_array(id, subarray(B[0],0));
    copy_array(id, subarray(p_forward,0));
    copy_array(id, subarray(p_back,0));

    for (lag = 1; lag <= nlag; lag++) {

	whittle2(acf, A[lag-1], B[lag-1], lag, "forward", A[lag], KA, EB);
	whittle2(acf, B[lag-1], A[lag-1], lag, "back", B[lag], KB, EA);

	copy_array(EA, subarray(v_forward,lag-1));
	copy_array(EB, subarray(v_back,lag-1));

	copy_array(KA, subarray(p_forward,lag));
	copy_array(KB, subarray(p_back,lag));

    }

    tmp = make_zero_matrix(nser,nser);

    matrix_prod(KB,KA, 1, 1, tmp);
    array_op(id, tmp, '-', tmp);
    matrix_prod(EA, tmp, 0, 0, subarray(v_forward, nlag));

    vmaxset(vmax);

}
Beispiel #11
0
void render() {


    for(int j=0; j<updates.size(); j++) {
        updates[j]->apply();
    }
    updates.clear();
    
    GLfloat* scaleM = new GLfloat[16];
    make_scale_matrix(1,-1,1,scaleM);
    //make_scale_matrix(1,1,1,scaleM);
    GLfloat* transM = new GLfloat[16];
    make_trans_matrix(-width/2,height/2,0,transM);
    //make_trans_matrix(10,10,0,transM);
    //make_trans_matrix(0,0,0,transM);
    
    GLfloat* m4 = new GLfloat[16];
    mul_matrix(m4, transM, scaleM); 


    GLfloat* pixelM = new GLfloat[16];
//    loadPixelPerfect(pixelM, width, height, 600, 100, -150);
    loadPixelPerfect(pixelM, width, height, eye, near, far);
    //printf("eye = %f\n",eye);
    //loadPerspectiveMatrix(pixelM, 45, 1, 10, -100);
    
    GLfloat* m5 = new GLfloat[16];
    //transpose(m5,pixelM);
    
    mul_matrix(modelView,pixelM,m4);
    
    
    make_identity_matrix(globaltx);
    glViewport(0,0,width, height);
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glDisable(GL_DEPTH_TEST);
    for(int j=0; j<anims.size(); j++) {
        anims[j]->update();
    }
    AminoNode* root = rects[rootHandle];
    root->draw();
    
    glfwSwapBuffers();
}
Beispiel #12
0
point_t get_tux_view_pt( player_data_t *plyr ) 
{ 
    matrixgl_t trans;
    char *tux_root_node_name;
    scene_node_t *tux_root_node;

    make_identity_matrix( trans );

    tux_root_node_name = get_tux_root_node();

    if ( get_scene_node( tux_root_node_name, &tux_root_node ) != TCL_OK ) {
	check_assertion(0, "couldn't load tux's root node" );
    } 

    traverse_dag_for_view_point( tux_root_node, trans );

    tux_view_pt = move_point( tux_view_pt, 
			      scale_vector( 0.2, plyr->plane_nml ) );

    return tux_view_pt; 
}
Beispiel #13
0
/**
 * \brief
 * return the A(bitsxbits) matrix corresponding to the given rank
 * see Generating Large Non-Singular ...; Jmes Xiao, section 2.
 * @param p number of bits
 * @param r rank
 * @return a matrix A of dims (pxp)
 *
 * For a 2x2 we have:
 *  r=0    r=1    r=2
 * |1 0|  |1 1|  |0 1|
 * |0 1|  |1 0|  |1 1|
 *
 * In general:
 * 1. r = 0 A = I(p,p)
 * 2. r is even:
 * 		 	    | |0 1|                        |
 *              | |1 1|                        |
 *              |      ...(r/2 times           |
 *      A =     |          diagonally)         |
 *              |                              |
 *              |                   I(p-r,p-r) |
 *
 * 3. r is 1:
 * 		 	    | |1 1|           |
 *     A =      | |1 0|           |
 *              |      I(p-2,p-2) |
 *
 * 4. r is odd and > 1:
 *              | |1 1 1|                      |
 *              | |1 1 0|                      |
 *              | |1 0 0|                      |
 * 		 	    |       |0 1|                  |
 *     A =      |       |1 1|                  |
 *              |            ...(n times       |
 *              |            diagonally)       |
 *              |                              |
 *              |                 I(p-2n,p-2n) |
 *    where n = (r - 3) / 2
 */
static gf2matrix *make_A_matrix(int p, int r)
{
	gf2matrix *a;
	if (r == 0) {
		a = make_identity_matrix(p);
	}
	else if (r == 1) {
		gf2matrix *I = make_identity_matrix(p - 2);
		gf2matrix *block = new_matrix(2, 2);
		scalar2matrix(block, 0xE, 4);
		a = new_matrix(p, p);
		clear_matrix(a);
		copy_matrix_to_offset(a, I, 2, 2);
		copy_matrix_to_offset(a, block, 0, 0);
		free_matrix(block);
		free_matrix(I);
	}
	else if ((r % 2) == 0) {
		int i;
		gf2matrix *I = NULL;
		gf2matrix *block = new_matrix(2, 2);
		if (p > r)
			I = make_identity_matrix(p - r);
		scalar2matrix(block, 0xE, 4);
		a = new_matrix(p, p);
		clear_matrix(a);
		if (I)
			copy_matrix_to_offset(a, I, r, r);
		for (i = 0; i < r; i += 2)
			copy_matrix_to_offset(a, block, i, i);
		free_matrix(block);
		free_matrix(I);
	}
	else /*  r is odd and > 1 */
	{
		int i;
		int n;
		gf2matrix *I = NULL;
		gf2matrix *block = NULL;
		n = (r - 3) / 2;
		if (n = 0) {
			a = make_identity_matrix(p);
		}
		else {
			int p_2n = p - (2 * n);
			block = new_matrix(2, 2);
			if (p > r)
				I = make_identity_matrix(p - r);
			scalar2matrix(block, 0xE, 4);
			a = new_matrix(p, p);
			clear_matrix(a);
			if (I)
				copy_matrix_to_offset(a, I, r, r);
			for (i = 0; i < n; ++i) {
				int offset = (i * 2) + 3;
				copy_matrix_to_offset(a, block, offset, offset);
			}
			set_bit_at(a, 1, 0, 0);
			set_bit_at(a, 1, 0, 1);
			set_bit_at(a, 1, 0, 2);
			set_bit_at(a, 1, 1, 1);
			set_bit_at(a, 1, 1, 0);
			set_bit_at(a, 1, 2, 0);
		}
		free_matrix(block);
		free_matrix(I);
	}
	/* print_matrix(a, "A:"); */
	return a;
}
Beispiel #14
0
void update_key_frame( player_data_t *plyr, scalar_t dt )
{
    int idx;
    scalar_t frac;
    point_t pos;
    scalar_t v;
    matrixgl_t cob_mat, rot_mat;

    char *root;
    char *lsh;
    char *rsh;
    char *lhp;
    char *rhp;
    char *lkn;
    char *rkn;
    char *lank;
    char *rank;
    char *head;
    char *neck;
    char *tail;

    root = get_tux_root_node();
    lsh  = get_tux_left_shoulder_joint();
    rsh  = get_tux_right_shoulder_joint();
    lhp  = get_tux_left_hip_joint();
    rhp  = get_tux_right_hip_joint();
    lkn  = get_tux_left_knee_joint();
    rkn  = get_tux_right_knee_joint();
    lank = get_tux_left_ankle_joint();
    rank = get_tux_right_ankle_joint();
    head = get_tux_head();
    neck = get_tux_neck();
    tail = get_tux_tail_joint();

    keyTime += dt;

    for (idx = 1; idx < numFrames; idx ++) {
        if ( keyTime < frames[idx].time )
            break;
    } 

    if ( idx == numFrames || numFrames == 0 ) {
        set_game_mode( RACING );
        return;
    } 

    reset_scene_node( root );
    reset_scene_node( lsh );
    reset_scene_node( rsh );
    reset_scene_node( lhp );
    reset_scene_node( rhp );
    reset_scene_node( lkn );
    reset_scene_node( rkn );
    reset_scene_node( lank );
    reset_scene_node( rank );
    reset_scene_node( head );
    reset_scene_node( neck );
    reset_scene_node( tail );

    check_assertion( idx > 0, "invalid keyframe index" );

    if ( fabs( frames[idx-1].time - frames[idx].time ) < EPS ) {
	frac = 1.;
    } else {
	frac = (keyTime - frames[idx].time) 
	    / ( frames[idx-1].time - frames[idx].time );
    }

    pos.x = interp( frac, frames[idx-1].pos.x, frames[idx].pos.x );
    pos.z = interp( frac, frames[idx-1].pos.z, frames[idx].pos.z );
    pos.y = interp( frac, frames[idx-1].pos.y, frames[idx].pos.y );
    pos.y += find_y_coord( pos.x, pos.z );

    set_tux_pos( plyr, pos );

    make_identity_matrix( cob_mat );

    v = interp( frac, frames[idx-1].yaw, frames[idx].yaw );
    rotate_scene_node( root, 'y', v );
    make_rotation_matrix( rot_mat, v, 'y' );
    multiply_matrices( cob_mat, cob_mat, rot_mat );

    v = interp( frac, frames[idx-1].pitch, frames[idx].pitch );
    rotate_scene_node( root, 'x', v );
    make_rotation_matrix( rot_mat, v, 'x' );
    multiply_matrices( cob_mat, cob_mat, rot_mat );

    v = interp( frac, frames[idx-1].l_shldr, frames[idx].l_shldr );
    rotate_scene_node( lsh, 'z', v );

    v = interp( frac, frames[idx-1].r_shldr, frames[idx].r_shldr );
    rotate_scene_node( rsh, 'z', v );

    v = interp( frac, frames[idx-1].l_hip, frames[idx].l_hip );
    rotate_scene_node( lhp, 'z', v );

    v = interp( frac, frames[idx-1].r_hip, frames[idx].r_hip );
    rotate_scene_node( rhp, 'z', v );

    /* Set orientation */
    plyr->orientation = make_quaternion_from_matrix( cob_mat );
    plyr->orientation_initialized = True;
} 
Beispiel #15
0
static void burg0(int omax, Array resid_f, Array resid_b, Array *A, Array *B,
    Array P, Array V, int vmethod)
{
    int i, j, m, n = NCOL(resid_f), nser=NROW(resid_f);
    Array ss_ff, ss_bb, ss_fb;
    Array resid_f_tmp, resid_b_tmp;
    Array KA, KB, E;
    Array id, tmp;

    ss_ff = make_zero_matrix(nser, nser);
    ss_fb = make_zero_matrix(nser, nser);
    ss_bb = make_zero_matrix(nser, nser);

    resid_f_tmp = make_zero_matrix(nser, n);
    resid_b_tmp = make_zero_matrix(nser, n);

    id    = make_identity_matrix(nser);

    tmp   = make_zero_matrix(nser, nser);

    E = make_zero_matrix(nser, nser);
    KA = make_zero_matrix(nser, nser);
    KB = make_zero_matrix(nser, nser);

    set_array_to_zero(A[0]);
    set_array_to_zero(B[0]);
    copy_array(id, subarray(A[0],0));
    copy_array(id, subarray(B[0],0));

    matrix_prod(resid_f, resid_f, 0, 1, E);
    scalar_op(E, n, '/',  E);
    copy_array(E, subarray(V,0));

    for (m = 0; m < omax; m++) {

	for(i = 0; i < nser; i++) {
	    for (j = n - 1; j > m; j--) {
		MATRIX(resid_b)[i][j] = MATRIX(resid_b)[i][j-1];
	    }
	    MATRIX(resid_f)[i][m] = 0.0;
	    MATRIX(resid_b)[i][m] = 0.0;
	}
	matrix_prod(resid_f, resid_f, 0, 1, ss_ff);
	matrix_prod(resid_b, resid_b, 0, 1, ss_bb);
	matrix_prod(resid_f, resid_b, 0, 1, ss_fb);

	burg2(ss_ff, ss_bb, ss_fb, E, KA, KB);		/* Update K */

	for (i = 0; i <= m + 1; i++) {

	    matrix_prod(KA, subarray(B[m], m + 1 - i), 0, 0, tmp);
	    array_op(subarray(A[m], i), tmp, '-', subarray(A[m+1], i));

	    matrix_prod(KB, subarray(A[m], m + 1 - i), 0, 0, tmp);
	    array_op(subarray(B[m], i), tmp, '-', subarray(B[m+1], i));

	}

	matrix_prod(KA, resid_b, 0, 0, resid_f_tmp);
	matrix_prod(KB, resid_f, 0, 0, resid_b_tmp);
	array_op(resid_f, resid_f_tmp, '-', resid_f);
	array_op(resid_b, resid_b_tmp, '-', resid_b);

	if (vmethod == 1) {
	    matrix_prod(KA, KB, 0, 0, tmp);
	    array_op(id, tmp, '-', tmp);
	    matrix_prod(tmp, E, 0, 0, E);
	}
	else if (vmethod == 2) {
	    matrix_prod(resid_f, resid_f, 0, 1, E);
	    matrix_prod(resid_b, resid_b, 0, 1, tmp);
	    array_op(E, tmp, '+', E);
	    scalar_op(E, 2.0*(n - m - 1), '/', E);
	}
	else error(_("Invalid vmethod"));

	copy_array(E, subarray(V,m+1));
	copy_array(KA, subarray(P,m+1));
    }
}