--- ray/src/rt/rv2.c 2005/01/21 00:52:59 2.45 +++ ray/src/rt/rv2.c 2008/09/05 19:45:41 2.58 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rv2.c,v 2.45 2005/01/21 00:52:59 greg Exp $"; +static const char RCSid[] = "$Id: rv2.c,v 2.58 2008/09/05 19:45:41 greg Exp $"; #endif /* * rv2.c - command routines used in tracing a view. @@ -14,6 +14,7 @@ static const char RCSid[] = "$Id: rv2.c,v 2.45 2005/01 #include "platform.h" #include "ray.h" +#include "source.h" #include "ambient.h" #include "otypes.h" #include "rpaint.h" @@ -35,7 +36,7 @@ extern char *progname; extern char *octname; -extern void +void getframe( /* get a new frame */ char *s ) @@ -46,7 +47,7 @@ getframe( /* get a new frame */ } -extern void +void getrepaint( /* get area and repaint */ char *s ) @@ -55,11 +56,11 @@ getrepaint( /* get area and repaint */ if (getrect(s, &box) < 0) return; - paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box); + paintrect(&ptrunk, &box); } -extern void +void getview( /* get/show view parameters */ char *s ) @@ -152,7 +153,7 @@ getview( /* get/show view parameters */ } -extern void +void lastview( /* return to a previous view */ char *s ) @@ -183,11 +184,11 @@ lastview( /* return to a previous view */ nv = ourview; ourview = oldview; oldview = nv; - newimage(); + newimage(NULL); } -extern void +void saveview( /* save view to rad file */ char *s ) @@ -225,7 +226,7 @@ saveview( /* save view to rad file */ } -extern void +void loadview( /* load view from rad file */ char *s ) @@ -268,7 +269,7 @@ loadview( /* load view from rad file */ } -extern void +void getaim( /* aim camera */ char *s ) @@ -283,12 +284,12 @@ getaim( /* aim camera */ } -extern void +void getfocus( /* set focus distance */ char *s ) { - FVECT vc; + char buf[64]; double dist; if (sscanf(s, "%lf", &dist) < 1) { @@ -304,7 +305,7 @@ getfocus( /* set focus distance */ error(COMMAND, "not on image"); return; } - rayorigin(&thisray, NULL, PRIMARY, 1.0); + rayorigin(&thisray, PRIMARY, NULL, NULL); if (!localhit(&thisray, &thescene)) { error(COMMAND, "not a local object"); return; @@ -315,10 +316,12 @@ getfocus( /* set focus distance */ return; } ourview.vdist = dist; + sprintf(buf, "Focus distance set to %f\n", dist); + (*dev->comout)(buf); } -extern void +void getmove( /* move camera */ char *s ) @@ -332,7 +335,7 @@ getmove( /* move camera */ } -extern void +void getrotate( /* rotate camera */ char *s ) @@ -357,9 +360,9 @@ getrotate( /* rotate camera */ } -extern void +void getpivot( /* pivot viewpoint */ - register char *s + char *s ) { FVECT vc; @@ -376,16 +379,15 @@ getpivot( /* pivot viewpoint */ } -extern void +void getexposure( /* get new exposure */ char *s ) { char buf[128]; - register char *cp; - RECT r; + char *cp; int x, y; - register PNODE *p = &ptrunk; + PNODE *p = &ptrunk; int adapt = 0; double e = 1.0; @@ -402,9 +404,7 @@ getexposure( /* get new exposure */ (*dev->comout)("Pick point for exposure\n"); if ((*dev->getcur)(&x, &y) == ABORT) return; - r.l = r.d = 0; - r.r = hresolu; r.u = vresolu; - p = findrect(x, y, &ptrunk, &r, -1); + p = findrect(x, y, &ptrunk, -1); } else { if (*cp == '=') { /* absolute setting */ p = NULL; @@ -427,6 +427,7 @@ getexposure( /* get new exposure */ e *= atof(cp); } if (p != NULL) { /* relative setting */ + compavg(p); if (bright(p->v) < 1e-15) { error(COMMAND, "cannot normalize to zero"); return; @@ -444,8 +445,9 @@ getexposure( /* get new exposure */ } typedef union {int i; double d; COLOR C;} *MyUptr; +#define FEQ(x,y) (fabs((x)-(y)) <= FTINY) -extern int +int getparam( /* get variable from user */ char *str, char *dsc, @@ -453,7 +455,7 @@ getparam( /* get variable from user */ void *p ) { - register MyUptr ptr = (MyUptr)p; + MyUptr ptr = (MyUptr)p; int i0; double d0, d1, d2; char buf[48]; @@ -468,8 +470,10 @@ getparam( /* get variable from user */ if (sscanf(buf, "%d", &i0) != 1) return(0); } + if (ptr->i == i0) + return(0); ptr->i = i0; - return(1); + break; case 'r': /* real */ if (sscanf(str, "%lf", &d0) != 1) { (*dev->comout)(dsc); @@ -479,20 +483,26 @@ getparam( /* get variable from user */ if (sscanf(buf, "%lf", &d0) != 1) return(0); } + if (FEQ(ptr->d, d0)) + return(0); ptr->d = d0; - return(1); + 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' || - strchr("yY+1tTnN-0fF", buf[0]) == NULL) + if (buf[0] == '\0') return(0); } - ptr->i = strchr("yY+1tT", buf[0]) != NULL; - return(1); + if (strchr("yY+1tTnN-0fF", buf[0]) == NULL) + return(0); + i0 = strchr("yY+1tT", buf[0]) != NULL; + if (ptr->i == i0) + return(0); + ptr->i = i0; + break; case 'C': /* color */ if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { (*dev->comout)(dsc); @@ -505,27 +515,38 @@ getparam( /* get variable from user */ if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) return(0); } + if (FEQ(colval(ptr->C,RED), d0) && + FEQ(colval(ptr->C,GRN), d1) && + FEQ(colval(ptr->C,BLU), d2)) + return(0); setcolor(ptr->C, d0, d1, d2); - return(1); + break; + default: + return(0); /* shouldn't happen */ } - return 0; /* nothing matched */ + newparam++; + return(1); } -extern void +void setparam( /* get/set program parameter */ - register char *s + char *s ) { char buf[128]; if (s[0] == '\0') { (*dev->comout)( - "aa ab ad ar as av aw b dc dv dj ds dt i lr lw me ma mg ms ps pt sj st bv: "); + "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: "); (*dev->comin)(buf, NULL); s = buf; } switch (s[0]) { + case 'u': /* uncorrelated sampling */ + getparam(s+1, "uncorrelated sampling", 'b', + (void *)&rand_samp); + break; case 'l': /* limit */ switch (s[1]) { case 'w': /* weight */ @@ -687,9 +708,10 @@ badparam: } -extern void -traceray(s) /* trace a single ray */ -char *s; +void +traceray( /* trace a single ray */ + char *s +) { char buf[128]; int x, y; @@ -718,17 +740,29 @@ char *s; return; } - rayorigin(&thisray, NULL, PRIMARY, 1.0); - - rayvalue(&thisray); + ray_trace(&thisray); if (thisray.ro == NULL) (*dev->comout)("ray hit nothing"); else { - sprintf(buf, "ray hit %s%s %s \"%s\"", - thisray.rod < 0.0 ? "back of " : "", - thisray.ro->omod == OVOID ? VOIDID : - objptr(thisray.ro->omod)->oname, + OBJREC *mat = NULL; + OBJREC *mod = NULL; + char matspec[256]; + matspec[0] = '\0'; + if (thisray.ro->omod != OVOID) { + mod = objptr(thisray.ro->omod); + mat = findmaterial(mod); + } + if (thisray.rod < 0.0) + strcpy(matspec, "back of "); + if (mod != NULL) { + strcat(matspec, mod->oname); + if (mat != mod && mat != NULL) + sprintf(matspec+strlen(matspec), + " (%s)", mat->oname); + } else + strcat(matspec, VOIDID); + sprintf(buf, "ray hit %s %s \"%s\"", matspec, ofun[thisray.ro->otype].funame, thisray.ro->oname); if ((ino = objptr(thisray.robj)) != thisray.ro) @@ -756,9 +790,10 @@ char *s; } -extern void -writepict(s) /* write the picture to a file */ -char *s; +void +writepict( /* write the picture to a file */ + char *s +) { static char buf[128]; char *fname;