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 | */ |
||
| 7 | |||
| 8 | #ifdef _WIN32 |
||
| 9 | #include <windows.h> |
||
| 10 | #endif |
||
| 11 | #include <stdio.h> |
||
| 12 | #ifndef __APPLE__ |
||
| 13 | #include <malloc.h> |
||
| 14 | #endif |
||
| 15 | #include <stdlib.h> |
||
| 16 | #include <AR/ar.h> |
||
| 17 | #include "object.h" |
||
| 18 | |||
| 19 | static char *get_buff( char *buf, int n, FILE *fp ); |
||
| 20 | |||
| 21 | ObjectData_T *read_objectdata( char *name, int *objectnum ) |
||
| 22 | { |
||
| 23 | FILE *fp; |
||
| 24 | ObjectData_T *object; |
||
| 25 | char buf[256], buf1[256]; |
||
| 26 | int i; |
||
| 27 | |||
| 28 | if( (fp=fopen(name, "r")) == NULL ) return(0); |
||
| 29 | |||
| 30 | get_buff(buf, 256, fp); |
||
| 31 | if( sscanf(buf, "%d", objectnum) != 1 ) {fclose(fp); return(0);} |
||
| 32 | |||
| 33 | object = (ObjectData_T *)malloc( sizeof(ObjectData_T) * *objectnum ); |
||
| 34 | if( object == NULL ) return(0); |
||
| 35 | |||
| 36 | for( i = 0; i < *objectnum; i++ ) { |
||
| 37 | get_buff(buf, 256, fp); |
||
| 38 | if( sscanf(buf, "%s", object[i].name) != 1 ) { |
||
| 39 | fclose(fp); free(object); return(0);} |
||
| 40 | |||
| 41 | get_buff(buf, 256, fp); |
||
| 42 | if( sscanf(buf, "%s", buf1) != 1 ) { |
||
| 43 | fclose(fp); free(object); return(0);} |
||
| 44 | |||
| 45 | if( (object[i].id = arLoadPatt(buf1)) < 0 ) |
||
| 46 | {fclose(fp); free(object); return(0);} |
||
| 47 | |||
| 48 | object[i].visible = 0; |
||
| 49 | |||
| 50 | get_buff(buf, 256, fp); |
||
| 51 | if( sscanf(buf, "%lf", &object[i].marker_width) != 1 ) { |
||
| 52 | fclose(fp); free(object); return(0); |
||
| 53 | } |
||
| 54 | |||
| 55 | printf("No.%d: %20s\n", i+1, &(object[i].name[0]) ); |
||
| 56 | } |
||
| 57 | |||
| 58 | fclose(fp); |
||
| 59 | |||
| 60 | return( object ); |
||
| 61 | } |
||
| 62 | |||
| 63 | static char *get_buff( char *buf, int n, FILE *fp ) |
||
| 64 | { |
||
| 65 | char *ret; |
||
| 66 | |||
| 67 | for(;;) { |
||
| 68 | ret = fgets( buf, n, fp ); |
||
| 69 | if( ret == NULL ) return(NULL); |
||
| 70 | if( buf[0] != '\n' && buf[0] != '#' ) return(ret); |
||
| 71 | } |
||
| 72 | } |