--- ray/src/common/image.c 1990/01/08 14:45:52 1.5 +++ ray/src/common/image.c 1990/09/21 17:06:31 1.11 @@ -65,6 +65,20 @@ register VIEW *v; } +normaspect(va, ap, xp, yp) /* fix pixel aspect or resolution */ +double va; /* view aspect ratio */ +double *ap; /* pixel aspect in (or out if 0) */ +int *xp, *yp; /* x and y resolution in (or out if *ap!=0) */ +{ + if (*ap <= FTINY) + *ap = va * *xp / *yp; /* compute pixel aspect */ + else if (va * *xp > *ap * *yp) + *xp = *yp / va * *ap + .5; /* reduce x resolution */ + else + *yp = *xp * va / *ap + .5; /* reduce y resolution */ +} + + viewray(orig, direc, v, x, y) /* compute ray origin and direction */ FVECT orig, direc; register VIEW *v; @@ -105,15 +119,20 @@ FVECT p; if (zp != NULL) *zp = DOT(disp,v->vdir); } else { /* perspective view */ - d = 1.0/DOT(disp,v->vdir); + d = DOT(disp,v->vdir); if (zp != NULL) { *zp = sqrt(DOT(disp,disp)); if (d < 0.0) *zp = -*zp; } - disp[0] *= d; - disp[1] *= d; - disp[2] *= d; + if (d < 0.0) /* fold pyramid */ + d = -d; + if (d > FTINY) { + d = 1.0/d; + disp[0] *= d; + disp[1] *= d; + disp[2] *= d; + } } *xp = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff; *yp = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff; @@ -129,7 +148,7 @@ register char *av[]; #define check(c,n) if ((av[0][c]&&av[0][c]!=' ') || n>=ac) return(-1) extern double atof(); - if (av[0][0] != '-' || av[0][1] != 'v') + if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v') return(-1); switch (av[0][2]) { case 't': /* type */ @@ -191,7 +210,7 @@ register char *s; while (*s == ' ') s++; - do { + while (*s) { ac = 0; do { av[ac++] = s; @@ -204,8 +223,9 @@ register char *s; if (na+1 < ac) s = av[na+1]; nvopts++; - } - } while (*s); + } else if (ac > 1) + s = av[1]; + } return(nvopts); } @@ -219,7 +239,7 @@ FILE *fp; fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]); fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]); fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert); - fprintf(fp, " -vs %d -vl %d", vp->hoff, vp->voff); + fprintf(fp, " -vs %.6g -vl %.6g", vp->hoff, vp->voff); } @@ -244,9 +264,10 @@ char *s; int -viewfile(fname, vp) /* get view from file */ +viewfile(fname, vp, xp, yp) /* get view from file */ char *fname; VIEW *vp; +int *xp, *yp; { extern char *progname; FILE *fp; @@ -259,6 +280,10 @@ VIEW *vp; gothview = 0; getheader(fp, gethview); + + if (xp != NULL && yp != NULL + && fgetresolu(xp, yp, fp) == -1) + gothview = 0; fclose(fp);