/* raw_dat.c read an autodesk .3ds file, crossroads.exe, to bull.raw */ /* well, for a start just extract vertices and points in .dat format */ #include #include typedef struct {float x; float y; float z;} dpts; static int read(char filename[], dpts * *data_points, int *num_points, int * *data_polys, int *num_polys); int datwrite(char filename[], dpts * data_points, int num_points, int * data_polys, int num_polys); static int read(char filename[], dpts * *data_points, int *num_points, int * *data_polys, int *num_polys) { FILE * obj_file; /* file descriptor for input obj*/ int num_pts, num_pys, num_tri; int i, j, k; float x, y, z; num_tri = 12398; num_pts = 3 * num_tri; num_pys = num_tri; *num_points = num_pts; /* send back to caller */ *num_polys = num_pys; /* crude! */ if((obj_file = fopen(filename, "r"))==NULL) { printf("could not open for reading %s \n", filename); return 1; } /* allocate space for points and vertices */ *data_points = (dpts *)malloc(sizeof(dpts)*num_pts); if(*data_points == NULL) { printf("read could not allocate enough space for points\n"); return 1; } *data_polys = (int *)malloc(sizeof(int)*4*num_pys); if(*data_polys == NULL) { printf("read could not allocate enough user space for points\n"); return 1; } k = 0; for(i=0; i2) { printf("about to read %s, and write %s \n", argv[1], argv[2]); } else { printf("raw_dat xxx.raw xxx.dat needs two file names.\n"); return 1; } status = read(argv[1], &data_points, &num_points, &data_verts, &num_polys); printf("status=%d, num_points=%d, num_polys=%d\n", status, num_points, num_polys); datwrite(argv[2], data_points, num_points, data_verts, num_polys); printf("read3ds has written %s \n", argv[2]); return 0; }