ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rv2.c
(Generate patch)

Comparing ray/src/rt/rv2.c (file contents):
Revision 1.2 by greg, Fri Feb 3 07:58:07 1989 UTC vs.
Revision 1.26 by greg, Mon Aug 26 10:12:02 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 28 | Line 28 | extern char  *progname;
28   getframe(s)                             /* get a new frame */
29   char  *s;
30   {
31 <        int  x0, y0, x1, y1;
32 <
33 <        if (!strcmp("all", s)) {
34 <                pframe.l = pframe.d = 0;
35 <                pframe.r = ourview.hresolu;
36 <                pframe.u = ourview.vresolu;
37 <                pdepth = 0;
31 >        if (getrect(s, &pframe) < 0)
32                  return;
39        }
40        if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) {
41                if (dev->getcur == NULL)
42                        return;
43                (*dev->comout)("Pick first corner\n");
44                if ((*dev->getcur)(&x0, &y0) == ABORT)
45                        return;
46                (*dev->comout)("Pick second corner\n");
47                if ((*dev->getcur)(&x1, &y1) == ABORT)
48                        return;
49        }
50        if (x0 < x1) {
51                pframe.l = x0;
52                pframe.r = x1;
53        } else {
54                pframe.l = x1;
55                pframe.r = x0;
56        }
57        if (y0 < y1) {
58                pframe.d = y0;
59                pframe.u = y1;
60        } else {
61                pframe.d = y1;
62                pframe.u = y0;
63        }
64        if (pframe.l < 0) pframe.l = 0;
65        if (pframe.d < 0) pframe.d = 0;
66        if (pframe.r > ourview.hresolu) pframe.r = ourview.hresolu;
67        if (pframe.u > ourview.vresolu) pframe.u = ourview.vresolu;
33          pdepth = 0;
34   }
35  
36  
37 + getrepaint(s)                           /* get area and repaint */
38 + char  *s;
39 + {
40 +        RECT  box;
41 +
42 +        if (getrect(s, &box) < 0)
43 +                return;
44 +        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box);
45 + }
46 +
47 +
48   getview(s)                              /* get/show view parameters */
49   char  *s;
50   {
51          FILE  *fp;
52          char  buf[128];
53 <        char  *fname, *getpath();
53 >        char  *fname;
54 >        int  change = 0;
55          VIEW  nv;
56  
57          if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
58 <                if ((fname = getpath(buf, NULL)) == NULL ||
58 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
59                                  (fp = fopen(fname, "a")) == NULL) {
60                          sprintf(errmsg, "cannot open \"%s\"", buf);
61                          error(COMMAND, errmsg);
# Line 86 | Line 63 | char  *s;
63                  }
64                  fputs(progname, fp);
65                  fprintview(&ourview, fp);
66 +                fputs(sskip(s), fp);
67                  fputs("\n", fp);
68                  fclose(fp);
69                  return;
70          }
71          sprintf(buf, "view type (%c): ", ourview.type);
72          (*dev->comout)(buf);
73 <        (*dev->comin)(buf);
73 >        (*dev->comin)(buf, NULL);
74          if (buf[0] == CTRL(C)) return;
75 <        if (buf[0])
75 >        if (buf[0] && buf[0] != ourview.type) {
76                  nv.type = buf[0];
77 <        else
77 >                change++;
78 >        } else
79                  nv.type = ourview.type;
80          sprintf(buf, "view point (%.6g %.6g %.6g): ",
81                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
82          (*dev->comout)(buf);
83 <        (*dev->comin)(buf);
83 >        (*dev->comin)(buf, NULL);
84          if (buf[0] == CTRL(C)) return;
85 <        if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) != 3)
85 >        if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
86 >                change++;
87 >        else
88                  VCOPY(nv.vp, ourview.vp);
89          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
90                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
91          (*dev->comout)(buf);
92 <        (*dev->comin)(buf);
92 >        (*dev->comin)(buf, NULL);
93          if (buf[0] == CTRL(C)) return;
94 <        if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) != 3)
94 >        if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
95 >                change++;
96 >        else
97                  VCOPY(nv.vdir, ourview.vdir);
98          sprintf(buf, "view up (%.6g %.6g %.6g): ",
99                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
100          (*dev->comout)(buf);
101 <        (*dev->comin)(buf);
101 >        (*dev->comin)(buf, NULL);
102          if (buf[0] == CTRL(C)) return;
103 <        if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) != 3)
103 >        if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
104 >                change++;
105 >        else
106                  VCOPY(nv.vup, ourview.vup);
107          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
108                          ourview.horiz, ourview.vert);
109          (*dev->comout)(buf);
110 <        (*dev->comin)(buf);
110 >        (*dev->comin)(buf, NULL);
111          if (buf[0] == CTRL(C)) return;
112 <        if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) != 2) {
112 >        if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
113 >                change++;
114 >        else {
115                  nv.horiz = ourview.horiz; nv.vert = ourview.vert;
116          }
117 <        sprintf(buf, "x and y resolution (%d %d): ",
118 <                        ourview.hresolu, ourview.vresolu);
117 >        sprintf(buf, "view shift and lift (%.6g %.6g): ",
118 >                        ourview.hoff, ourview.voff);
119          (*dev->comout)(buf);
120 <        (*dev->comin)(buf);
120 >        (*dev->comin)(buf, NULL);
121          if (buf[0] == CTRL(C)) return;
122 <        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) != 2) {
123 <                nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
122 >        if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
123 >                change++;
124 >        else {
125 >                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
126          }
127 <        newview(&nv);
127 >        if (change)
128 >                newview(&nv);
129   }
130  
131  
# Line 143 | Line 133 | lastview(s)                            /* return to a previous view */
133   char  *s;
134   {
135          char  buf[128];
136 <        char  *fname, *getpath();
136 >        char  *fname;
137          int  success;
138          VIEW  nv;
139  
140          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
141 <                bcopy(&stdview, &nv, sizeof(VIEW));
142 <                if ((fname = getpath(buf, NULL)) == NULL ||
143 <                                (success = viewfile(fname, &nv)) == -1) {
141 >                copystruct(&nv, &stdview);
142 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
143 >                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
144                          sprintf(errmsg, "cannot open \"%s\"", buf);
145                          error(COMMAND, errmsg);
146                          return;
# Line 161 | Line 151 | char  *s;
151                          newview(&nv);
152                  return;
153          }
154 <        if (oldview.hresolu == 0) {     /* no old view! */
154 >        if (oldview.type == 0) {        /* no old view! */
155                  error(COMMAND, "no previous view");
156                  return;
157          }
158 <        bcopy(&ourview, &nv, sizeof(VIEW));
159 <        bcopy(&oldview, &ourview, sizeof(VIEW));
160 <        bcopy(&nv, &oldview, sizeof(VIEW));
158 >        copystruct(&nv, &ourview);
159 >        copystruct(&ourview, &oldview);
160 >        copystruct(&oldview, &nv);
161          newimage();
162   }
163  
164  
175 getinterest(s, direc, vec, mp)          /* get area of interest */
176 char  *s;
177 int  direc;
178 FVECT  vec;
179 double  *mp;
180 {
181        int  x, y;
182        RAY  thisray;
183        register int  i;
184
185        if (sscanf(s, "%lf", mp) != 1)
186                *mp = 1.0;
187        else if (*mp < -FTINY)          /* negative zoom is reduction */
188                *mp = -1.0 / *mp;
189        else if (*mp <= FTINY) {        /* too small */
190                error(COMMAND, "illegal magnification");
191                return(-1);
192        }
193        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
194                if (dev->getcur == NULL)
195                        return(-1);
196                (*dev->comout)("Pick view center\n");
197                if ((*dev->getcur)(&x, &y) == ABORT)
198                        return(-1);
199                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
200                if (!direc || ourview.type == VT_PAR) {
201                        rayorigin(&thisray, NULL, PRIMARY, 1.0);
202                        if (!localhit(&thisray, &thescene)) {
203                                error(COMMAND, "not a local object");
204                                return(-1);
205                        }
206                }
207                if (direc)
208                        if (ourview.type == VT_PAR)
209                                for (i = 0; i < 3; i++)
210                                        vec[i] = thisray.rop[i] - ourview.vp[i];
211                        else
212                                VCOPY(vec, thisray.rdir);
213                else
214                        VCOPY(vec, thisray.rop);
215        } else if (direc)
216                        for (i = 0; i < 3; i++)
217                                vec[i] -= ourview.vp[i];
218        return(0);
219 }
220
221
165   getaim(s)                               /* aim camera */
166   char  *s;
167   {
# Line 228 | Line 171 | char  *s;
171  
172          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
173                  return;
174 +        nv.type = ourview.type;
175          VCOPY(nv.vp, ourview.vp);
176          VCOPY(nv.vup, ourview.vup);
177 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
178 <        if ((nv.type = ourview.type) == VT_PAR) {
179 <                nv.horiz = ourview.horiz / zfact;
236 <                nv.vert = ourview.vert / zfact;
237 <        } else {
238 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
239 <                                (PI/180./2.);
240 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
241 <                                (PI/180./2.);
242 <        }
177 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
178 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
179 >        zoomview(&nv, zfact);
180          newview(&nv);
181   }
182  
# Line 252 | Line 189 | char  *s;
189  
190          if (getinterest(s, 0, vc, &mag) < 0)
191                  return;
192 <        moveview(0.0, mag, vc);
192 >        moveview(0.0, 0.0, mag, vc);
193   }
194  
195  
196   getrotate(s)                            /* rotate camera */
197   char  *s;
198   {
199 <        extern double  normalize();
199 >        extern double  normalize(), tan(), atan();
200          VIEW  nv;
201          FVECT  v1;
202 <        double  angle, elev;
202 >        double  angle, elev, zfact;
203          
204 <        elev = 0.0;
205 <        if (sscanf(s, "%lf %lf", &angle, &elev) < 1) {
204 >        elev = 0.0; zfact = 1.0;
205 >        if (sscanf(s, "%lf %lf %lf", &angle, &elev, &zfact) < 1) {
206                  error(COMMAND, "missing angle");
207                  return;
208          }
209          nv.type = ourview.type;
210          VCOPY(nv.vp, ourview.vp);
211          VCOPY(nv.vup, ourview.vup);
212 <        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
276 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
212 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
213          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
214          if (elev != 0.0) {
215                  fcross(v1, nv.vdir, ourview.vup);
216                  normalize(v1);
217                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
218          }
219 +        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
220 +        zoomview(&nv, zfact);
221          newview(&nv);
222   }
223  
# Line 288 | Line 226 | getpivot(s)                            /* pivot viewpoint */
226   register char  *s;
227   {
228          FVECT  vc;
229 <        double  angle, mag;
229 >        double  angle, elev, mag;
230  
231 <        if (sscanf(s, "%lf", &angle) != 1) {
231 >        elev = 0.0;
232 >        if (sscanf(s, "%lf %lf", &angle, &elev) < 1) {
233                  error(COMMAND, "missing angle");
234                  return;
235          }
236 <        if (getinterest(sskip(s), 0, vc, &mag) < 0)
236 >        if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0)
237                  return;
238 <        moveview(angle, mag, vc);
238 >        moveview(angle, elev, mag, vc);
239   }
240  
241  
# Line 320 | Line 259 | char  *s;
259                  if ((*dev->getcur)(&x, &y) == ABORT)
260                          return;
261                  r.l = r.d = 0;
262 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
262 >                r.r = hresolu; r.u = vresolu;
263                  p = findrect(x, y, &ptrunk, &r, -1);
264                  e = 1.0;
265          } else {
# Line 332 | Line 271 | char  *s;
271                          if (*cp == '\0') {      /* interactive */
272                                  sprintf(buf, "exposure (%lf): ", exposure);
273                                  (*dev->comout)(buf);
274 <                                (*dev->comin)(buf);
274 >                                (*dev->comin)(buf, NULL);
275                                  for (cp = buf; isspace(*cp); cp++)
276                                          ;
277                                  if (*cp == '\0')
# Line 348 | Line 287 | char  *s;
287                          e *= atof(cp);
288          }
289          if (p != NULL) {                /* relative setting */
290 <                if (intens(p->v) <= FTINY) {
290 >                if (bright(p->v) <= FTINY) {
291                          error(COMMAND, "cannot normalize to zero");
292                          return;
293                  }
294 <                e *= 0.5 / intens(p->v);
294 >                e *= 0.5 / bright(p->v);
295          }
296          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
297                  return;
# Line 362 | Line 301 | char  *s;
301   }
302  
303  
304 + getparam(str, dsc, typ, ptr)            /* get variable from user */
305 + char  *str, *dsc;
306 + int  typ;
307 + register union {int i; double d; COLOR C;}  *ptr;
308 + {
309 +        extern char  *index();
310 +        int  i0;
311 +        double  d0, d1, d2;
312 +        char  buf[48];
313 +
314 +        switch (typ) {
315 +        case 'i':                       /* integer */
316 +                if (sscanf(str, "%d", &i0) != 1) {
317 +                        (*dev->comout)(dsc);
318 +                        sprintf(buf, " (%d): ", ptr->i);
319 +                        (*dev->comout)(buf);
320 +                        (*dev->comin)(buf, NULL);
321 +                        if (sscanf(buf, "%d", &i0) != 1)
322 +                                break;
323 +                }
324 +                ptr->i = i0;
325 +                break;
326 +        case 'r':                       /* real */
327 +                if (sscanf(str, "%lf", &d0) != 1) {
328 +                        (*dev->comout)(dsc);
329 +                        sprintf(buf, " (%.6g): ", ptr->d);
330 +                        (*dev->comout)(buf);
331 +                        (*dev->comin)(buf, NULL);
332 +                        if (sscanf(buf, "%lf", &d0) != 1)
333 +                                break;
334 +                }
335 +                ptr->d = d0;
336 +                break;
337 +        case 'b':                       /* boolean */
338 +                if (sscanf(str, "%1s", buf) != 1) {
339 +                        (*dev->comout)(dsc);
340 +                        sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n');
341 +                        (*dev->comout)(buf);
342 +                        (*dev->comin)(buf, NULL);
343 +                        if (buf[0] == '\0' ||
344 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
345 +                                break;
346 +                }
347 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
348 +                break;
349 +        case 'C':                       /* color */
350 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
351 +                        (*dev->comout)(dsc);
352 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
353 +                                        colval(ptr->C,RED),
354 +                                        colval(ptr->C,GRN),
355 +                                        colval(ptr->C,BLU));
356 +                        (*dev->comout)(buf);
357 +                        (*dev->comin)(buf, NULL);
358 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
359 +                                break;
360 +                }
361 +                setcolor(ptr->C, d0, d1, d2);
362 +                break;
363 +        }
364 + }
365 +
366 +
367   setparam(s)                             /* get/set program parameter */
368   register char  *s;
369   {
# Line 370 | Line 372 | register char  *s;
372          extern double  minweight;
373          extern int  maxdepth;
374          extern double  dstrsrc;
375 +        extern double  shadthresh;
376 +        extern double  shadcert;
377          extern COLOR  ambval;
378          extern double  ambacc;
379          extern double  minarad;
# Line 377 | Line 381 | register char  *s;
381          extern int  ambdiv;
382          extern int  ambssamp;
383          extern int  ambounce;
384 <        int  i0;
385 <        double  d0, d1, d2;
384 >        extern int  directinvis;
385 >        extern int  do_irrad;
386          char  buf[128];
387          
388          if (s[0] == '\0') {
389 <                (*dev->comout)("aa ab ad ar as av ds lr lw sd sp: ");
390 <                (*dev->comin)(buf);
389 >                (*dev->comout)(
390 >                        "aa ab ad ar as av b dc di dj dt i lr lw sp st: ");
391 >                (*dev->comin)(buf, NULL);
392                  s = buf;
393          }
394          switch (s[0]) {
395          case 'l':                       /* limit */
396                  switch (s[1]) {
397                  case 'w':                       /* weight */
398 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
394 <                                sprintf(buf, "limit weight (%.6g): ",
395 <                                                minweight);
396 <                                (*dev->comout)(buf);
397 <                                (*dev->comin)(buf);
398 <                                if (sscanf(buf, "%lf", &d0) != 1)
399 <                                        break;
400 <                        }
401 <                        minweight = d0;
398 >                        getparam(s+2, "limit weight", 'r', &minweight);
399                          break;
400                  case 'r':                       /* reflection */
401 <                        if (sscanf(s+2, "%d", &i0) != 1) {
405 <                                sprintf(buf, "limit reflection (%d): ",
406 <                                                maxdepth);
407 <                                (*dev->comout)(buf);
408 <                                (*dev->comin)(buf);
409 <                                if (sscanf(buf, "%d", &i0) != 1)
410 <                                        break;
411 <                        }
412 <                        maxdepth = i0;
401 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
402                          break;
403                  default:
404                          goto badparam;
405                  }
406                  break;
407 <        case 'd':                       /* distribute source */
408 <                if (s[1] != 's')
407 >        case 'd':                       /* direct */
408 >                switch (s[1]) {
409 >                case 'j':                       /* jitter */
410 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
411 >                        break;
412 >                case 'c':                       /* certainty */
413 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
414 >                        break;
415 >                case 't':                       /* threshold */
416 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
417 >                        break;
418 >                case 'i':                       /* invisibility */
419 >                        getparam(s+2, "direct invisibility",
420 >                                        'b', &directinvis);
421 >                        break;
422 >                default:
423                          goto badparam;
421                if (sscanf(s+2, "%lf", &d0) != 1) {
422                        sprintf(buf, "distribute source (%.6g): ", dstrsrc);
423                        (*dev->comout)(buf);
424                        (*dev->comin)(buf);
425                        if (sscanf(buf, "%lf", &d0) != 1)
426                                break;
424                  }
428                dstrsrc = d0;
425                  break;
426 +        case 'b':                       /* black and white */
427 +                getparam(s+1, "black and white", 'b', &greyscale);
428 +                break;
429 +        case 'i':                       /* irradiance */
430 +                getparam(s+1, "irradiance", 'b', &do_irrad);
431 +                break;
432          case 'a':                       /* ambient */
433                  switch (s[1]) {
434                  case 'v':                       /* value */
435 <                        if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
434 <                                sprintf(buf,
435 <                                        "ambient value (%.6g %.6g %.6g): ",
436 <                                                colval(ambval,RED),
437 <                                                colval(ambval,GRN),
438 <                                                colval(ambval,BLU));
439 <                                (*dev->comout)(buf);
440 <                                (*dev->comin)(buf);
441 <                                if (sscanf(buf, "%lf %lf %lf",
442 <                                                &d0, &d1, &d2) != 3)
443 <                                        break;
444 <                        }
445 <                        setcolor(ambval, d0, d1, d2);
435 >                        getparam(s+2, "ambient value", 'C', ambval);
436                          break;
437                  case 'a':                       /* accuracy */
438 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
449 <                                sprintf(buf, "ambient accuracy (%.6g): ",
450 <                                                ambacc);
451 <                                (*dev->comout)(buf);
452 <                                (*dev->comin)(buf);
453 <                                if (sscanf(buf, "%lf", &d0) != 1)
454 <                                        break;
455 <                        }
456 <                        ambacc = d0;
438 >                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
439                          break;
440                  case 'd':                       /* divisions */
441 <                        if (sscanf(s+2, "%d", &i0) != 1) {
460 <                                sprintf(buf, "ambient divisions (%d): ",
461 <                                                ambdiv);
462 <                                (*dev->comout)(buf);
463 <                                (*dev->comin)(buf);
464 <                                if (sscanf(buf, "%d", &i0) != 1)
465 <                                        break;
466 <                        }
467 <                        ambdiv = i0;
441 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
442                          break;
443                  case 's':                       /* samples */
444 <                        if (sscanf(s+2, "%d", &i0) != 1) {
471 <                                sprintf(buf, "ambient super-samples (%d): ",
472 <                                                ambssamp);
473 <                                (*dev->comout)(buf);
474 <                                (*dev->comin)(buf);
475 <                                if (sscanf(buf, "%d", &i0) != 1)
476 <                                        break;
477 <                        }
478 <                        ambssamp = i0;
444 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
445                          break;
446                  case 'b':                       /* bounces */
447 <                        if (sscanf(s+2, "%d", &i0) != 1) {
482 <                                sprintf(buf, "ambient bounces (%d): ",
483 <                                                ambounce);
484 <                                (*dev->comout)(buf);
485 <                                (*dev->comin)(buf);
486 <                                if (sscanf(buf, "%d", &i0) != 1)
487 <                                        break;
488 <                        }
489 <                        ambounce = i0;
447 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
448                          break;
449                  case 'r':
450 <                        if (sscanf(s+2, "%d", &i0) != 1) {
493 <                                sprintf(buf, "ambient resolution (%d): ",
494 <                                                ambres);
495 <                                (*dev->comout)(buf);
496 <                                (*dev->comin)(buf);
497 <                                if (sscanf(buf, "%d", &i0) != 1)
498 <                                        break;
499 <                        }
500 <                        ambres = i0;
450 >                        getparam(s+2, "ambient resolution", 'i', &ambres);
451                          minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
452                          break;
453                  default:
# Line 507 | Line 457 | register char  *s;
457          case 's':                       /* sample */
458                  switch (s[1]) {
459                  case 'p':                       /* pixel */
460 <                        if (sscanf(s+2, "%d", &i0) != 1) {
511 <                                sprintf(buf, "sample pixel (%d): ", psample);
512 <                                (*dev->comout)(buf);
513 <                                (*dev->comin)(buf);
514 <                                if (sscanf(buf, "%d", &i0) != 1)
515 <                                        break;
516 <                        }
517 <                        psample = i0;
460 >                        getparam(s+2, "sample pixel", 'i', &psample);
461                          pdepth = 0;
462                          break;
463 <                case 'd':                       /* difference */
464 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
522 <                                sprintf(buf, "sample difference (%.6g): ",
523 <                                                maxdiff);
524 <                                (*dev->comout)(buf);
525 <                                (*dev->comin)(buf);
526 <                                if (sscanf(buf, "%lf", &d0) != 1)
527 <                                        break;
528 <                        }
529 <                        maxdiff = d0;
463 >                case 't':                       /* threshold */
464 >                        getparam(s+2, "sample threshold", 'r', &maxdiff);
465                          pdepth = 0;
466                          break;
467                  default:
# Line 537 | Line 472 | register char  *s;
472                  break;
473          default:;
474   badparam:
475 +                *sskip(s) = '\0';
476                  sprintf(errmsg, "%s: unknown variable", s);
477                  error(COMMAND, errmsg);
478                  break;
# Line 561 | Line 497 | char  *s;
497                  if ((*dev->getcur)(&x, &y) == ABORT)
498                          return;
499  
500 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
501 <                
500 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
501 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
502 >                        error(COMMAND, "not on image");
503 >                        return;
504 >                }
505 >
506          } else if (normalize(thisray.rdir) == 0.0) {
507                  error(COMMAND, "zero ray direction");
508                  return;
# Line 580 | Line 520 | char  *s;
520                                  ofun[thisray.ro->otype].funame,
521                                  thisray.ro->oname);
522                  (*dev->comout)(buf);
523 <                (*dev->comin)(buf);
523 >                (*dev->comin)(buf, NULL);
524                  if (thisray.rot >= FHUGE)
525                          (*dev->comout)("at infinity");
526                  else {
# Line 588 | Line 528 | char  *s;
528                                          thisray.rop[1], thisray.rop[2]);
529                          (*dev->comout)(buf);
530                  }
531 <                (*dev->comin)(buf);
531 >                (*dev->comin)(buf, NULL);
532                  sprintf(buf, "with value (%.6g %.6g %.6g)",
533                                  colval(thisray.rcol,RED),
534                                  colval(thisray.rcol,GRN),
535                                  colval(thisray.rcol,BLU));
536                  (*dev->comout)(buf);
537          }
538 <        (*dev->comin)(buf);
538 >        (*dev->comin)(buf, NULL);
539   }
540  
541  
# Line 603 | Line 543 | writepict(s)                           /* write the picture to a file */
543   char  *s;
544   {
545          static char  buf[128];
546 <        char  *fname, *getpath();
546 >        char  *fname;
547          FILE  *fp;
548          COLR  *scanline;
549          int  y;
# Line 612 | Line 552 | char  *s;
552                  error(COMMAND, "no file");
553                  return;
554          }
555 <        if ((fname = getpath(buf, NULL)) == NULL ||
555 >        if ((fname = getpath(buf, NULL, 0)) == NULL ||
556                          (fp = fopen(fname, "w")) == NULL) {
557                  sprintf(errmsg, "cannot open \"%s\"", buf);
558                  error(COMMAND, errmsg);
# Line 624 | Line 564 | char  *s;
564                                                  /* write header */
565          fputs(progname, fp);
566          fprintview(&ourview, fp);
567 <        fputs("\n", fp);
567 >        putc('\n', fp);
568          if (exposure != 1.0)
569 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
570 <        fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
569 >                fputexpos(exposure, fp);
570 >        if (dev->pixaspect != 1.0)
571 >                fputaspect(dev->pixaspect, fp);
572 >        fputformat(COLRFMT, fp);
573 >        putc('\n', fp);
574 >        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
575  
576 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
576 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
577          if (scanline == NULL)
578                  error(SYSTEM, "out of memory in writepict");
579 <        for (y = ourview.vresolu-1; y >= 0; y--) {
580 <                getpictcolrs(y, scanline, &ptrunk,
581 <                                ourview.hresolu, ourview.vresolu);
638 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
579 >        for (y = vresolu-1; y >= 0; y--) {
580 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
581 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
582                          break;
583          }
584          if (fclose(fp) < 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines