--- ray/src/rt/rv2.c 1990/01/30 11:37:37 1.18 +++ ray/src/rt/rv2.c 1991/07/19 15:22:02 1.25 @@ -63,6 +63,7 @@ char *s; } fputs(progname, fp); fprintview(&ourview, fp); + fputs(sskip(s), fp); fputs("\n", fp); fclose(fp); return; @@ -150,7 +151,7 @@ char *s; newview(&nv); return; } - if (oldview.horiz == 0) { /* no old view! */ + if (oldview.type == 0) { /* no old view! */ error(COMMAND, "no previous view"); return; } @@ -170,18 +171,12 @@ char *s; if (getinterest(s, 1, nv.vdir, &zfact) < 0) return; + nv.type = ourview.type; VCOPY(nv.vp, ourview.vp); VCOPY(nv.vup, ourview.vup); nv.hoff = ourview.hoff; nv.voff = ourview.voff; - if ((nv.type = ourview.type) == VT_PAR) { - nv.horiz = ourview.horiz / zfact; - nv.vert = ourview.vert / zfact; - } else { - nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / - (PI/180./2.); - nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / - (PI/180./2.); - } + nv.horiz = ourview.horiz; nv.vert = ourview.vert; + zoomview(&nv, zfact); newview(&nv); } @@ -211,6 +206,7 @@ char *s; error(COMMAND, "missing angle"); return; } + nv.type = ourview.type; VCOPY(nv.vp, ourview.vp); VCOPY(nv.vup, ourview.vup); nv.hoff = ourview.hoff; nv.voff = ourview.voff; @@ -220,15 +216,8 @@ char *s; normalize(v1); spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); } - if ((nv.type = ourview.type) == VT_PAR) { - nv.horiz = ourview.horiz / zfact; - nv.vert = ourview.vert / zfact; - } else { - nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / - (PI/180./2.); - nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / - (PI/180./2.); - } + nv.horiz = ourview.horiz; nv.vert = ourview.vert; + zoomview(&nv, zfact); newview(&nv); } @@ -312,6 +301,69 @@ char *s; } +getparam(str, dsc, typ, ptr) /* get variable from user */ +char *str, *dsc; +int typ; +register union {int i; double d; COLOR C;} *ptr; +{ + extern char *index(); + int i0; + double d0, d1, d2; + char buf[48]; + + switch (typ) { + case 'i': /* integer */ + if (sscanf(str, "%d", &i0) != 1) { + (*dev->comout)(dsc); + sprintf(buf, " (%d): ", ptr->i); + (*dev->comout)(buf); + (*dev->comin)(buf, NULL); + if (sscanf(buf, "%d", &i0) != 1) + break; + } + ptr->i = i0; + break; + case 'r': /* real */ + if (sscanf(str, "%lf", &d0) != 1) { + (*dev->comout)(dsc); + sprintf(buf, " (%.6g): ", ptr->d); + (*dev->comout)(buf); + (*dev->comin)(buf, NULL); + if (sscanf(buf, "%lf", &d0) != 1) + break; + } + ptr->d = d0; + break; + case 'b': /* boolean */ + if (sscanf(str, "%1s", buf) != 1) { + (*dev->comout)(dsc); + sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n'); + (*dev->comout)(buf); + (*dev->comin)(buf, NULL); + if (buf[0] == '\0' || + index("yY+1tTnN-0fF", buf[0]) == NULL) + break; + } + ptr->i = index("yY+1tT", buf[0]) != NULL; + break; + case 'C': /* color */ + if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { + (*dev->comout)(dsc); + sprintf(buf, " (%.6g %.6g %.6g): ", + colval(ptr->C,RED), + colval(ptr->C,GRN), + colval(ptr->C,BLU)); + (*dev->comout)(buf); + (*dev->comin)(buf, NULL); + if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) + break; + } + setcolor(ptr->C, d0, d1, d2); + break; + } +} + + setparam(s) /* get/set program parameter */ register char *s; { @@ -329,12 +381,13 @@ register char *s; extern int ambdiv; extern int ambssamp; extern int ambounce; - int i0; - double d0, d1, d2; + extern int directinvis; + extern int do_irrad; char buf[128]; if (s[0] == '\0') { - (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: "); + (*dev->comout)( + "aa ab ad ar as av b dc di dj dt i lr lw sp st: "); (*dev->comin)(buf, NULL); s = buf; } @@ -342,26 +395,10 @@ register char *s; case 'l': /* limit */ switch (s[1]) { case 'w': /* weight */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "limit weight (%.6g): ", - minweight); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - minweight = d0; + getparam(s+2, "limit weight", 'r', &minweight); break; case 'r': /* reflection */ - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "limit reflection (%d): ", - maxdepth); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - maxdepth = i0; + getparam(s+2, "limit reflection", 'i', &maxdepth); break; default: goto badparam; @@ -370,113 +407,47 @@ register char *s; case 'd': /* direct */ switch (s[1]) { case 'j': /* jitter */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "direct jitter (%.6g): ", - dstrsrc); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - dstrsrc = d0; + getparam(s+2, "direct jitter", 'r', &dstrsrc); break; case 'c': /* certainty */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "direct certainty (%.6g): ", - shadcert); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - shadcert = d0; + getparam(s+2, "direct certainty", 'r', &shadcert); break; case 't': /* threshold */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "direct threshold (%.6g): ", - shadthresh); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - shadthresh = d0; + getparam(s+2, "direct threshold", 'r', &shadthresh); break; + case 'i': /* invisibility */ + getparam(s+2, "direct invisibility", + 'b', &directinvis); + break; default: goto badparam; } break; + case 'b': /* black and white */ + getparam(s+1, "black and white", 'b', &greyscale); + break; + case 'i': /* irradiance */ + getparam(s+1, "irradiance", 'b', &do_irrad); + break; case 'a': /* ambient */ switch (s[1]) { case 'v': /* value */ - if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) { - sprintf(buf, - "ambient value (%.6g %.6g %.6g): ", - colval(ambval,RED), - colval(ambval,GRN), - colval(ambval,BLU)); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf %lf %lf", - &d0, &d1, &d2) != 3) - break; - } - setcolor(ambval, d0, d1, d2); + getparam(s+2, "ambient value", 'C', ambval); break; case 'a': /* accuracy */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "ambient accuracy (%.6g): ", - ambacc); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - ambacc = d0; + getparam(s+2, "ambient accuracy", 'r', &ambacc); break; case 'd': /* divisions */ - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "ambient divisions (%d): ", - ambdiv); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - ambdiv = i0; + getparam(s+2, "ambient divisions", 'i', &ambdiv); break; case 's': /* samples */ - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "ambient super-samples (%d): ", - ambssamp); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - ambssamp = i0; + getparam(s+2, "ambient super-samples", 'i', &ambssamp); break; case 'b': /* bounces */ - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "ambient bounces (%d): ", - ambounce); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - ambounce = i0; + getparam(s+2, "ambient bounces", 'i', &ambounce); break; case 'r': - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "ambient resolution (%d): ", - ambres); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - ambres = i0; + getparam(s+2, "ambient resolution", 'i', &ambres); minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; break; default: @@ -486,26 +457,11 @@ register char *s; case 's': /* sample */ switch (s[1]) { case 'p': /* pixel */ - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "sample pixel (%d): ", psample); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - psample = i0; + getparam(s+2, "sample pixel", 'i', &psample); pdepth = 0; break; case 't': /* threshold */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "sample threshold (%.6g): ", - maxdiff); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - maxdiff = d0; + getparam(s+2, "sample threshold", 'r', &maxdiff); pdepth = 0; break; default: @@ -540,9 +496,12 @@ char *s; if ((*dev->getcur)(&x, &y) == ABORT) return; - viewray(thisray.rorg, thisray.rdir, &ourview, - (x+.5)/hresolu, (y+.5)/vresolu); - + if (viewray(thisray.rorg, thisray.rdir, &ourview, + (x+.5)/hresolu, (y+.5)/vresolu) < 0) { + error(COMMAND, "not on image"); + return; + } + } else if (normalize(thisray.rdir) == 0.0) { error(COMMAND, "zero ray direction"); return; @@ -609,6 +568,7 @@ char *s; fputexpos(exposure, fp); if (dev->pixaspect != 1.0) fputaspect(dev->pixaspect, fp); + fputformat(COLRFMT, fp); putc('\n', fp); fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);