#include #include #include #include #include "3d.h" #include "model.h" static MODEL *m; static int matx; static int lx[12]; 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}); } static int addloc(double x, double y, double z) { int lx; LOCATION *l; lx = new_location(m); l = get_location(m,lx); l->l.x = x; l->l.y = y; l->l.z = z; return(lx); } static int ptx(int lx, PT3 normal) { int px; POINT *p; px = new_point(m); p = get_point(m,px); p->loc = lx; p->type = PT_SURFACE; p->normal = pt3_to_xyz(normal); return(px); } static void tri(int pt, int pa, int pb) { TRIANGLE *t; t = get_triangle(m,new_triangle(m)); t->material = matx; t->corner[0] = pt; t->corner[1] = pa; t->corner[2] = pb; #if 0 printf("triangle %d: (%g,%g,%g) - (%g,%g,%g) - (%g,%g,%g)\n", t->inx, get_location(m,get_point(m,pt)->loc)->l.x, get_location(m,get_point(m,pt)->loc)->l.y, get_location(m,get_point(m,pt)->loc)->l.z, get_location(m,get_point(m,pa)->loc)->l.x, get_location(m,get_point(m,pa)->loc)->l.y, get_location(m,get_point(m,pa)->loc)->l.z, get_location(m,get_point(m,pb)->loc)->l.x, get_location(m,get_point(m,pb)->loc)->l.y, get_location(m,get_point(m,pb)->loc)->l.z); #endif } static void face(int t1, int t2, int t3, int t4, int t5, int n) { PT3 normal; int tpx[5]; normal = unit3(xyz_to_pt3(get_location(m,n)->l)); tpx[0] = ptx(lx[t1],normal); tpx[1] = ptx(lx[t2],normal); tpx[2] = ptx(lx[t3],normal); tpx[3] = ptx(lx[t4],normal); tpx[4] = ptx(lx[t5],normal); tri(tpx[0],tpx[4],tpx[3]); tri(tpx[0],tpx[3],tpx[2]); tri(tpx[0],tpx[2],tpx[1]); } int main(void); int main(void) { double sqrt5; double r; double h; double s36; double c36; double s72; double c72; double s144; double c144; MATERIAL *mat; OBJECT *o; int i; 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; h = 1 / sqrt5; r = 2 / sqrt5; m = new_model(); 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; lx[ 0] = addloc(0,0,1); lx[ 1] = addloc(r,0,h); lx[ 2] = addloc(r*c72,r*s72,h); lx[ 3] = addloc(r*c144,r*s144,h); lx[ 4] = addloc(r*c144,-r*s144,h); lx[ 5] = addloc(r*c72,-r*s72,h); lx[ 6] = addloc(0,0,-1); lx[ 7] = addloc(-r,0,-h); lx[ 8] = addloc(-r*c72,r*s72,-h); lx[ 9] = addloc(-r*c144,r*s144,-h); lx[10] = addloc(-r*c144,-r*s144,-h); lx[11] = addloc(-r*c72,-r*s72,-h); face(1,2,3,4,5, 0); face(0,5,10,9,2, 1); face(0,1,9,8,3, 2); face(0,2,8,7,4, 3); face(0,3,7,11,5, 4); face(0,4,11,10,1, 5); face(7,8,9,10,11, 6); face(6,11,4,3,8, 7); face(6,7,3,2,9, 8); face(6,8,2,1,10, 9); face(6,9,1,5,11, 10); face(6,10,5,4,7, 11); o = get_object(m,new_object(m)); o->ntriangles = n_triangles(m); o->triangles = malloc(o->ntriangles*sizeof(*o->triangles)); for (i=o->ntriangles-1;i>=0;i--) o->triangles[i] = i; save_model(m,stdout); return(0); }