1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include "Vlib.h"
#include <string.h>
int VWriteObject(f, obj)
FILE *f;
VObject *obj; {
int i, j, k, points;
VPolygon **q;
VPoint *p;
/*
* Total the number of vertices in all of the object's polygons
*/
points = 0;
q = obj->polygon;
for (i=0; i<obj->numPolys; ++i) {
points += q[i]->numVtces;
}
/*
* Print the header
*/
fprintf (f, "%s\n%d %d\n", obj->name, points, obj->numPolys);
/*
* Print the point list
*/
k = 1;
q = obj->polygon;
for (i=0; i<obj->numPolys; ++i) {
for ((j=0, p=q[i]->vertex); j<q[i]->numVtces; (++p, ++j)) {
fprintf(f, "%d %g %g %g\n", k, p->x, p->y, p->z);
++k;
}
}
/*
* Print the polygon list
*/
k = 1;
q = obj->polygon;
for (i=0; i<obj->numPolys; ++i) {
if (q[i]->backColor) {
fprintf(f, "(%s %s) %d",
q[i]->color->color_name,
q[i]->backColor->color_name,
q[i]->numVtces);;
}
else if (q[i]->flags & PolyClipBackface) {
fprintf(f, "(%s clip) %d",
q[i]->color->color_name,
q[i]->numVtces);
}
else {
fprintf(f, "%s %d",
q[i]->color->color_name,
q[i]->numVtces);
}
for (j=0; j<q[i]->numVtces; ++j)
fprintf(f, " %d", k++);
fprintf (f, "\n");
}
return ferror(f) ? -1 : 0;
}
|