Update of /cvsroot/artoolkit/artoolkit/examples/paddleDemo
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21131
Modified Files:
command_sub.h command_sub.c paddle.c paddleDemo.c
Log Message:
Fix some build warnings.
Index: command_sub.c
===================================================================
RCS file: /cvsroot/artoolkit/artoolkit/examples/paddleDemo/command_sub.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** command_sub.c 22 Nov 2004 03:37:35 -0000 1.1
--- command_sub.c 2 Dec 2004 00:47:43 -0000 1.2
***************
*** 1,276 ****
! #ifdef _WIN32
! #include <windows.h>
! #endif
! #include <stdio.h>
! #include <stdlib.h>
! #include <string.h>
! #include <math.h>
! #include <AR/param.h>
! #include <AR/matrix.h>
! #include <AR/ar.h>
! #include "paddle.h"
! #include "command_sub.h"
! #include "util.h"
!
!
! #define SHAKE_BUF_SIZE 10
! #define PUNCH_BUF_SIZE 5
! #define PUSH_BUF_SIZE 2
!
! typedef struct {
! double mat[3][4];
! int f;
! } SHAKE_BUF_T;
!
! typedef struct {
! double x, y, z;
! int f;
! } PUNCH_BUF_T;
!
! typedef struct {
! double x, y, z;
! int f;
! } PUSH_BUF_T;
!
! static SHAKE_BUF_T shake_buf[SHAKE_BUF_SIZE];
! static int shake_buf_num = 0;
! static PUNCH_BUF_T punch_buf[PUNCH_BUF_SIZE];
! static int punch_buf_num = 0;
! static PUSH_BUF_T push_buf[PUNCH_BUF_SIZE];
! static int push_buf_num = 0;
!
!
! int check_shake( double card_trans[3][4], int f )
! {
! ARMat *mat_a, *mat_b, *mat_c;
! double lxy, lz;
! int i, j, k;
!
! if( shake_buf_num < SHAKE_BUF_SIZE ) {
! if( f ) {
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! shake_buf[shake_buf_num].mat[j][i] = card_trans[j][i];
! }
! }
! shake_buf[shake_buf_num].f = 1;
! }
! else {
! shake_buf[shake_buf_num].f = 0;
! }
! shake_buf_num++;
!
! return 0;
! }
! for( i = 1; i < shake_buf_num; i++ ) {
! shake_buf[i-1] = shake_buf[i];
! }
! if( f ) {
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! shake_buf[shake_buf_num-1].mat[j][i] = card_trans[j][i];
! }
! }
! shake_buf[shake_buf_num-1].f = 1;
! }
! else {
! shake_buf[shake_buf_num-1].f = 0;
!
! return 0;
! }
!
! if( shake_buf[SHAKE_BUF_SIZE-3].f == 0
! || shake_buf[0].f == 0 ) return 0;
!
!
! mat_a = arMatrixAlloc( 4, 4 );
! mat_b = arMatrixAlloc( 4, 4 );
! mat_c = arMatrixAlloc( 4, 4 );
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! mat_a->m[j*4+i] = card_trans[j][i];
! }
! }
! mat_a->m[3*4+0] = 0.0;
! mat_a->m[3*4+1] = 0.0;
! mat_a->m[3*4+2] = 0.0;
! mat_a->m[3*4+3] = 1.0;
! arMatrixSelfInv( mat_a );
!
! for( k = 0 ; k < SHAKE_BUF_SIZE-3; k++ ) {
! if( shake_buf[k].f == 0 ) continue;
!
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! mat_b->m[j*4+i] = shake_buf[k].mat[j][i];
! }
! }
! mat_b->m[3*4+0] = 0.0;
! mat_b->m[3*4+1] = 0.0;
! mat_b->m[3*4+2] = 0.0;
! mat_b->m[3*4+3] = 1.0;
! arMatrixMul( mat_c, mat_a, mat_b );
!
! lxy = sqrt( (mat_c->m[0*4+3])*(mat_c->m[0*4+3])
! +(mat_c->m[1*4+3])*(mat_c->m[1*4+3]));
! lz = mat_c->m[2*4+3];
!
! if( lxy < 20.0 && lz < 20.0 ) break;
! }
! if( k == SHAKE_BUF_SIZE-3 ) {
! arMatrixFree( mat_a );
! arMatrixFree( mat_b );
! arMatrixFree( mat_c );
! return 0;
! }
!
! for( ; k < SHAKE_BUF_SIZE-1; k++ ) {
! if( shake_buf[k].f == 0 ) continue;
!
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! mat_b->m[j*4+i] = shake_buf[k].mat[j][i];
! }
! }
! mat_b->m[3*4+0] = 0.0;
! mat_b->m[3*4+1] = 0.0;
! mat_b->m[3*4+2] = 0.0;
! mat_b->m[3*4+3] = 1.0;
! arMatrixMul( mat_c, mat_a, mat_b );
!
! lxy = sqrt( (mat_c->m[0*4+3])*(mat_c->m[0*4+3])
! +(mat_c->m[1*4+3])*(mat_c->m[1*4+3]));
! lz = mat_c->m[2*4+3];
!
! if( lxy > 60.0 && lz < 20.0 ) break;
! }
! arMatrixFree( mat_a );
! arMatrixFree( mat_b );
! arMatrixFree( mat_c );
!
! if( k < SHAKE_BUF_SIZE-1 ) {
! shake_buf_num = 0;
! return 1;
! }
!
! return 0;
! }
!
!
! int check_incline( double card_trans[3][4], double base_trans[3][4], double *angle )
! {
! ARMat *mat_a, *mat_b, *mat_c;
! double a, b, c;
! int i, j;
!
! mat_a = arMatrixAlloc( 4, 4 );
! mat_b = arMatrixAlloc( 4, 4 );
! mat_c = arMatrixAlloc( 4, 4 );
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! mat_b->m[j*4+i] = base_trans[j][i];
! }
! }
! mat_b->m[3*4+0] = 0.0;
! mat_b->m[3*4+1] = 0.0;
! mat_b->m[3*4+2] = 0.0;
! mat_b->m[3*4+3] = 1.0;
!
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! mat_a->m[j*4+i] = card_trans[j][i];
! }
! }
! mat_a->m[3*4+0] = 0.0;
! mat_a->m[3*4+1] = 0.0;
! mat_a->m[3*4+2] = 0.0;
! mat_a->m[3*4+3] = 1.0;
! arMatrixSelfInv( mat_a );
! arMatrixMul( mat_c, mat_a, mat_b );
!
! get_angle( (double (*)[4])(mat_c->m), &a, &b, &c );
!
! arMatrixFree( mat_a );
! arMatrixFree( mat_b );
! arMatrixFree( mat_c );
!
! if( b > 0.4 ) {
! *angle = a + 3.141592;
! return 1;
! }
!
! return 0;
! }
!
! int check_pickup(double card_trans[3][4], double base_trans[3][4], ItemList* itlist,float* angle)
! {
! ARMat *t1, *t2, *t3;
! double x, y, z;
! double lx, ly;
! double a, b, c;
! int ret;
! int i, j;
!
! // printf("checking pickup New \n");
!
! t1 = arMatrixAlloc( 4, 4 );
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! t1->m[j*4+i] = base_trans[j][i];
! }
! }
! t1->m[12] = t1->m[13] = t1->m[14] = 0.0;
! t1->m[15] = 1.0;
!
! t2 = arMatrixAlloc( 4, 4 );
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! t2->m[j*4+i] = card_trans[j][i];
! }
! }
! t2->m[12] = t2->m[13] = t2->m[14] = 0.0;
! t2->m[15] = 1.0;
!
! if( arMatrixSelfInv(t1) != 0 ) {
! arMatrixFree( t1 );
! arMatrixFree( t2 );
! return -1;
! }
! // printf("past arMatrixSelfInv\n");
!
! t3 = arMatrixAllocMul(t1, t2);
! if( t3 == NULL ) {
! arMatrixFree( t1 );
! arMatrixFree( t2 );
! return -1;
! }
!
! // printf("past arMatrixAllocMul\n");
!
! x = t3->m[0*4+3];
! y = t3->m[1*4+3];
! z = t3->m[2*4+3];
!
! // printf("x: %f y: %f z: %f\n",x,y,z);
!
! ret = -1;
! for( i = 0; i < itlist->itemnum; i ++ ){
! lx = x - itlist->item[i].pos[0];
! ly = y - itlist->item[i].pos[1];
! //MB increased by a factor of 10
! if( lx*lx + ly*ly < 1000.0 && z < 20.0 ) {
! ret = i;
! }
! }
!
! if( ret >= 0 ) {
! get_angle( (double (*)[4])(t3->m), &a, &b, &c );
! *angle = -c;
! }
!
! arMatrixFree( t1 );
! arMatrixFree( t2 );
! arMatrixFree( t3 );
!
! return ret;
! }
--- 1,276 ----
! #ifdef _WIN32
! #include <windows.h>
! #endif
! #include <stdio.h>
! #include <stdlib.h>
! #include <string.h>
! #include <math.h>
! #include <AR/param.h>
! #include <AR/matrix.h>
! #include <AR/ar.h>
! #include "paddle.h"
! #include "command_sub.h"
! #include "util.h"
!
!
! #define SHAKE_BUF_SIZE 10
! #define PUNCH_BUF_SIZE 5
! #define PUSH_BUF_SIZE 2
!
! typedef struct {
! double mat[3][4];
! int f;
! } SHAKE_BUF_T;
!
! typedef struct {
! double x, y, z;
! int f;
! } PUNCH_BUF_T;
!
! typedef struct {
! double x, y, z;
! int f;
! } PUSH_BUF_T;
!
! static SHAKE_BUF_T shake_buf[SHAKE_BUF_SIZE];
! static int shake_buf_num = 0;
! //static PUNCH_BUF_T punch_buf[PUNCH_BUF_SIZE];
! //static int punch_buf_num = 0;
! //static PUSH_BUF_T push_buf[PUNCH_BUF_SIZE];
! //static int push_buf_num = 0;
!
!
! int check_shake( double card_trans[3][4], int f )
! {
! ARMat *mat_a, *mat_b, *mat_c;
! double lxy, lz;
! int i, j, k;
!
! if( shake_buf_num < SHAKE_BUF_SIZE ) {
! if( f ) {
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! shake_buf[shake_buf_num].mat[j][i] = card_trans[j][i];
! }
! }
! shake_buf[shake_buf_num].f = 1;
! }
! else {
! shake_buf[shake_buf_num].f = 0;
! }
! shake_buf_num++;
!
! return 0;
! }
! for( i = 1; i < shake_buf_num; i++ ) {
! shake_buf[i-1] = shake_buf[i];
! }
! if( f ) {
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! shake_buf[shake_buf_num-1].mat[j][i] = card_trans[j][i];
! }
! }
! shake_buf[shake_buf_num-1].f = 1;
! }
! else {
! shake_buf[shake_buf_num-1].f = 0;
!
! return 0;
! }
!
! if( shake_buf[SHAKE_BUF_SIZE-3].f == 0
! || shake_buf[0].f == 0 ) return 0;
!
!
! mat_a = arMatrixAlloc( 4, 4 );
! mat_b = arMatrixAlloc( 4, 4 );
! mat_c = arMatrixAlloc( 4, 4 );
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! mat_a->m[j*4+i] = card_trans[j][i];
! }
! }
! mat_a->m[3*4+0] = 0.0;
! mat_a->m[3*4+1] = 0.0;
! mat_a->m[3*4+2] = 0.0;
! mat_a->m[3*4+3] = 1.0;
! arMatrixSelfInv( mat_a );
!
! for( k = 0 ; k < SHAKE_BUF_SIZE-3; k++ ) {
! if( shake_buf[k].f == 0 ) continue;
!
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! mat_b->m[j*4+i] = shake_buf[k].mat[j][i];
! }
! }
! mat_b->m[3*4+0] = 0.0;
! mat_b->m[3*4+1] = 0.0;
! mat_b->m[3*4+2] = 0.0;
! mat_b->m[3*4+3] = 1.0;
! arMatrixMul( mat_c, mat_a, mat_b );
!
! lxy = sqrt( (mat_c->m[0*4+3])*(mat_c->m[0*4+3])
! +(mat_c->m[1*4+3])*(mat_c->m[1*4+3]));
! lz = mat_c->m[2*4+3];
!
! if( lxy < 20.0 && lz < 20.0 ) break;
! }
! if( k == SHAKE_BUF_SIZE-3 ) {
! arMatrixFree( mat_a );
! arMatrixFree( mat_b );
! arMatrixFree( mat_c );
! return 0;
! }
!
! for( ; k < SHAKE_BUF_SIZE-1; k++ ) {
! if( shake_buf[k].f == 0 ) continue;
!
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! mat_b->m[j*4+i] = shake_buf[k].mat[j][i];
! }
! }
! mat_b->m[3*4+0] = 0.0;
! mat_b->m[3*4+1] = 0.0;
! mat_b->m[3*4+2] = 0.0;
! mat_b->m[3*4+3] = 1.0;
! arMatrixMul( mat_c, mat_a, mat_b );
!
! lxy = sqrt( (mat_c->m[0*4+3])*(mat_c->m[0*4+3])
! +(mat_c->m[1*4+3])*(mat_c->m[1*4+3]));
! lz = mat_c->m[2*4+3];
!
! if( lxy > 60.0 && lz < 20.0 ) break;
! }
! arMatrixFree( mat_a );
! arMatrixFree( mat_b );
! arMatrixFree( mat_c );
!
! if( k < SHAKE_BUF_SIZE-1 ) {
! shake_buf_num = 0;
! return 1;
! }
!
! return 0;
! }
!
!
! int check_incline( double card_trans[3][4], double base_trans[3][4], double *angle )
! {
! ARMat *mat_a, *mat_b, *mat_c;
! double a, b, c;
! int i, j;
!
! mat_a = arMatrixAlloc( 4, 4 );
! mat_b = arMatrixAlloc( 4, 4 );
! mat_c = arMatrixAlloc( 4, 4 );
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! mat_b->m[j*4+i] = base_trans[j][i];
! }
! }
! mat_b->m[3*4+0] = 0.0;
! mat_b->m[3*4+1] = 0.0;
! mat_b->m[3*4+2] = 0.0;
! mat_b->m[3*4+3] = 1.0;
!
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! mat_a->m[j*4+i] = card_trans[j][i];
! }
! }
! mat_a->m[3*4+0] = 0.0;
! mat_a->m[3*4+1] = 0.0;
! mat_a->m[3*4+2] = 0.0;
! mat_a->m[3*4+3] = 1.0;
! arMatrixSelfInv( mat_a );
! arMatrixMul( mat_c, mat_a, mat_b );
!
! get_angle( (double (*)[4])(mat_c->m), &a, &b, &c );
!
! arMatrixFree( mat_a );
! arMatrixFree( mat_b );
! arMatrixFree( mat_c );
!
! if( b > 0.4 ) {
! *angle = a + 3.141592;
! return 1;
! }
!
! return 0;
! }
!
! int check_pickup(double card_trans[3][4], double base_trans[3][4], ItemList* itlist, double* angle)
! {
! ARMat *t1, *t2, *t3;
! double x, y, z;
! double lx, ly;
! double a, b, c;
! int ret;
! int i, j;
!
! // printf("checking pickup New \n");
!
! t1 = arMatrixAlloc( 4, 4 );
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! t1->m[j*4+i] = base_trans[j][i];
! }
! }
! t1->m[12] = t1->m[13] = t1->m[14] = 0.0;
! t1->m[15] = 1.0;
!
! t2 = arMatrixAlloc( 4, 4 );
! for( j = 0; j < 3; j++ ) {
! for( i = 0; i < 4; i++ ) {
! t2->m[j*4+i] = card_trans[j][i];
! }
! }
! t2->m[12] = t2->m[13] = t2->m[14] = 0.0;
! t2->m[15] = 1.0;
!
! if( arMatrixSelfInv(t1) != 0 ) {
! arMatrixFree( t1 );
! arMatrixFree( t2 );
! return -1;
! }
! // printf("past arMatrixSelfInv\n");
!
! t3 = arMatrixAllocMul(t1, t2);
! if( t3 == NULL ) {
! arMatrixFree( t1 );
! arMatrixFree( t2 );
! return -1;
! }
!
! // printf("past arMatrixAllocMul\n");
!
! x = t3->m[0*4+3];
! y = t3->m[1*4+3];
! z = t3->m[2*4+3];
!
! // printf("x: %f y: %f z: %f\n",x,y,z);
!
! ret = -1;
! for( i = 0; i < itlist->itemnum; i ++ ){
! lx = x - itlist->item[i].pos[0];
! ly = y - itlist->item[i].pos[1];
! //MB increased by a factor of 10
! if( lx*lx + ly*ly < 1000.0 && z < 20.0 ) {
! ret = i;
! }
! }
!
! if( ret >= 0 ) {
! get_angle( (double (*)[4])(t3->m), &a, &b, &c );
! *angle = -c;
! }
!
! arMatrixFree( t1 );
! arMatrixFree( t2 );
! arMatrixFree( t3 );
!
! return ret;
! }
Index: paddle.c
===================================================================
RCS file: /cvsroot/artoolkit/artoolkit/examples/paddleDemo/paddle.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** paddle.c 22 Nov 2004 03:37:35 -0000 1.1
--- paddle.c 2 Dec 2004 00:47:43 -0000 1.2
***************
*** 1,155 ****
! #include <stdio.h>
! #include <malloc.h>
! #include <stdlib.h>
! #include <AR/ar.h>
! #include "paddle.h"
!
! static ARMarkerInfo prevInfoL;
! static ARMarkerInfo prevInfoR;
! static int pcountL = 0;
! static int pcountR = 0;
!
! static char *get_buff( char *buf, int n, FILE *fp );
!
! static int get_marker( ARMarkerInfo *markerInfo, int *markerFlag,
! int marker_num, int id,
! ARMarkerInfo *prevInfo, int *pcount );
!
!
! ARPaddleInfo *paddleInit( char *name )
! {
! FILE *fp;
! ARPaddleInfo *paddleInfo;
! char buf[256], buf1[256];
!
! if( (fp=fopen(name, "r")) == NULL ) return(0);
!
! arMalloc( paddleInfo, ARPaddleInfo, 1 );
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%s", paddleInfo->name) != 1 ) {
! fclose(fp); free(paddleInfo); return 0;
! }
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%s", buf1) != 1 ) {
! fclose(fp); free(paddleInfo); return 0;
! }
! if( (paddleInfo->marker_id = arLoadPatt(buf1)) < 0 ) {
! fclose(fp); free(paddleInfo); return 0;
! }
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%lf", &paddleInfo->width) != 1 ) {
! fclose(fp); free(paddleInfo); return 0;
! }
!
! paddleInfo->center[0] = 0.0;
! paddleInfo->center[1] = 0.0;
! paddleInfo->active = 0;
! paddleInfo->pcount = 0;
! paddleInfo->pcountL = 0;
! paddleInfo->pcountR = 0;
!
! fclose(fp);
!
! return paddleInfo;
! }
!
! static char *get_buff( char *buf, int n, FILE *fp )
! {
! char *ret;
!
! for(;;) {
! ret = fgets( buf, n, fp );
! if( ret == NULL ) return(NULL);
! if( buf[0] != '\n' && buf[0] != '#' ) return(ret);
! }
! }
!
! int paddleGetTrans( ARPaddleInfo *paddleInfo, ARMarkerInfo *markerInfo, int *markerFlag, int marker_num, ARParam *cparam )
! {
! int id;
!
! id = get_marker( markerInfo, markerFlag, marker_num, paddleInfo->marker_id,
! &(paddleInfo->prevInfo), &(paddleInfo->pcount) );
!
! if( id == -1 ) { paddleInfo->active = 0; return 0; }
!
! arGetTransMat(&markerInfo[id],
! paddleInfo->center, paddleInfo->width, paddleInfo->trans);
! markerFlag[id] = 1;
!
! paddleInfo->active = 1;
!
! return 0;
! }
!
! static int get_marker( ARMarkerInfo *markerInfo, int *markerFlag, int marker_num, int id,
! ARMarkerInfo *prevInfo, int *pcount )
! {
! double rlen, rlenmin, rarea, diff, diffmin;
! int cid, cdir;
! int i, j;
!
! cid = -1;
! for( i = 0; i < marker_num; i++ ) {
! if( markerInfo[i].id == id && markerFlag[i] == 0 ) {
! if( cid == -1 ) cid = i;
! else {
! if( markerInfo[cid].cf < markerInfo[i].cf ) cid = i;
! }
! }
! }
! if( cid == -1 ) {
! if( *pcount == 0 ) return -1;
!
! rlenmin = 10.0;
! for( i = 0; i < marker_num; i++ ) {
! if( markerFlag[i] ) continue;
! rarea = (double)prevInfo->area / (double)markerInfo[i].area;
! if( rarea < 0.7 || rarea > 1.43 ) continue;
! rlen = ( (markerInfo[i].pos[0] - prevInfo->pos[0])
! * (markerInfo[i].pos[0] - prevInfo->pos[0])
! + (markerInfo[i].pos[1] - prevInfo->pos[1])
! * (markerInfo[i].pos[1] - prevInfo->pos[1]) ) / markerInfo[i].area;
! if( rlen < 0.5 && rlen < rlenmin ) {
! rlenmin = rlen;
! cid = i;
! }
! }
! if( cid >= 0 && markerInfo[cid].cf < prevInfo->cf ) {
! markerInfo[cid].cf = prevInfo->cf;
! markerInfo[cid].id = prevInfo->id;
! diffmin = 10000.0 * 10000.0;
! cdir = -1;
! for( i = 0; i < 4; i++ ) {
! diff = 0.0;
! for( j = 0; j < 4; j++ ) {
! diff += (prevInfo->vertex[j][0] - markerInfo[cid].vertex[(i+j)%4][0])
! * (prevInfo->vertex[j][0] - markerInfo[cid].vertex[(i+j)%4][0])
! + (prevInfo->vertex[j][1] - markerInfo[cid].vertex[(i+j)%4][1])
! * (prevInfo->vertex[j][1] - markerInfo[cid].vertex[(i+j)%4][1]);
! }
! if( diff < diffmin ) {
! diffmin = diff;
! cdir = (prevInfo->dir - i + 4) % 4;
! }
! }
! markerInfo[cid].dir = cdir;
!
! *prevInfo = markerInfo[cid];
! *pcount = 1;
! }
! else {
! *pcount = 0;
! return -1;
! }
! }
! else {
! *prevInfo = markerInfo[cid];
! *pcount = 1;
! }
!
! return cid;
! }
--- 1,149 ----
! #include <stdio.h>
! #include <stdlib.h>
! #include <AR/ar.h>
! #include "paddle.h"
!
! static char *get_buff( char *buf, int n, FILE *fp );
!
! static int get_marker( ARMarkerInfo *markerInfo, int *markerFlag,
! int marker_num, int id,
! ARMarkerInfo *prevInfo, int *pcount );
!
!
! ARPaddleInfo *paddleInit( char *name )
! {
! FILE *fp;
! ARPaddleInfo *paddleInfo;
! char buf[256], buf1[256];
!
! if( (fp=fopen(name, "r")) == NULL ) return(0);
!
! arMalloc( paddleInfo, ARPaddleInfo, 1 );
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%s", paddleInfo->name) != 1 ) {
! fclose(fp); free(paddleInfo); return 0;
! }
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%s", buf1) != 1 ) {
! fclose(fp); free(paddleInfo); return 0;
! }
! if( (paddleInfo->marker_id = arLoadPatt(buf1)) < 0 ) {
! fclose(fp); free(paddleInfo); return 0;
! }
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%lf", &paddleInfo->width) != 1 ) {
! fclose(fp); free(paddleInfo); return 0;
! }
!
! paddleInfo->center[0] = 0.0;
! paddleInfo->center[1] = 0.0;
! paddleInfo->active = 0;
! paddleInfo->pcount = 0;
! paddleInfo->pcountL = 0;
! paddleInfo->pcountR = 0;
!
! fclose(fp);
!
! return paddleInfo;
! }
!
! static char *get_buff( char *buf, int n, FILE *fp )
! {
! char *ret;
!
! for(;;) {
! ret = fgets( buf, n, fp );
! if( ret == NULL ) return(NULL);
! if( buf[0] != '\n' && buf[0] != '#' ) return(ret);
! }
! }
!
! int paddleGetTrans( ARPaddleInfo *paddleInfo, ARMarkerInfo *markerInfo, int *markerFlag, int marker_num, ARParam *cparam )
! {
! int id;
!
! id = get_marker( markerInfo, markerFlag, marker_num, paddleInfo->marker_id,
! &(paddleInfo->prevInfo), &(paddleInfo->pcount) );
!
! if( id == -1 ) { paddleInfo->active = 0; return 0; }
!
! arGetTransMat(&markerInfo[id],
! paddleInfo->center, paddleInfo->width, paddleInfo->trans);
! markerFlag[id] = 1;
!
! paddleInfo->active = 1;
!
! return 0;
! }
!
! static int get_marker( ARMarkerInfo *markerInfo, int *markerFlag, int marker_num, int id,
! ARMarkerInfo *prevInfo, int *pcount )
! {
! double rlen, rlenmin, rarea, diff, diffmin;
! int cid, cdir;
! int i, j;
!
! cid = -1;
! for( i = 0; i < marker_num; i++ ) {
! if( markerInfo[i].id == id && markerFlag[i] == 0 ) {
! if( cid == -1 ) cid = i;
! else {
! if( markerInfo[cid].cf < markerInfo[i].cf ) cid = i;
! }
! }
! }
! if( cid == -1 ) {
! if( *pcount == 0 ) return -1;
!
! rlenmin = 10.0;
! for( i = 0; i < marker_num; i++ ) {
! if( markerFlag[i] ) continue;
! rarea = (double)prevInfo->area / (double)markerInfo[i].area;
! if( rarea < 0.7 || rarea > 1.43 ) continue;
! rlen = ( (markerInfo[i].pos[0] - prevInfo->pos[0])
! * (markerInfo[i].pos[0] - prevInfo->pos[0])
! + (markerInfo[i].pos[1] - prevInfo->pos[1])
! * (markerInfo[i].pos[1] - prevInfo->pos[1]) ) / markerInfo[i].area;
! if( rlen < 0.5 && rlen < rlenmin ) {
! rlenmin = rlen;
! cid = i;
! }
! }
! if( cid >= 0 && markerInfo[cid].cf < prevInfo->cf ) {
! markerInfo[cid].cf = prevInfo->cf;
! markerInfo[cid].id = prevInfo->id;
! diffmin = 10000.0 * 10000.0;
! cdir = -1;
! for( i = 0; i < 4; i++ ) {
! diff = 0.0;
! for( j = 0; j < 4; j++ ) {
! diff += (prevInfo->vertex[j][0] - markerInfo[cid].vertex[(i+j)%4][0])
! * (prevInfo->vertex[j][0] - markerInfo[cid].vertex[(i+j)%4][0])
! + (prevInfo->vertex[j][1] - markerInfo[cid].vertex[(i+j)%4][1])
! * (prevInfo->vertex[j][1] - markerInfo[cid].vertex[(i+j)%4][1]);
! }
! if( diff < diffmin ) {
! diffmin = diff;
! cdir = (prevInfo->dir - i + 4) % 4;
! }
! }
! markerInfo[cid].dir = cdir;
!
! *prevInfo = markerInfo[cid];
! *pcount = 1;
! }
! else {
! *pcount = 0;
! return -1;
! }
! }
! else {
! *prevInfo = markerInfo[cid];
! *pcount = 1;
! }
!
! return cid;
! }
Index: paddleDemo.c
===================================================================
RCS file: /cvsroot/artoolkit/artoolkit/examples/paddleDemo/paddleDemo.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** paddleDemo.c 22 Nov 2004 03:37:35 -0000 1.1
--- paddleDemo.c 2 Dec 2004 00:47:43 -0000 1.2
***************
*** 1,546 ****
! #ifdef _WIN32
! #include <windows.h>
! #endif
! #include <stdio.h>
! #include <stdlib.h>
! #include <string.h>
! #include <math.h>
!
! #include <GL/gl.h>
! #include <GL/glut.h>
[...1061 lines suppressed...]
! y0 = y0 + deltaY;
! glBegin(GL_LINES);
! glVertex3f(x0,y0,height);
! glVertex3f(x1,y0,height);
! glEnd();
! }
!
! glLineWidth(1.0);
!
! glEnable(GL_LIGHTING);
! glEnable(GL_LIGHT0);
! glLightfv(GL_LIGHT0, GL_POSITION, light_position);
! glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
! glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
!
! glDisable( GL_LIGHTING );
! glDisable( GL_DEPTH_TEST );
! argDrawMode2D();
! return 0;
! }
Index: command_sub.h
===================================================================
RCS file: /cvsroot/artoolkit/artoolkit/examples/paddleDemo/command_sub.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** command_sub.h 22 Nov 2004 03:37:35 -0000 1.1
--- command_sub.h 2 Dec 2004 00:47:43 -0000 1.2
***************
*** 1,34 ****
! #ifndef COMMAND_SUB_H
! #define COMMAND_SUB_H
!
! #include "paddle.h"
!
! /* on item structure */
! typedef struct {
! double pos[2];
! int onpaddle;
! } Item;
!
! /* list of items */
! typedef struct {
! int itemnum;
! Item item[256];
! } ItemList;
!
! /* item which is on the paddle */
! typedef struct {
! int item;
! double angle;
! double x, y;
! } PaddleItemInfo;
!
! /* shaking gesture to remove a pattern */
! int check_shake ( double paddleTrans[3][4], int f );
!
! /* inclining gesture to put an object on the ground*/
! int check_incline ( double paddleTrans[3][4], double baseTrans[3][4], double *angle );
!
! /* picking gesture to take an object from the ground*/
! int check_pickup(double card_trans[3][4], double base_trans[3][4], ItemList* itlist,float* angle);
!
! #endif
--- 1,34 ----
! #ifndef COMMAND_SUB_H
! #define COMMAND_SUB_H
!
! #include "paddle.h"
!
! /* on item structure */
! typedef struct {
! double pos[2];
! int onpaddle;
! } Item;
!
! /* list of items */
! typedef struct {
! int itemnum;
! Item item[256];
! } ItemList;
!
! /* item which is on the paddle */
! typedef struct {
! int item;
! double angle;
! double x, y;
! } PaddleItemInfo;
!
! /* shaking gesture to remove a pattern */
! int check_shake ( double paddleTrans[3][4], int f );
!
! /* inclining gesture to put an object on the ground*/
! int check_incline ( double paddleTrans[3][4], double baseTrans[3][4], double *angle );
!
! /* picking gesture to take an object from the ground*/
! int check_pickup(double card_trans[3][4], double base_trans[3][4], ItemList* itlist, double* angle);
!
! #endif
|