--- ray/src/rt/rv2.c 2003/02/25 02:47:23 2.39 +++ ray/src/rt/rv2.c 2005/01/18 00:33:16 2.44 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rv2.c,v 2.39 2003/02/25 02:47:23 greg Exp $"; +static const char RCSid[] = "$Id: rv2.c,v 2.44 2005/01/18 00:33:16 greg Exp $"; #endif /* * rv2.c - command routines used in tracing a view. @@ -9,14 +9,15 @@ static const char RCSid[] = "$Id: rv2.c,v 2.39 2003/02 #include "copyright.h" -#include "ray.h" +#include +#include +#include "platform.h" +#include "ray.h" +#include "ambient.h" #include "otypes.h" - #include "rpaint.h" -#include - extern int psample; /* pixel sample size */ extern double maxdiff; /* max. sample difference */ @@ -34,9 +35,10 @@ extern char *progname; extern char *octname; -void -getframe(s) /* get a new frame */ -char *s; +extern void +getframe( /* get a new frame */ + char *s +) { if (getrect(s, &pframe) < 0) return; @@ -44,9 +46,10 @@ char *s; } -void -getrepaint(s) /* get area and repaint */ -char *s; +extern void +getrepaint( /* get area and repaint */ + char *s +) { RECT box; @@ -56,20 +59,20 @@ char *s; } -void -getview(s) /* get/show view parameters */ -char *s; +extern void +getview( /* get/show view parameters */ + char *s +) { FILE *fp; char buf[128]; char *fname; int change = 0; - VIEW nv; + VIEW nv = ourview; while (isspace(*s)) s++; if (*s == '-') { /* command line parameters */ - copystruct(&nv, &ourview); if (sscanview(&nv, s)) newview(&nv); else @@ -97,8 +100,7 @@ char *s; if (buf[0] && buf[0] != ourview.type) { nv.type = buf[0]; 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); @@ -106,8 +108,6 @@ char *s; if (buf[0] == CTRL('C')) return; if (sscanvec(buf, nv.vp)) 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); @@ -115,8 +115,6 @@ char *s; if (buf[0] == CTRL('C')) return; if (sscanvec(buf, nv.vdir)) 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); @@ -124,8 +122,6 @@ char *s; if (buf[0] == CTRL('C')) return; if (sscanvec(buf, nv.vup)) change++; - else - VCOPY(nv.vup, ourview.vup); sprintf(buf, "view horiz and vert size (%.6g %.6g): ", ourview.horiz, ourview.vert); (*dev->comout)(buf); @@ -133,9 +129,6 @@ char *s; if (buf[0] == CTRL('C')) return; if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2) change++; - else { - nv.horiz = ourview.horiz; nv.vert = ourview.vert; - } sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ", ourview.vfore, ourview.vaft); (*dev->comout)(buf); @@ -143,9 +136,6 @@ char *s; if (buf[0] == CTRL('C')) return; if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2) change++; - else { - nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; - } sprintf(buf, "view shift and lift (%.6g %.6g): ", ourview.hoff, ourview.voff); (*dev->comout)(buf); @@ -153,17 +143,15 @@ char *s; if (buf[0] == CTRL('C')) return; if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2) change++; - else { - nv.hoff = ourview.hoff; nv.voff = ourview.voff; - } if (change) newview(&nv); } -void -lastview(s) /* return to a previous view */ -char *s; +extern void +lastview( /* return to a previous view */ + char *s +) { char buf[128]; char *fname; @@ -171,7 +159,7 @@ char *s; VIEW nv; if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ - copystruct(&nv, &stdview); + nv = stdview; if ((fname = getpath(buf, "", R_OK)) == NULL || (success = viewfile(fname, &nv, NULL)) == -1) { sprintf(errmsg, "cannot open \"%s\"", buf); @@ -188,16 +176,17 @@ char *s; error(COMMAND, "no previous view"); return; } - copystruct(&nv, &ourview); - copystruct(&ourview, &oldview); - copystruct(&oldview, &nv); + nv = ourview; + ourview = oldview; + oldview = nv; newimage(); } -void -saveview(s) /* save view to rad file */ -char *s; +extern void +saveview( /* save view to rad file */ + char *s +) { char view[64]; char *fname; @@ -232,9 +221,10 @@ char *s; } -void -loadview(s) /* load view from rad file */ -char *s; +extern void +loadview( /* load view from rad file */ + char *s +) { char buf[512]; char *fname; @@ -265,7 +255,7 @@ char *s; buf[0] = '\0'; fgets(buf, sizeof(buf), fp); pclose(fp); - copystruct(&nv, &stdview); + nv = stdview; if (!sscanview(&nv, buf)) { error(COMMAND, "rad error -- no such view?"); return; @@ -274,29 +264,25 @@ char *s; } -void -getaim(s) /* aim camera */ -char *s; +extern void +getaim( /* aim camera */ + char *s +) { + VIEW nv = ourview; double zfact; - VIEW nv; if (getinterest(s, 1, nv.vdir, &zfact) < 0) return; - nv.type = ourview.type; - VCOPY(nv.vp, ourview.vp); - VCOPY(nv.vup, ourview.vup); - nv.horiz = ourview.horiz; nv.vert = ourview.vert; - nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; - nv.hoff = ourview.hoff; nv.voff = ourview.voff; zoomview(&nv, zfact); newview(&nv); } -void -getmove(s) /* move camera */ -char *s; +extern void +getmove( /* move camera */ + char *s +) { FVECT vc; double mag; @@ -307,11 +293,12 @@ char *s; } -void -getrotate(s) /* rotate camera */ -char *s; +extern void +getrotate( /* rotate camera */ + char *s +) { - VIEW nv; + VIEW nv = ourview; FVECT v1; double angle, elev, zfact; @@ -320,26 +307,21 @@ 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; - nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; 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.)); } - nv.horiz = ourview.horiz; nv.vert = ourview.vert; zoomview(&nv, zfact); newview(&nv); } -void -getpivot(s) /* pivot viewpoint */ -register char *s; +extern void +getpivot( /* pivot viewpoint */ + register char *s +) { FVECT vc; double angle, elev, mag; @@ -355,9 +337,10 @@ register char *s; } -void -getexposure(s) /* get new exposure */ -char *s; +extern void +getexposure( /* get new exposure */ + char *s +) { char buf[128]; register char *cp; @@ -423,11 +406,13 @@ char *s; typedef union {int i; double d; COLOR C;} *MyUptr; -int -getparam(str, dsc, typ, p) /* get variable from user */ -char *str, *dsc; -int typ; -void *p; +extern int +getparam( /* get variable from user */ + char *str, + char *dsc, + int typ, + void *p +) { register MyUptr ptr = (MyUptr)p; int i0; @@ -464,10 +449,10 @@ void *p; (*dev->comout)(buf); (*dev->comin)(buf, NULL); if (buf[0] == '\0' || - index("yY+1tTnN-0fF", buf[0]) == NULL) + strchr("yY+1tTnN-0fF", buf[0]) == NULL) return(0); } - ptr->i = index("yY+1tT", buf[0]) != NULL; + ptr->i = strchr("yY+1tT", buf[0]) != NULL; return(1); case 'C': /* color */ if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { @@ -484,12 +469,14 @@ void *p; setcolor(ptr->C, d0, d1, d2); return(1); } + return 0; /* nothing matched */ } -void -setparam(s) /* get/set program parameter */ -register char *s; +extern void +setparam( /* get/set program parameter */ + register char *s +) { char buf[128]; @@ -661,7 +648,7 @@ badparam: } -void +extern void traceray(s) /* trace a single ray */ char *s; { @@ -730,7 +717,7 @@ char *s; } -void +extern void writepict(s) /* write the picture to a file */ char *s; { @@ -754,9 +741,7 @@ char *s; error(COMMAND, errmsg); return; } -#ifdef MSDOS - setmode(fileno(fp), O_BINARY); -#endif + SET_FILE_BINARY(fp); (*dev->comout)("writing \""); (*dev->comout)(fname); (*dev->comout)("\"...\n");