void do_tri( /* put out smoothed triangle */ char *mat, C_VERTEX *cv1, C_VERTEX *cv2, C_VERTEX *cv3, int iv ) { static int ntris; BARYCCM bvecs; RREAL bcoor[3][3]; C_VERTEX *cvt; FVECT v1, v2, v3; FVECT n1, n2, n3; register int i; if (iv) { /* swap vertex order if inverted */ cvt = cv1; cv1 = cv3; cv3 = cvt; } xf_xfmpoint(v1, cv1->p); xf_xfmpoint(v2, cv2->p); xf_xfmpoint(v3, cv3->p); /* compute barycentric coords. */ if (comp_baryc(&bvecs, v1, v2, v3) < 0) return; /* degenerate triangle! */ printf("\n%s texfunc T-nor\n", mat); /* put out texture */ printf("4 dx dy dz %s\n0\n", TCALNAME); xf_rotvect(n1, cv1->n); xf_rotvect(n2, cv2->n); xf_rotvect(n3, cv3->n); for (i = 0; i < 3; i++) { bcoor[i][0] = n1[i]; bcoor[i][1] = n2[i]; bcoor[i][2] = n3[i]; } put_baryc(&bvecs, bcoor, 3); /* put out triangle */ printf("\nT-nor polygon %st%d\n", object(), ++ntris); printf("0\n0\n9\n"); putv(v1); putv(v2); putv(v3); }
void triangle( /* put out a triangle */ char *pn, char *mod, char *obj, VERTEX *v1, VERTEX *v2, VERTEX *v3 ) { static char vfmt[] = "%18.12g %18.12g %18.12g\n"; static int ntri = 0; int flatness = ISFLAT; BARYCCM bvecs; RREAL bvm[3][3]; int i; /* compute barycentric coordinates */ if (v1->flags & v2->flags & v3->flags & (V_HASINDX|V_HASNORM)) if (comp_baryc(&bvecs, v1->pos, v2->pos, v3->pos) < 0) return; /* check flatness */ if (v1->flags & v2->flags & v3->flags & V_HASNORM) { flatness = flat_tri(v1->pos, v2->pos, v3->pos, v1->nor, v2->nor, v3->nor); if (flatness == DEGEN) return; } /* put out texture (if any) */ if (flatness == ISBENT || flatness == RVBENT) { printf("\n%s texfunc %s\n", mod, TEXNAME); mod = TEXNAME; printf("4 dx dy dz %s\n", TCALNAME); printf("0\n"); for (i = 0; i < 3; i++) { bvm[i][0] = v1->nor[i]; bvm[i][1] = v2->nor[i]; bvm[i][2] = v3->nor[i]; } put_baryc(&bvecs, bvm, 3); } /* put out pattern (if any) */ if (*pn && (v1->flags & v2->flags & v3->flags & V_HASINDX)) { printf("\n%s colorpict %s\n", mod, PATNAME); mod = PATNAME; printf("7 noneg noneg noneg %s %s u v\n", pn, TCALNAME); printf("0\n"); for (i = 0; i < 2; i++) { bvm[i][0] = v1->ndx[i]; bvm[i][1] = v2->ndx[i]; bvm[i][2] = v3->ndx[i]; } put_baryc(&bvecs, bvm, 2); } /* put out (reversed) triangle */ printf("\n%s polygon %s.%d\n", mod, obj, ++ntri); printf("0\n0\n9\n"); if (flatness == RVFLAT || flatness == RVBENT) { printf(vfmt, v3->pos[0],v3->pos[1],v3->pos[2]); printf(vfmt, v2->pos[0],v2->pos[1],v2->pos[2]); printf(vfmt, v1->pos[0],v1->pos[1],v1->pos[2]); } else { printf(vfmt, v1->pos[0],v1->pos[1],v1->pos[2]); printf(vfmt, v2->pos[0],v2->pos[1],v2->pos[2]); printf(vfmt, v3->pos[0],v3->pos[1],v3->pos[2]); } }
int puttri( /* put out a triangle */ char *v1, char *v2, char *v3 ) { char *mod; VNDX v1i, v2i, v3i; BARYCCM bvecs; RREAL bcoor[3][3]; int texOK = 0, patOK; int flatness; int i; if ((mod = getmtl()) == NULL) return(-1); if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3)) return(0); /* compute barycentric coordinates */ if (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0) flatness = flat_tri(vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]], vnlist[v1i[2]], vnlist[v2i[2]], vnlist[v3i[2]]); else flatness = ISFLAT; switch (flatness) { case DEGEN: /* zero area */ ndegen++; return(-1); case RVFLAT: /* reversed normals, but flat */ case ISFLAT: /* smoothing unnecessary */ texOK = 0; break; case RVBENT: /* reversed normals with smoothing */ case ISBENT: /* proper smoothing */ texOK = 1; break; } if (flatten) texOK = 0; #ifdef TEXMAPS patOK = mapname[0] && (v1i[1]>=0 && v2i[1]>=0 && v3i[1]>=0); #else patOK = 0; #endif if (texOK | patOK) if (comp_baryc(&bvecs, vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]]) < 0) texOK = patOK = 0; /* put out texture (if any) */ if (texOK) { printf("\n%s texfunc %s\n", mod, TEXNAME); mod = TEXNAME; printf("4 dx dy dz %s\n", TCALNAME); printf("0\n"); for (i = 0; i < 3; i++) { bcoor[i][0] = vnlist[v1i[2]][i]; bcoor[i][1] = vnlist[v2i[2]][i]; bcoor[i][2] = vnlist[v3i[2]][i]; } put_baryc(&bvecs, bcoor, 3); } #ifdef TEXMAPS /* put out pattern (if any) */ if (patOK) { printf("\n%s colorpict %s\n", mod, PATNAME); mod = PATNAME; printf("7 noneg noneg noneg %s %s u v\n", mapname, TCALNAME); printf("0\n"); for (i = 0; i < 2; i++) { bcoor[i][0] = vtlist[v1i[1]][i]; bcoor[i][1] = vtlist[v2i[1]][i]; bcoor[i][2] = vtlist[v3i[1]][i]; } put_baryc(&bvecs, bcoor, 2); } #endif /* put out (reversed) triangle */ printf("\n%s polygon %s.%d\n", mod, getonm(), faceno); printf("0\n0\n9\n"); if (flatness == RVFLAT || flatness == RVBENT) { pvect(vlist[v3i[0]]); pvect(vlist[v2i[0]]); pvect(vlist[v1i[0]]); } else { pvect(vlist[v1i[0]]); pvect(vlist[v2i[0]]); pvect(vlist[v3i[0]]); } return(1); }