#include #include #include #include #include "3d.h" #include "model.h" typedef struct ppt PPT; struct ppt { int mx; PT3 loc; } ; static MODEL *m; #if 0 static PT3 xyz_to_pt3(XYZ i) { return((PT3){i.x,i.y,i.z}); } static XYZ pt3_to_xyz(PT3 i) { return((XYZ){i.x,i.y,i.z}); } #endif 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; double ifrac; PPT dloc[20]; PPT iloc[12]; int dt[60*3]; int i; int matx; MATERIAL *mat; static const int iinit[12][2] = { { 0, 10 }, // 0 { 10, 0 }, // 1 { 0, 16 }, // 2 { 16, 0 }, // 3 { 0, 19 }, // 4 { 19, 0 }, // 5 { 15, 4 }, // 6 { 4, 15 }, // 7 { 15, 1 }, // 8 { 1, 15 }, // 9 { 15, 5 }, // 10 { 5, 15 } }; // 11 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}); } PPT fracloc(PPT x1, PPT x2, double f) { return(add_loc(add3(smul3(f,x1.loc),smul3(1-f,x2.loc)))); } void tri(int tip, int b1, int b2) { int tx; TRIANGLE *t; tx = new_triangle(m); dt[i++] = tx; t = get_triangle(m,tx); t->material = matx; t->corner[0] = tip; t->corner[1] = b1; t->corner[2] = b2; } void face(int x1, int x2, int x3, int x4, int x5, int i1, int i2, int i3, int i4, int i5) { int x[5]; int i[5]; int px[5]; int pi[5]; POINT *pt; 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; i[0] = i1; i[1] = i2; i[2] = i3; i[3] = i4; i[4] = i5; for (k=5-1;k>=0;k--) { px[k] = new_point(m); pt = get_point(m,px[k]); pt->loc = dloc[x[k]].mx; pt->type = PT_SURFACE; pt->normal = (XYZ){.x=n.x,.y=n.y,.z=n.z}; pi[k] = new_point(m); pt = get_point(m,pi[k]); pt->loc = iloc[i[k]].mx; pt->type = PT_SURFACE; pt->normal = (XYZ){.x=n.x,.y=n.y,.z=n.z}; } for (k=5-1;k>=0;k--) tri(px[k],pi[k],pi[(k+1)%5]); } 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; ifrac = (1 - c72) / (1 - c144); 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)); for (i=12-1;i>=0;i--) iloc[i] = fracloc(dloc[iinit[i][0]],dloc[iinit[i][1]],ifrac); i = 0; face(5,6,7,8,9, 3,5,8,0,6); face(0,9,16,19,6, 5,3,2,11,4); face(1,5,17,15,7, 8,5,10,11,9); face(2,6,18,16,8, 0,8,4,11,7); face(3,7,19,17,9, 6,0,9,11,2); face(4,8,15,18,5, 3,6,7,11,10); face(15,11,4,1,14, 9,7,6,1,8); face(16,12,0,2,10, 7,2,3,1,0); face(17,13,1,3,11, 2,10,5,1,6); face(18,14,2,4,12, 10,4,8,1,3); face(19,10,3,0,13, 4,9,0,1,5); face(14,13,12,11,10, 9,4,10,2,7); add_obj(i,&dt[0]); save_model(m,stdout); return(0); }