Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 204 | chris | 1 | |
| 2 | /* |
||
| 3 | ** ARToolKit object parsing function |
||
| 4 | ** - reads in object data from object file in Data/object_data |
||
| 5 | ** |
||
| 6 | ** Format: |
||
| 7 | ** <obj_num> |
||
| 8 | ** |
||
| 9 | ** <obj_name> |
||
| 10 | ** <obj_pattern filename> |
||
| 11 | ** <marker_width> |
||
| 12 | ** <centerX centerY> |
||
| 13 | ** |
||
| 14 | ** ... |
||
| 15 | ** |
||
| 16 | ** eg |
||
| 17 | ** |
||
| 18 | ** #pattern 1 |
||
| 19 | ** Hiro |
||
| 20 | ** Data/hiroPatt |
||
| 21 | ** 80.0 |
||
| 22 | ** 0.0 0.0 |
||
| 23 | ** |
||
| 24 | */ |
||
| 25 | |||
| 26 | #include <stdio.h> |
||
| 27 | #include <stdlib.h> |
||
| 28 | #include <string.h> |
||
| 29 | #include <AR/ar.h> |
||
| 30 | #include "object.h" |
||
| 31 | |||
| 32 | static char *get_buff( char *buf, int n, FILE *fp ); |
||
| 33 | |||
| 34 | ObjectData_T *read_ObjData( char *name, int *objectnum ) |
||
| 35 | { |
||
| 36 | FILE *fp; |
||
| 37 | ObjectData_T *object; |
||
| 38 | char buf[256], buf1[256]; |
||
| 39 | int i; |
||
| 40 | |||
| 41 | printf("Opening Data File %s\n",name); |
||
| 42 | |||
| 43 | if( (fp=fopen(name, "r")) == NULL ) { |
||
| 44 | printf("Can't find the file - quitting \n"); |
||
| 45 | return(0); |
||
| 46 | } |
||
| 47 | |||
| 48 | get_buff(buf, 256, fp); |
||
| 49 | if( sscanf(buf, "%d", objectnum) != 1 ) {fclose(fp); return(0);} |
||
| 50 | |||
| 51 | printf("About to load %d Models\n",*objectnum); |
||
| 52 | |||
| 53 | object = (ObjectData_T *)malloc( sizeof(ObjectData_T) * *objectnum ); |
||
| 54 | if( object == NULL ) return(0); |
||
| 55 | |||
| 56 | for( i = 0; i < *objectnum; i++ ) { |
||
| 57 | object[i].visible = 0; |
||
| 58 | |||
| 59 | get_buff(buf, 256, fp); |
||
| 60 | if( sscanf(buf, "%s", object[i].name) != 1 ) { |
||
| 61 | fclose(fp); free(object); return(0); |
||
| 62 | } |
||
| 63 | |||
| 64 | printf("Read in No.%d \n", i+1); |
||
| 65 | |||
| 66 | get_buff(buf, 256, fp); |
||
| 67 | if( sscanf(buf, "%s", buf1) != 1 ) { |
||
| 68 | fclose(fp); free(object); return(0);} |
||
| 69 | |||
| 70 | if( (object[i].id = arLoadPatt(buf1)) < 0 ) |
||
| 71 | {fclose(fp); free(object); return(0);} |
||
| 72 | |||
| 73 | get_buff(buf, 256, fp); |
||
| 74 | if( sscanf(buf, "%lf", &object[i].marker_width) != 1 ) { |
||
| 75 | fclose(fp); free(object); return(0); |
||
| 76 | } |
||
| 77 | |||
| 78 | get_buff(buf, 256, fp); |
||
| 79 | if( sscanf(buf, "%lf %lf", &object[i].marker_center[0], |
||
| 80 | &object[i].marker_center[1]) != 2 ) { |
||
| 81 | fclose(fp); free(object); return(0); |
||
| 82 | } |
||
| 83 | |||
| 84 | } |
||
| 85 | |||
| 86 | fclose(fp); |
||
| 87 | |||
| 88 | return( object ); |
||
| 89 | } |
||
| 90 | |||
| 91 | static char *get_buff( char *buf, int n, FILE *fp ) |
||
| 92 | { |
||
| 93 | char *ret; |
||
| 94 | |||
| 95 | for(;;) { |
||
| 96 | ret = fgets( buf, n, fp ); |
||
| 97 | if( ret == NULL ) return(NULL); |
||
| 98 | if( buf[0] != '\n' && buf[0] != '#' ) return(ret); |
||
| 99 | } |
||
| 100 | } |