/* * polyobj * * construct a polygon from a object token list. */ void polyobj(int n, Token *dp, int fill) { int i, j; float vect[4], result[4]; for (i = 0, j = 0; i < n; i++, j += 3) { vect[V_X] = dp[j + V_X].f; vect[V_Y] = dp[j + V_Y].f; vect[V_Z] = dp[j + V_Z].f; vect[V_W] = 1; multvector(result, vect, vdevice.transmat->m); p[i][V_X] = result[V_X]; p[i][V_Y] = result[V_Y]; p[i][V_Z] = result[V_Z]; p[i][V_W] = result[V_W]; } if (fill) vdevice.fill = polymodeflag; else vdevice.fill = 0; dopoly(n); vdevice.cpW[V_X] = dp[V_X].f; vdevice.cpW[V_Y] = dp[V_Y].f; vdevice.cpW[V_Z] = dp[V_Z].f; }
/* * pclos * * draw the polygon started by the above. */ void pclos(void) { float lstx, lsty, lstz; Vector result; int i, j; Token *tok; if (!vdevice.initialised) verror("pclos: vogl not initialised"); vdevice.inpolygon = 0; if (vdevice.inobject) { tok = newtokens(2 + 3 * (numv + 1)); tok[0].i = POLYF; tok[1].i = numv + 1; for (i = 0, j = 2; i <= numv; i++, j += 3) { tok[j + V_X].f = p[i][V_X]; tok[j + V_Y].f = p[i][V_Y]; tok[j + V_Z].f = p[i][V_Z]; } return; } lstx = p[numv][V_X]; lsty = p[numv][V_Y]; lstz = p[numv][V_Z]; numv++; for (i = 0; i < numv; i++) { multvector(result, p[i], vdevice.transmat->m); p[i][V_X] = result[V_X]; p[i][V_Y] = result[V_Y]; p[i][V_Z] = result[V_Z]; p[i][V_W] = result[V_W]; } dopoly(numv); vdevice.cpW[V_X] = lstx; vdevice.cpW[V_Y] = lsty; vdevice.cpW[V_Z] = lstz; }
/* * polf * * construct a filled polygon from an array of points provided * by the user. */ void polf(long int nv, float (*dp)[3]) { int i, j; Vector vect, result; Token *tok; long n = nv; if (!vdevice.initialised) verror("poly: vogl not initialised"); vdevice.fill = polymodeflag; if (vdevice.inobject) { tok = newtokens(2 + 3 * n); tok[0].i = POLYF; tok[1].i = n; for (i = 0, j = 2; i < n; i++, j += 3) { tok[j + V_X].f = dp[i][V_X]; tok[j + V_Y].f = dp[i][V_Y]; tok[j + V_Z].f = dp[i][V_Z]; } return; } for (i = 0; i < n; i++) { vect[V_X] = dp[i][V_X]; vect[V_Y] = dp[i][V_Y]; vect[V_Z] = dp[i][V_Z]; vect[V_W] = 1; multvector(result, vect, vdevice.transmat->m); p[i][V_X] = result[V_X]; p[i][V_Y] = result[V_Y]; p[i][V_Z] = result[V_Z]; p[i][V_W] = result[V_W]; } dopoly(n); vdevice.cpW[V_X] = dp[0][V_X]; vdevice.cpW[V_Y] = dp[0][V_Y]; vdevice.cpW[V_Z] = dp[0][V_Z]; vdevice.fill = 0; }
main() { dopoly(x, y, ARRSIZE(x)); printf("Done.\n"); return 0; }
void fillpolyop(Image *dst, Point *p, int np, int wind, Image *src, Point sp, Drawop op) { dopoly('P', dst, p, np, wind, 0, 0, src, &sp, op); }
void fillpoly(Image *dst, Point *p, int np, int wind, Image *src, Point sp) { dopoly('P', dst, p, np, wind, 0, 0, src, &sp, SoverD); }
void polyop(Image *dst, Point *p, int np, int end0, int end1, int radius, Image *src, Point sp, Drawop op) { dopoly('p', dst, p, np, end0, end1, radius, src, &sp, op); }
void poly(Image *dst, Point *p, int np, int end0, int end1, int radius, Image *src, Point sp) { dopoly('p', dst, p, np, end0, end1, radius, src, &sp, SoverD); }