#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 p1, int p2, int p3) { PT3 normal; normal = unit3(cross( sub3(xyz_to_pt3(get_location(m,p1)->l),xyz_to_pt3(get_location(m,p2)->l)), sub3(xyz_to_pt3(get_location(m,p3)->l),xyz_to_pt3(get_location(m,p2)->l)) )); tri(ptx(lx[p1],normal),ptx(lx[p2],normal),ptx(lx[p3],normal)); } 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(0,1,5); face(0,5,4); face(0,4,3); face(0,3,2); face(0,2,1); face(1,9,10); face(9,1,2); face(2,8,9); face(8,2,3); face(3,7,8); face(7,3,4); face(4,11,7); face(11,4,5); face(5,10,11); face(10,5,1); face(6,11,10); face(6,10,9); face(6,9,8); face(6,8,7); face(6,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); }