--- ray/src/rt/rv2.c 2009/01/14 20:27:00 2.59 +++ ray/src/rt/rv2.c 2013/10/18 17:04:13 2.64 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rv2.c,v 2.59 2009/01/14 20:27:00 greg Exp $"; +static const char RCSid[] = "$Id: rv2.c,v 2.64 2013/10/18 17:04:13 greg Exp $"; #endif /* * rv2.c - command routines used in tracing a view. @@ -13,6 +13,8 @@ static const char RCSid[] = "$Id: rv2.c,v 2.59 2009/01 #include #include "platform.h" +#include "rtprocess.h" /* win_popen() */ +#include "paths.h" #include "ray.h" #include "source.h" #include "ambient.h" @@ -61,7 +63,7 @@ getrepaint( /* get area and repaint */ void -getview( /* get/show view parameters */ +getview( /* get/show/save view parameters */ char *s ) { @@ -80,7 +82,7 @@ getview( /* get/show view parameters */ error(COMMAND, "bad view option(s)"); return; } - if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ + if (nextword(buf, sizeof(buf), s) != NULL) { /* write to a file */ if ((fname = getpath(buf, NULL, 0)) == NULL || (fp = fopen(fname, "a")) == NULL) { sprintf(errmsg, "cannot open \"%s\"", buf); @@ -162,8 +164,8 @@ lastview( /* return to a previous view */ char *fname; int success; VIEW nv; - - if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ + /* get parameters from a file */ + if (nextword(buf, sizeof(buf), s) != NULL) { nv = stdview; if ((fname = getpath(buf, "", R_OK)) == NULL || (success = viewfile(fname, &nv, NULL)) == -1) { @@ -204,11 +206,7 @@ saveview( /* save view to rad file */ } s = sskip(s); } - while (isspace(*s)) - s++; - if (*s) - atos(rifname, sizeof(rifname), s); - else if (rifname[0] == '\0') { + if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) { error(COMMAND, "no previous rad file"); return; } @@ -241,9 +239,7 @@ loadview( /* load view from rad file */ s = sskip(s); else strcat(buf, "1"); - if (*s) - atos(rifname, sizeof(rifname), s); - else if (rifname[0] == '\0') { + if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) { error(COMMAND, "no previous rad file"); return; } @@ -341,7 +337,6 @@ getrotate( /* rotate camera */ ) { VIEW nv = ourview; - FVECT v1; double angle, elev, zfact; elev = 0.0; zfact = 1.0; @@ -350,11 +345,9 @@ getrotate( /* rotate camera */ return; } spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); - if (elev != 0.0) { - fcross(v1, nv.vdir, ourview.vup); - normalize(v1); - spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); - } + if (elev != 0.0) + geodesic(nv.vdir, nv.vdir, nv.vup, elev*(PI/180.), GEOD_RAD); + zoomview(&nv, zfact); newview(&nv); } @@ -380,6 +373,52 @@ getpivot( /* pivot viewpoint */ void +getorigin( /* origin viewpoint */ + char *s +) +{ + VIEW nv = ourview; + double d; + /* get new view origin */ + if (!sscanvec(s, nv.vp)) { + int x, y; + RAY thisray; + if (dev->getcur == NULL) + return; + (*dev->comout)("Pick point on surface for new origin\n"); + if ((*dev->getcur)(&x, &y) == ABORT) + return; + if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, + &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { + error(COMMAND, "not on image"); + return; + } + rayorigin(&thisray, PRIMARY, NULL, NULL); + if (!localhit(&thisray, &thescene)) { + error(COMMAND, "not a local object"); + return; + } + if (thisray.rod < 0.0) /* don't look through other side */ + flipsurface(&thisray); + VSUM(nv.vp, thisray.rop, thisray.ron, 2.0*FTINY); + VCOPY(nv.vdir, thisray.ron); + } else if (!sscanvec(sskip2(s,3), nv.vdir) || normalize(nv.vdir) == 0.0) + VCOPY(nv.vdir, ourview.vdir); + + d = DOT(nv.vdir, nv.vup); /* need different up vector? */ + if (d*d >= 1.-2.*FTINY) { + int i; + nv.vup[0] = nv.vup[1] = nv.vup[2] = 0.0; + for (i = 3; i--; ) + if (nv.vdir[i]*nv.vdir[i] < 0.34) + break; + nv.vup[i] = 1.; + } + newview(&nv); +} + + +void getexposure( /* get new exposure */ char *s ) @@ -539,7 +578,7 @@ setparam( /* get/set program parameter */ if (s[0] == '\0') { (*dev->comout)( - "aa ab ad ar as av aw b bv dc dv dj ds dt i lr lw me ma mg ms ps pt sj st u: "); + "aa ab ad ar as av aw b bv dc dv dj ds dt i lr lw me ma mg ms ps pt ss st u: "); (*dev->comin)(buf, NULL); s = buf; } @@ -687,8 +726,8 @@ setparam( /* get/set program parameter */ break; case 's': /* specular */ switch (s[1]) { - case 'j': /* jitter */ - getparam(s+2, "specular jitter", 'r', + case 's': /* sampling */ + getparam(s+2, "specular sampling", 'r', (void *)&specjitter); break; case 't': /* threshold */ @@ -716,15 +755,14 @@ traceray( /* trace a single ray */ char *s ) { - char buf[128]; - int x, y; - OBJREC *ino; - RAY thisray; + RAY thisray; + char buf[512]; thisray.rmax = 0.0; if (!sscanvec(s, thisray.rorg) || !sscanvec(sskip2(s,3), thisray.rdir)) { + int x, y; if (dev->getcur == NULL) return; @@ -751,6 +789,8 @@ traceray( /* trace a single ray */ OBJREC *mat = NULL; OBJREC *mod = NULL; char matspec[256]; + OBJREC *ino; + matspec[0] = '\0'; if (thisray.ro->omod != OVOID) { mod = objptr(thisray.ro->omod); @@ -803,12 +843,8 @@ writepict( /* write the picture to a file */ FILE *fp; COLR *scanline; int y; - - while (isspace(*s)) - s++; - if (*s) - atos(buf, sizeof(buf), s); - else if (buf[0] == '\0') { + /* XXX relies on words.c 2.11 behavior */ + if (nextword(buf, sizeof(buf), s) == NULL && !buf[0]) { error(COMMAND, "no file"); return; }