Update of /cvsroot/artoolkit/artoolkit/examples/loadMultiple
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21251
Modified Files:
object.c loadMultiple.c
Log Message:
Fix some build warnings.
Index: object.c
===================================================================
RCS file: /cvsroot/artoolkit/artoolkit/examples/loadMultiple/object.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** object.c 22 Nov 2004 03:38:05 -0000 1.1
--- object.c 2 Dec 2004 00:48:07 -0000 1.2
***************
*** 1,101 ****
!
! /*
! ** ARToolKit object parsing function
! ** - reads in object data from object file in Data/object_data
! **
! ** Format:
! ** <obj_num>
! **
! ** <obj_name>
! ** <obj_pattern filename>
! ** <marker_width>
! ** <centerX centerY>
! **
! ** ...
! **
! ** eg
! **
! ** #pattern 1
! ** Hiro
! ** Data/hiroPatt
! ** 80.0
! ** 0.0 0.0
! **
! */
!
! #include <stdio.h>
! #include <malloc.h>
! #include <stdlib.h>
! #include <string.h>
! #include <AR/ar.h>
! #include "object.h"
!
! static char *get_buff( char *buf, int n, FILE *fp );
!
! ObjectData_T *read_ObjData( char *name, int *objectnum )
! {
! FILE *fp;
! ObjectData_T *object;
! char buf[256], buf1[256];
! int i;
!
! printf("Opening Data File %s\n",name);
!
! if( (fp=fopen(name, "r")) == NULL ) {
! printf("Can't find the file - quitting \n");
! return(0);
! }
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%d", objectnum) != 1 ) {fclose(fp); return(0);}
!
! printf("About to load %d Models\n",*objectnum);
!
! object = (ObjectData_T *)malloc( sizeof(ObjectData_T) * *objectnum );
! if( object == NULL ) return(0);
!
! for( i = 0; i < *objectnum; i++ ) {
! object[i].visible = 0;
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%s", buf1, object[i].name) != 1 ) {
! fclose(fp); free(object); return(0);
! }
!
! printf("Read in No.%d \n", i+1);
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%s", buf1) != 1 ) {
! fclose(fp); free(object); return(0);}
!
! if( (object[i].id = arLoadPatt(buf1)) < 0 )
! {fclose(fp); free(object); return(0);}
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%lf", &object[i].marker_width) != 1 ) {
! fclose(fp); free(object); return(0);
! }
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%lf %lf", &object[i].marker_center[0],
! &object[i].marker_center[1]) != 2 ) {
! fclose(fp); free(object); return(0);
! }
!
! }
!
! fclose(fp);
!
! return( object );
! }
!
! 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);
! }
! }
--- 1,100 ----
!
! /*
! ** ARToolKit object parsing function
! ** - reads in object data from object file in Data/object_data
! **
! ** Format:
! ** <obj_num>
! **
! ** <obj_name>
! ** <obj_pattern filename>
! ** <marker_width>
! ** <centerX centerY>
! **
! ** ...
! **
! ** eg
! **
! ** #pattern 1
! ** Hiro
! ** Data/hiroPatt
! ** 80.0
! ** 0.0 0.0
! **
! */
!
! #include <stdio.h>
! #include <stdlib.h>
! #include <string.h>
! #include <AR/ar.h>
! #include "object.h"
!
! static char *get_buff( char *buf, int n, FILE *fp );
!
! ObjectData_T *read_ObjData( char *name, int *objectnum )
! {
! FILE *fp;
! ObjectData_T *object;
! char buf[256], buf1[256];
! int i;
!
! printf("Opening Data File %s\n",name);
!
! if( (fp=fopen(name, "r")) == NULL ) {
! printf("Can't find the file - quitting \n");
! return(0);
! }
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%d", objectnum) != 1 ) {fclose(fp); return(0);}
!
! printf("About to load %d Models\n",*objectnum);
!
! object = (ObjectData_T *)malloc( sizeof(ObjectData_T) * *objectnum );
! if( object == NULL ) return(0);
!
! for( i = 0; i < *objectnum; i++ ) {
! object[i].visible = 0;
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%s", object[i].name) != 1 ) {
! fclose(fp); free(object); return(0);
! }
!
! printf("Read in No.%d \n", i+1);
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%s", buf1) != 1 ) {
! fclose(fp); free(object); return(0);}
!
! if( (object[i].id = arLoadPatt(buf1)) < 0 )
! {fclose(fp); free(object); return(0);}
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%lf", &object[i].marker_width) != 1 ) {
! fclose(fp); free(object); return(0);
! }
!
! get_buff(buf, 256, fp);
! if( sscanf(buf, "%lf %lf", &object[i].marker_center[0],
! &object[i].marker_center[1]) != 2 ) {
! fclose(fp); free(object); return(0);
! }
!
! }
!
! fclose(fp);
!
! return( object );
! }
!
! 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);
! }
! }
Index: loadMultiple.c
===================================================================
RCS file: /cvsroot/artoolkit/artoolkit/examples/loadMultiple/loadMultiple.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** loadMultiple.c 22 Nov 2004 03:38:05 -0000 1.1
--- loadMultiple.c 2 Dec 2004 00:48:07 -0000 1.2
***************
*** 1,256 ****
! #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>
! #include <AR/gsub.h>
! #include <AR/param.h>
! #include <AR/ar.h>
! #include <AR/video.h>
!
! #include "object.h"
!
! #define COLLIDE_DIST 30000.0
!
! /* Object Data */
! char *model_name = "Data/object_data2";
! ObjectData_T *object;
! int objectnum;
!
! int xsize, ysize;
! int thresh = 100;
! int count = 0;
!
! /* set video capture configuration */
! /*****************************************************************************/
! // modified by Thomas Pintaric, Vienna University of Technology
!
! #ifdef _WIN32
! char *vconf = "flipV,showDlg"; // see video.h for a list of supported parameters
! #else
! char *vconf = "";
! #endif
! /*****************************************************************************/
!
! char *cparam_name = "Data/camera_para.dat";
! ARParam cparam;
!
! static void init(void);
! static void cleanup(void);
! static void keyEvent( unsigned char key, int x, int y);
! static void mainLoop(void);
! static int draw( ObjectData_T *object, int objectnum );
! static int draw_object( int obj_id, double gl_para[16] );
!
! int main()
! {
! //initialize applications
! init();
!
! arVideoCapStart();
!
! //start the main event loop
! argMainLoop( NULL, keyEvent, mainLoop );
!
! return 0;
! }
!
! static void keyEvent( unsigned char key, int x, int y)
! {
! /* quit if the ESC key is pressed */
! if( key == 0x1b ) {
! printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
! cleanup();
! exit(0);
! }
! }
!
! /* main loop */
! static void mainLoop(void)
! {
! ARUint8 *dataPtr;
! ARMarkerInfo *marker_info;
! int marker_num;
! int i,j,k;
!
! /* grab a video frame */
! if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
! arUtilSleep(2);
! return;
! }
!
! if( count == 0 ) arUtilTimerReset();
! count++;
!
! /*draw the video*/
! argDrawMode2D();
! argDispImage( dataPtr, 0,0 );
!
! glColor3f( 1.0, 0.0, 0.0 );
! glLineWidth(6.0);
!
! /* detect the markers in the video frame */
! if(arDetectMarker(dataPtr, thresh,
! &marker_info, &marker_num) < 0 ) {
! cleanup();
! exit(0);
! }
! for( i = 0; i < marker_num; i++ ) {
! argDrawSquare(marker_info[i].vertex,0,0);
! }
!
! /* check for known patterns */
! for( i = 0; i < objectnum; i++ ) {
! k = -1;
! for( j = 0; j < marker_num; j++ ) {
! if( object[i].id == marker_info[j].id) {
!
! /* you've found a pattern */
! //printf("Found pattern: %d ",patt_id);
! glColor3f( 0.0, 1.0, 0.0 );
! argDrawSquare(marker_info[j].vertex,0,0);
!
! if( k == -1 ) k = j;
! else /* make sure you have the best pattern (highest confidence factor) */
! if( marker_info[k].cf < marker_info[j].cf ) k = j;
! }
! }
! if( k == -1 ) {
! object[i].visible = 0;
! continue;
! }
!
! /* calculate the transform for each marker */
! if( object[i].visible == 0 ) {
! arGetTransMat(&marker_info[k],
! object[i].marker_center, object[i].marker_width,
! object[i].trans);
! }
! else {
! arGetTransMatCont(&marker_info[k], object[i].trans,
! object[i].marker_center, object[i].marker_width,
! object[i].trans);
! }
! object[i].visible = 1;
! }
!
! arVideoCapNext();
!
! /* draw the AR graphics */
! draw( object, objectnum );
!
! /*swap the graphics buffers*/
! argSwapBuffers();
! }
!
! static void init( void )
! {
! ARParam wparam;
!
! /* open the video path */
! if( arVideoOpen( vconf ) < 0 ) exit(0);
! /* find the size of the window */
! if( arVideoInqSize(&xsize, &ysize) < 0 ) exit(0);
! printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);
!
! /* set the initial camera parameters */
! if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
! printf("Camera parameter load error !!\n");
! exit(0);
! }
! arParamChangeSize( &wparam, xsize, ysize, &cparam );
! arInitCparam( &cparam );
! printf("*** Camera Parameter ***\n");
! arParamDisp( &cparam );
!
! /* load in the object data - trained markers and associated bitmap files */
! if( (object=read_ObjData(model_name, &objectnum)) == NULL ) exit(0);
! printf("Objectfile num = %d\n", objectnum);
!
! /* open the graphics window */
! argInit( &cparam, 2.0, 0, 0, 0, 0 );
! }
!
! /* cleanup function called when program exits */
! static void cleanup(void)
! {
! arVideoCapStop();
! arVideoClose();
! argCleanup();
! }
!
! /* draw the the AR objects */
! static int draw( ObjectData_T *object, int objectnum )
! {
! int i;
! double gl_para[16];
!
! glClearDepth( 1.0 );
! glClear(GL_DEPTH_BUFFER_BIT);
! glEnable(GL_DEPTH_TEST);
! glDepthFunc(GL_LEQUAL);
! glEnable(GL_LIGHTING);
!
! /* calculate the viewing parameters - gl_para */
! for( i = 0; i < objectnum; i++ ) {
! if( object[i].visible == 0 ) continue;
! argConvGlpara(object[i].trans, gl_para);
! draw_object( object[i].id, gl_para);
! }
!
! glDisable( GL_LIGHTING );
! glDisable( GL_DEPTH_TEST );
!
! return(0);
! }
!
! /* draw the user object */
! static int draw_object( int obj_id, double gl_para[16])
! {
! GLfloat mat_ambient[] = {0.0, 0.0, 1.0, 1.0};
! GLfloat mat_ambient_collide[] = {1.0, 0.0, 0.0, 1.0};
! GLfloat mat_flash[] = {0.0, 0.0, 1.0, 1.0};
! GLfloat mat_flash_collide[] = {1.0, 0.0, 0.0, 1.0};
! GLfloat mat_flash_shiny[] = {50.0};
! GLfloat light_position[] = {100.0,-200.0,200.0,0.0};
! GLfloat ambi[] = {0.1, 0.1, 0.1, 0.1};
! GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1};
!
! argDrawMode3D();
! argDraw3dCamera( 0, 0 );
! glMatrixMode(GL_MODELVIEW);
! glLoadMatrixd( gl_para );
!
! /* set the material */
! 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);
!
! glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);
!
! if(obj_id == 0){
! glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash_collide);
! glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_collide);
! /* draw a cube */
! glTranslatef( 0.0, 0.0, 30.0 );
! glutSolidSphere(30,12,6);
! }
! else {
! glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
! glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
! /* draw a cube */
! glTranslatef( 0.0, 0.0, 30.0 );
! glutSolidCube(60);
! }
!
! argDrawMode2D();
!
! return 0;
! }
--- 1,259 ----
! #ifdef _WIN32
! # include <windows.h>
! #endif
! #include <stdio.h>
! #include <stdlib.h>
! #include <string.h>
! #include <math.h>
!
! #ifndef __APPLE__
! # include <GL/glut.h>
! #else
! # include <GLUT/glut.h>
! #endif
! #include <AR/gsub.h>
! #include <AR/param.h>
! #include <AR/ar.h>
! #include <AR/video.h>
!
! #include "object.h"
!
! #define COLLIDE_DIST 30000.0
!
! /* Object Data */
! char *model_name = "Data/object_data2";
! ObjectData_T *object;
! int objectnum;
!
! int xsize, ysize;
! int thresh = 100;
! int count = 0;
!
! /* set video capture configuration */
! /*****************************************************************************/
! // modified by Thomas Pintaric, Vienna University of Technology
!
! #ifdef _WIN32
! char *vconf = "flipV,showDlg"; // see video.h for a list of supported parameters
! #else
! char *vconf = "";
! #endif
! /*****************************************************************************/
!
! char *cparam_name = "Data/camera_para.dat";
! ARParam cparam;
!
! static void init(void);
! static void cleanup(void);
! static void keyEvent( unsigned char key, int x, int y);
! static void mainLoop(void);
! static int draw( ObjectData_T *object, int objectnum );
! static int draw_object( int obj_id, double gl_para[16] );
!
! int main()
! {
! //initialize applications
! init();
!
! arVideoCapStart();
!
! //start the main event loop
! argMainLoop( NULL, keyEvent, mainLoop );
!
! return 0;
! }
!
! static void keyEvent( unsigned char key, int x, int y)
! {
! /* quit if the ESC key is pressed */
! if( key == 0x1b ) {
! printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
! cleanup();
! exit(0);
! }
! }
!
! /* main loop */
! static void mainLoop(void)
! {
! ARUint8 *dataPtr;
! ARMarkerInfo *marker_info;
! int marker_num;
! int i,j,k;
!
! /* grab a video frame */
! if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
! arUtilSleep(2);
! return;
! }
!
! if( count == 0 ) arUtilTimerReset();
! count++;
!
! /*draw the video*/
! argDrawMode2D();
! argDispImage( dataPtr, 0,0 );
!
! glColor3f( 1.0, 0.0, 0.0 );
! glLineWidth(6.0);
!
! /* detect the markers in the video frame */
! if(arDetectMarker(dataPtr, thresh,
! &marker_info, &marker_num) < 0 ) {
! cleanup();
! exit(0);
! }
! for( i = 0; i < marker_num; i++ ) {
! argDrawSquare(marker_info[i].vertex,0,0);
! }
!
! /* check for known patterns */
! for( i = 0; i < objectnum; i++ ) {
! k = -1;
! for( j = 0; j < marker_num; j++ ) {
! if( object[i].id == marker_info[j].id) {
!
! /* you've found a pattern */
! //printf("Found pattern: %d ",patt_id);
! glColor3f( 0.0, 1.0, 0.0 );
! argDrawSquare(marker_info[j].vertex,0,0);
!
! if( k == -1 ) k = j;
! else /* make sure you have the best pattern (highest confidence factor) */
! if( marker_info[k].cf < marker_info[j].cf ) k = j;
! }
! }
! if( k == -1 ) {
! object[i].visible = 0;
! continue;
! }
!
! /* calculate the transform for each marker */
! if( object[i].visible == 0 ) {
! arGetTransMat(&marker_info[k],
! object[i].marker_center, object[i].marker_width,
! object[i].trans);
! }
! else {
! arGetTransMatCont(&marker_info[k], object[i].trans,
! object[i].marker_center, object[i].marker_width,
! object[i].trans);
! }
! object[i].visible = 1;
! }
!
! arVideoCapNext();
!
! /* draw the AR graphics */
! draw( object, objectnum );
!
! /*swap the graphics buffers*/
! argSwapBuffers();
! }
!
! static void init( void )
! {
! ARParam wparam;
!
! /* open the video path */
! if( arVideoOpen( vconf ) < 0 ) exit(0);
! /* find the size of the window */
! if( arVideoInqSize(&xsize, &ysize) < 0 ) exit(0);
! printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);
!
! /* set the initial camera parameters */
! if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
! printf("Camera parameter load error !!\n");
! exit(0);
! }
! arParamChangeSize( &wparam, xsize, ysize, &cparam );
! arInitCparam( &cparam );
! printf("*** Camera Parameter ***\n");
! arParamDisp( &cparam );
!
! /* load in the object data - trained markers and associated bitmap files */
! if( (object=read_ObjData(model_name, &objectnum)) == NULL ) exit(0);
! printf("Objectfile num = %d\n", objectnum);
!
! /* open the graphics window */
! argInit( &cparam, 2.0, 0, 0, 0, 0 );
! }
!
! /* cleanup function called when program exits */
! static void cleanup(void)
! {
! arVideoCapStop();
! arVideoClose();
! argCleanup();
! }
!
! /* draw the the AR objects */
! static int draw( ObjectData_T *object, int objectnum )
! {
! int i;
! double gl_para[16];
!
! glClearDepth( 1.0 );
! glClear(GL_DEPTH_BUFFER_BIT);
! glEnable(GL_DEPTH_TEST);
! glDepthFunc(GL_LEQUAL);
! glEnable(GL_LIGHTING);
!
! /* calculate the viewing parameters - gl_para */
! for( i = 0; i < objectnum; i++ ) {
! if( object[i].visible == 0 ) continue;
! argConvGlpara(object[i].trans, gl_para);
! draw_object( object[i].id, gl_para);
! }
!
! glDisable( GL_LIGHTING );
! glDisable( GL_DEPTH_TEST );
!
! return(0);
! }
!
! /* draw the user object */
! static int draw_object( int obj_id, double gl_para[16])
! {
! GLfloat mat_ambient[] = {0.0, 0.0, 1.0, 1.0};
! GLfloat mat_ambient_collide[] = {1.0, 0.0, 0.0, 1.0};
! GLfloat mat_flash[] = {0.0, 0.0, 1.0, 1.0};
! GLfloat mat_flash_collide[] = {1.0, 0.0, 0.0, 1.0};
! GLfloat mat_flash_shiny[] = {50.0};
! GLfloat light_position[] = {100.0,-200.0,200.0,0.0};
! GLfloat ambi[] = {0.1, 0.1, 0.1, 0.1};
! GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1};
!
! argDrawMode3D();
! argDraw3dCamera( 0, 0 );
! glMatrixMode(GL_MODELVIEW);
! glLoadMatrixd( gl_para );
!
! /* set the material */
! 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);
!
! glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);
!
! if(obj_id == 0){
! glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash_collide);
! glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_collide);
! /* draw a cube */
! glTranslatef( 0.0, 0.0, 30.0 );
! glutSolidSphere(30,12,6);
! }
! else {
! glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
! glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
! /* draw a cube */
! glTranslatef( 0.0, 0.0, 30.0 );
! glutSolidCube(60);
! }
!
! argDrawMode2D();
!
! return 0;
! }
|