--- ray/src/rt/rv2.c 1989/02/02 10:41:37 1.1 +++ ray/src/rt/rv2.c 1989/05/30 09:57:13 1.4 @@ -75,6 +75,7 @@ char *s; FILE *fp; char buf[128]; char *fname, *getpath(); + int change = 0; VIEW nv; if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ @@ -84,7 +85,7 @@ char *s; error(COMMAND, errmsg); return; } - fputs(VIEWSTR, fp); + fputs(progname, fp); fprintview(&ourview, fp); fputs("\n", fp); fclose(fp); @@ -94,37 +95,46 @@ char *s; (*dev->comout)(buf); (*dev->comin)(buf); if (buf[0] == CTRL(C)) return; - if (buf[0]) + if (buf[0] && buf[0] != ourview.type) { nv.type = buf[0]; - else + change++; + } else nv.type = ourview.type; sprintf(buf, "view point (%.6g %.6g %.6g): ", ourview.vp[0], ourview.vp[1], ourview.vp[2]); (*dev->comout)(buf); (*dev->comin)(buf); if (buf[0] == CTRL(C)) return; - if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) != 3) + if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3) + change++; + else VCOPY(nv.vp, ourview.vp); sprintf(buf, "view direction (%.6g %.6g %.6g): ", ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); (*dev->comout)(buf); (*dev->comin)(buf); if (buf[0] == CTRL(C)) return; - if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) != 3) + if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3) + change++; + else VCOPY(nv.vdir, ourview.vdir); sprintf(buf, "view up (%.6g %.6g %.6g): ", ourview.vup[0], ourview.vup[1], ourview.vup[2]); (*dev->comout)(buf); (*dev->comin)(buf); if (buf[0] == CTRL(C)) return; - if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) != 3) + if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3) + change++; + else VCOPY(nv.vup, ourview.vup); sprintf(buf, "view horiz and vert size (%.6g %.6g): ", ourview.horiz, ourview.vert); (*dev->comout)(buf); (*dev->comin)(buf); if (buf[0] == CTRL(C)) return; - if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) != 2) { + if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2) + change++; + else { nv.horiz = ourview.horiz; nv.vert = ourview.vert; } sprintf(buf, "x and y resolution (%d %d): ", @@ -132,10 +142,13 @@ char *s; (*dev->comout)(buf); (*dev->comin)(buf); if (buf[0] == CTRL(C)) return; - if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) != 2) { + if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2) + change++; + else { nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; } - newview(&nv); + if (change) + newview(&nv); } @@ -252,27 +265,25 @@ char *s; if (getinterest(s, 0, vc, &mag) < 0) return; - moveview(0.0, mag, vc); + moveview(0.0, 0.0, mag, vc); } getrotate(s) /* rotate camera */ char *s; { - extern double normalize(); + extern double normalize(), tan(), atan(); VIEW nv; FVECT v1; - double angle, elev; + double angle, elev, zfact; - elev = 0.0; - if (sscanf(s, "%lf %lf", &angle, &elev) < 1) { + elev = 0.0; zfact = 1.0; + if (sscanf(s, "%lf %lf %lf", &angle, &elev, &zfact) < 1) { error(COMMAND, "missing angle"); return; } - nv.type = ourview.type; VCOPY(nv.vp, ourview.vp); VCOPY(nv.vup, ourview.vup); - nv.horiz = ourview.horiz; nv.vert = ourview.vert; nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); if (elev != 0.0) { @@ -280,6 +291,15 @@ 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.); + } newview(&nv); } @@ -288,15 +308,16 @@ getpivot(s) /* pivot viewpoint */ register char *s; { FVECT vc; - double angle, mag; + double angle, elev, mag; - if (sscanf(s, "%lf", &angle) != 1) { + elev = 0.0; + if (sscanf(s, "%lf %lf", &angle, &elev) < 1) { error(COMMAND, "missing angle"); return; } - if (getinterest(sskip(s), 0, vc, &mag) < 0) + if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0) return; - moveview(angle, mag, vc); + moveview(angle, elev, mag, vc); }