#define ROOT_HALF .707106781186547524400844362104849039284835937688474036588 #include #include #include extern const char *__progname; #include "allocv.h" typedef struct pt2 PT2; typedef struct pt3 PT3; typedef struct csrv CSRV; typedef struct tri TRI; typedef struct point POINT; struct pt2 { double x; double y; } ; #define MAKEPT2(xv,yv) ((PT2){.x=(xv),.y=(yv)}) struct pt3 { double x; double y; double z; } ; #define MAKEPT3(xv,yv,zv) ((PT3){.x=(xv),.y=(yv),.z=(zv)}) struct csrv { PT3 cs; PT3 norm; } ; struct point { int pt; PT3 normal; } ; struct tri { int material; #define MAT_WHITE 0 #define MAT_LIGHT 1 #define MAT_DARK 2 int px[3]; } ; static ALLOCV *pts; static ALLOCV *points; static ALLOCV *tris; static void init_arrays(void) { pts = allocv_init(sizeof(PT3)); points = allocv_init(sizeof(POINT)); tris = allocv_init(sizeof(TRI)); } #if 0 static int newpt(PT3 loc) { int x; x = allocv_new(&pts); *(PT3 *)allocv_el(&pts,x) = loc; return(x); } #endif #if 0 static int newpoint(int loc, PT3 norm) { int x; x = allocv_new(&points); if (! allocv_okx(&pts,loc)) abort(); *(POINT *)allocv_el(&points,x) = (POINT){ .pt=loc, .normal=unit(norm) }; return(x); } #endif #if 0 static int newtri(int a, int b, int c) { int x; x = allocv_new(&tris); if ( !allocv_okx(&points,a) || !allocv_okx(&points,b) || !allocv_okx(&points,c) ) abort(); *(TRI *)allocv_el(&tris,x) = (TRI){ .material=cur_material, .px={ [0]=a, [1]=b, [2]=c } }; return(x); } #endif static void dump(void) { int i; int n; printf("ModelV1\n"); printf("3 %d %d %d\n",allocv_n(pts),allocv_n(points),allocv_n(tris)); printf("White 0 0 0 .7 .7 .7 10 .5\n"); printf("Light 0 0 0 .4 .4 .4 10 .1\n"); printf("Dark 0 0 0 .2 .2 .2 0 0\n"); n = allocv_n(pts); for (i=0;ix,e->y,e->z); } n = allocv_n(points); for (i=0;ipt,e->normal.x,e->normal.y,e->normal.z); } n = allocv_n(tris); for (i=0;imaterial,e->px[0],e->px[1],e->px[2]); } } int main(int, char **); int main(int ac, char **av) { if (ac != 1) { av=av; fprintf(stderr,"Usage: %s\n",__progname); exit(1); } init_arrays(); dump(); return(0); }