#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 sqrt3; double r; double h; PPT tloc[4]; int tv[4]; int nt; int mx; 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 face(int x1, int x2, int x3) { int p1; int p2; int p3; POINT *p; int tx; TRIANGLE *t; PT3 n; n = unit3(add3(tloc[x1].loc,add3(tloc[x2].loc,tloc[x3].loc))); p1 = new_point(m); p = get_point(m,p1); p->loc = tloc[x1].mx; p->type = PT_SURFACE; p->normal = (XYZ){.x=n.x,.y=n.y,.z=n.z}; p2 = new_point(m); p = get_point(m,p2); p->loc = tloc[x2].mx; p->type = PT_SURFACE; p->normal = (XYZ){.x=n.x,.y=n.y,.z=n.z}; p3 = new_point(m); p = get_point(m,p3); p->loc = tloc[x3].mx; p->type = PT_SURFACE; p->normal = (XYZ){.x=n.x,.y=n.y,.z=n.z}; tx = new_triangle(m); tv[nt++] = tx; t = get_triangle(m,tx); t->material = mx; t->corner[0] = p1; t->corner[1] = p2; t->corner[2] = p3; } 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(); sqrt3 = sqrt(3); h = -1.0 / 3; r = sqrt(8) / 3; mx = new_material(m); mat = get_material(m,mx); mat->name = strdup("M"); mat->selflum = (RGB){0,0,0}; mat->reflect = (RGB){.7,.7,.7}; mat->spec_exp = 10; mat->spec_mul = .5; tloc[ 0] = add_loc(MAKEPT3(0,0,1)); tloc[ 1] = add_loc(MAKEPT3(r,0,h)); tloc[ 2] = add_loc(MAKEPT3(-r/2,r*sqrt3/2,h)); tloc[ 3] = add_loc(MAKEPT3(-r/2,-r*sqrt3/2,h)); nt = 0; face(0,2,1); face(0,3,2); face(0,1,3); face(1,2,3); add_obj(nt,&tv[0]); save_model(m,stdout); return(0); }