#include #include #include "object.h" extern int DEBUG; void read_grid_from_file (grid * thing, FILE * df); void read_polylist_from_file (polylist * thing, FILE * df); void read_object(object * thing, char * file){ FILE * df; /* file descriptor for input */ char ch; df = fopen(file,"r"); if (df == NULL) { printf("Invalid file name--- aborted \n"); exit (-1); } ch = ' '; while ((ch != 'g') && (ch != 'p')){ fscanf(df,"%c",&ch); } if (ch == 'g') { thing->kind = GRID; read_grid_from_file(&(thing->go.gd),df); } if (ch == 'p') { thing->kind = POLYLIST; read_polylist_from_file(&(thing->go.pl),df); } fclose(df); } void read_grid_from_file (grid * thing, FILE * df) { int x,y; point * gd; int i,j; fscanf(df,"%d %d",&x,&y); if (DEBUG > 0) { printf ("%d %d\n",x,y); } gd = (point *) malloc(sizeof(point)*x*y); for (i=0;i 0) { for (i=0;ix = x; thing->y = y; thing->point_list = gd; } void read_polylist_from_file (polylist * thing, FILE * df) { int verts, polys, sides; /* # of points, polygons , and sides */ point * vt; /* tempory point list */ polygon * pl; /* temporary polygon list */ int i,j; /* indexes for for loop */ /* open the file */ fscanf(df,"%d %d %d",&verts,&polys,&sides); vt = (point *) malloc(sizeof(point)*verts); /* read in the points */ for (i=0;i 0) { for (i=0;i 0) { for(i=0;ipoints = verts; thing->polys = polys; thing->point_list = vt; thing->poly_list = pl; }