/* File: simple_xyzc.c Reads two files: color_map file r[0] g[0] b[0] red, green, blue color map entries (float, float, float) ... model file nv nt number of vertices, number of triangles (int, int) x[0] y[0] z[0] c[0] x, y, z, color_index (float, float, float, int) ... x[nv-1] y[nv-1] z[nv-1] c[nv-1] "" t[0] t[1] t[2] first triangle verts 0, 1, 2 (int) ... t[3*(nt-1)] t[3*(nt-1)+1] t[3*(nt-1)+2] last tri verts 0, 1, 2 Displays the set of triangles. This program uses a number of standard C paradigms for accessing data, to show thier use. Typically one would use a less disparate set of methods, for consistency. */ #include #include #define MAXNCOLOR 1024 static int ncolor; static int color[MAXNCOLOR][3]; static int nvert; static float *x, *y, *z; static int *cind; static int ntri; static int *tri; #define GETMINMAX(MN, MX, V) { \ if ((V) < (MN)) (MN) = (V); \ if ((V) > (MX)) (MX) = (V); \ } void readCmap(char *fname) { int i; FILE *fpin; if (!(fpin = fopen(fname, "r"))) { fprintf(stderr, "readCmap could not open %s\n", fname); fflush(stderr); exit(1); } ncolor = 0; do { if (fscanf(fpin, "%d %d %d", &color[ncolor][0], &color[ncolor][1], &color[ncolor][2]) == 3) ncolor++; } while (!feof(fpin)); for (i=0; i 0) { *xmin = x[0]; *xmax = x[0]; *ymin = y[0]; *ymax = y[0]; *zmin = z[0]; *zmax = z[0]; } for (ivert=0; ivert