#include #include #include #include #include "3d.h" #include "model.h" typedef struct ppt PPT; struct ppt { int mx; PT3 loc; } ; static MODEL *m; int main(void); int main(void) { double sqrt5; double r1; double h1; double r2; double h2; double s36; double c36; double s72; double c72; double s144; double c144; PPT dloc[20]; int dt[12*3]; int i; int matx; MATERIAL *mat; PPT add_loc(PT3 at) { int inx; inx = new_location(m); get_location(m,inx)->l = (XYZ){at.x,at.y,at.z}; return((PPT){.mx=inx,.loc=at}); } void dface(int x1, int x2, int x3, int x4, int x5) { int x[5]; int p[5]; POINT *pt; int tx; TRIANGLE *t; PT3 n; int k; n = unit3(cross(sub3(dloc[x3].loc,dloc[x2].loc), sub3(dloc[x2].loc,dloc[x1].loc))); x[0] = x1; x[1] = x2; x[2] = x3; x[3] = x4; x[4] = x5; for (k=5-1;k>=0;k--) { p[k] = new_point(m); pt = get_point(m,p[k]); pt->loc = dloc[x[k]].mx; pt->type = PT_SURFACE; pt->normal = (XYZ){.x=n.x,.y=n.y,.z=n.z}; } tx = new_triangle(m); dt[i++] = tx; t = get_triangle(m,tx); t->material = matx; t->corner[0] = p[0]; t->corner[1] = p[1]; t->corner[2] = p[2]; tx = new_triangle(m); dt[i++] = tx; t = get_triangle(m,tx); t->material = matx; t->corner[0] = p[0]; t->corner[1] = p[2]; t->corner[2] = p[3]; tx = new_triangle(m); dt[i++] = tx; t = get_triangle(m,tx); t->material = matx; t->corner[0] = p[0]; t->corner[1] = p[3]; t->corner[2] = p[4]; } void add_obj(int nt, int *txv) { OBJECT *o; o = get_object(m,new_object(m)); o->ntriangles = nt; free(o->triangles); o->triangles = malloc(nt*sizeof(*o->triangles)); bcopy(txv,o->triangles,nt*sizeof(int)); } m = new_model(); sqrt5 = sqrt(5); c36 = (sqrt5 + 1) / 4; s36 = sqrt((5-sqrt5)/8); c72 = (sqrt5 - 1) / 4; s72 = sqrt((5+sqrt5)/8); c144 = - c36; s144 = s36; h1 = .7946544722917661; r1 = .6070619982066862; h2 = .1875924740850799; r2 = .9822469463768460; matx = new_material(m); mat = get_material(m,matx); mat->name = strdup("M"); mat->selflum = (RGB){0,0,0}; mat->reflect = (RGB){.7,.7,.7}; mat->spec_exp = 10; mat->spec_mul = .5; dloc[ 0] = add_loc(MAKEPT3(r1,0,h1)); dloc[ 1] = add_loc(MAKEPT3(r1*c72,r1*s72,h1)); dloc[ 2] = add_loc(MAKEPT3(r1*c144,r1*s144,h1)); dloc[ 3] = add_loc(MAKEPT3(r1*c144,-r1*s144,h1)); dloc[ 4] = add_loc(MAKEPT3(r1*c72,-r1*s72,h1)); dloc[ 5] = add_loc(MAKEPT3(r2,0,h2)); dloc[ 6] = add_loc(MAKEPT3(r2*c72,r2*s72,h2)); dloc[ 7] = add_loc(MAKEPT3(r2*c144,r2*s144,h2)); dloc[ 8] = add_loc(MAKEPT3(r2*c144,-r2*s144,h2)); dloc[ 9] = add_loc(MAKEPT3(r2*c72,-r2*s72,h2)); dloc[10] = add_loc(MAKEPT3(-r2,0,-h2)); dloc[11] = add_loc(MAKEPT3(-r2*c72,-r2*s72,-h2)); dloc[12] = add_loc(MAKEPT3(-r2*c144,-r2*s144,-h2)); dloc[13] = add_loc(MAKEPT3(-r2*c144,r2*s144,-h2)); dloc[14] = add_loc(MAKEPT3(-r2*c72,r2*s72,-h2)); dloc[15] = add_loc(MAKEPT3(-r1,0,-h1)); dloc[16] = add_loc(MAKEPT3(-r1*c72,-r1*s72,-h1)); dloc[17] = add_loc(MAKEPT3(-r1*c144,-r1*s144,-h1)); dloc[18] = add_loc(MAKEPT3(-r1*c144,r1*s144,-h1)); dloc[19] = add_loc(MAKEPT3(-r1*c72,r1*s72,-h1)); i = 0; dface( 0, 4, 3, 2, 1); dface( 0, 1, 6,13, 5); dface( 1, 2, 7,14, 6); dface( 2, 3, 8,10, 7); dface( 3, 4, 9,11, 8); dface( 4, 0, 5,12, 9); dface( 5,13,18,17,12); dface( 6,14,19,18,13); dface( 7,10,15,19,14); dface( 8,11,16,15,10); dface( 9,12,17,16,11); dface(15,16,17,18,19); add_obj(12*3,&dt[0]); save_model(m,stdout); return(0); }