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 2.38 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.80 by greg, Sat Jun 7 05:09:46 2025 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *  External symbols declared in rpaint.h
8   */
9  
10 < /* ====================================================================
11 < * The Radiance Software License, Version 1.0
12 < *
13 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
14 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
15 < *
16 < * Redistribution and use in source and binary forms, with or without
17 < * modification, are permitted provided that the following conditions
18 < * are met:
19 < *
20 < * 1. Redistributions of source code must retain the above copyright
21 < *         notice, this list of conditions and the following disclaimer.
22 < *
23 < * 2. Redistributions in binary form must reproduce the above copyright
24 < *       notice, this list of conditions and the following disclaimer in
25 < *       the documentation and/or other materials provided with the
26 < *       distribution.
27 < *
28 < * 3. The end-user documentation included with the redistribution,
29 < *           if any, must include the following acknowledgment:
30 < *             "This product includes Radiance software
31 < *                 (http://radsite.lbl.gov/)
32 < *                 developed by the Lawrence Berkeley National Laboratory
33 < *               (http://www.lbl.gov/)."
34 < *       Alternately, this acknowledgment may appear in the software itself,
35 < *       if and wherever such third-party acknowledgments normally appear.
36 < *
37 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
38 < *       and "The Regents of the University of California" must
39 < *       not be used to endorse or promote products derived from this
40 < *       software without prior written permission. For written
41 < *       permission, please contact [email protected].
42 < *
43 < * 5. Products derived from this software may not be called "Radiance",
44 < *       nor may "Radiance" appear in their name, without prior written
45 < *       permission of Lawrence Berkeley National Laboratory.
46 < *
47 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
48 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
51 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
54 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 < * SUCH DAMAGE.
59 < * ====================================================================
60 < *
61 < * This software consists of voluntary contributions made by many
62 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
63 < * information on Lawrence Berkeley National Laboratory, please see
64 < * <http://www.lbl.gov/>.
65 < */
10 > #include "copyright.h"
11  
12 < #include  "ray.h"
12 > #include  <ctype.h>
13 > #include  <string.h>
14  
15 + #include  "platform.h"
16 + #include  "rtprocess.h" /* win_popen() */
17 + #include  "ray.h"
18 + #include  "ambient.h"
19   #include  "otypes.h"
20 <
20 > #include  "otspecial.h"
21   #include  "rpaint.h"
22  
73 #include  <ctype.h>
74
23   extern int  psample;                    /* pixel sample size */
24   extern double  maxdiff;                 /* max. sample difference */
25  
26   #define  CTRL(c)        ((c)-'@')
27  
28 < #ifdef  SMLFLT
81 < #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
82 < #else
83 < #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
84 < #endif
28 > #define  sscanvec(s,v)  (sscanf(s,FVFORMAT,v,v+1,v+2)==3)
29  
30   extern char  rifname[128];              /* rad input file name */
31  
# Line 90 | Line 34 | extern char  *octname;
34  
35  
36   void
37 < getframe(s)                             /* get a new frame */
38 < char  *s;
37 > getframe(                               /* get a new frame */
38 >        char  *s
39 > )
40   {
41          if (getrect(s, &pframe) < 0)
42                  return;
# Line 100 | Line 45 | char  *s;
45  
46  
47   void
48 < getrepaint(s)                           /* get area and repaint */
49 < char  *s;
48 > getrepaint(                             /* get area and repaint */
49 >        char  *s
50 > )
51   {
52          RECT  box;
53  
54          if (getrect(s, &box) < 0)
55                  return;
56 <        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box);
56 >        paintrect(&ptrunk, &box);
57   }
58  
59  
60   void
61 < getview(s)                              /* get/show view parameters */
62 < char  *s;
61 > getview(                                /* get/show/save view parameters */
62 >        char  *s
63 > )
64   {
65          FILE  *fp;
66          char  buf[128];
67          char  *fname;
68          int  change = 0;
69 <        VIEW  nv;
69 >        VIEW  nv = ourview;
70  
71          while (isspace(*s))
72                  s++;
73          if (*s == '-') {                        /* command line parameters */
127                copystruct(&nv, &ourview);
74                  if (sscanview(&nv, s))
75                          newview(&nv);
76                  else
77                          error(COMMAND, "bad view option(s)");
78                  return;
79          }
80 <        if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
80 >        if (nextword(buf, sizeof(buf), s) != NULL) {    /* write to a file */
81                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
82                                  (fp = fopen(fname, "a")) == NULL) {
83                          sprintf(errmsg, "cannot open \"%s\"", buf);
# Line 152 | Line 98 | char  *s;
98          if (buf[0] && buf[0] != ourview.type) {
99                  nv.type = buf[0];
100                  change++;
101 <        } else
156 <                nv.type = ourview.type;
101 >        }
102          sprintf(buf, "view point (%.6g %.6g %.6g): ",
103                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
104          (*dev->comout)(buf);
# Line 161 | Line 106 | char  *s;
106          if (buf[0] == CTRL('C')) return;
107          if (sscanvec(buf, nv.vp))
108                  change++;
164        else
165                VCOPY(nv.vp, ourview.vp);
109          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
110 <                        ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
110 >                        ourview.vdir[0]*ourview.vdist,
111 >                        ourview.vdir[1]*ourview.vdist,
112 >                        ourview.vdir[2]*ourview.vdist);
113          (*dev->comout)(buf);
114          (*dev->comin)(buf, NULL);
115          if (buf[0] == CTRL('C')) return;
116 <        if (sscanvec(buf, nv.vdir))
116 >        if (sscanvec(buf, nv.vdir)) {
117 >                nv.vdist = 1.;
118                  change++;
119 <        else
174 <                VCOPY(nv.vdir, ourview.vdir);
119 >        }
120          sprintf(buf, "view up (%.6g %.6g %.6g): ",
121                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
122          (*dev->comout)(buf);
# Line 179 | Line 124 | char  *s;
124          if (buf[0] == CTRL('C')) return;
125          if (sscanvec(buf, nv.vup))
126                  change++;
182        else
183                VCOPY(nv.vup, ourview.vup);
127          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
128                          ourview.horiz, ourview.vert);
129          (*dev->comout)(buf);
# Line 188 | Line 131 | char  *s;
131          if (buf[0] == CTRL('C')) return;
132          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
133                  change++;
191        else {
192                nv.horiz = ourview.horiz; nv.vert = ourview.vert;
193        }
134          sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ",
135                          ourview.vfore, ourview.vaft);
136          (*dev->comout)(buf);
# Line 198 | Line 138 | char  *s;
138          if (buf[0] == CTRL('C')) return;
139          if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2)
140                  change++;
201        else {
202                nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
203        }
141          sprintf(buf, "view shift and lift (%.6g %.6g): ",
142                          ourview.hoff, ourview.voff);
143          (*dev->comout)(buf);
# Line 208 | Line 145 | char  *s;
145          if (buf[0] == CTRL('C')) return;
146          if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
147                  change++;
211        else {
212                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
213        }
148          if (change)
149                  newview(&nv);
150   }
151  
152  
153   void
154 < lastview(s)                             /* return to a previous view */
155 < char  *s;
154 > lastview(                               /* return to a previous view */
155 >        char  *s
156 > )
157   {
158          char  buf[128];
159          char  *fname;
160          int  success;
161          VIEW  nv;
162 <
163 <        if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
164 <                copystruct(&nv, &stdview);
162 >                                        /* get parameters from a file */
163 >        if (nextword(buf, sizeof(buf), s) != NULL) {
164 >                nv = stdview;
165                  if ((fname = getpath(buf, "", R_OK)) == NULL ||
166                                  (success = viewfile(fname, &nv, NULL)) == -1) {
167                          sprintf(errmsg, "cannot open \"%s\"", buf);
# Line 243 | Line 178 | char  *s;
178                  error(COMMAND, "no previous view");
179                  return;
180          }
181 <        copystruct(&nv, &ourview);
182 <        copystruct(&ourview, &oldview);
183 <        copystruct(&oldview, &nv);
184 <        newimage();
181 >        nv = ourview;
182 >        ourview = oldview;
183 >        oldview = nv;
184 >        newimage(NULL);
185   }
186  
187  
188   void
189 < saveview(s)                             /* save view to rad file */
190 < char  *s;
189 > saveview(                               /* save view to rad file */
190 >        char  *s
191 > )
192   {
193          char  view[64];
194          char  *fname;
# Line 265 | Line 201 | char  *s;
201                  }
202                  s = sskip(s);
203          }
204 <        while (isspace(*s))
269 <                s++;
270 <        if (*s)
271 <                atos(rifname, sizeof(rifname), s);
272 <        else if (rifname[0] == '\0') {
204 >        if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) {
205                  error(COMMAND, "no previous rad file");
206                  return;
207          }
# Line 288 | Line 220 | char  *s;
220  
221  
222   void
223 < loadview(s)                             /* load view from rad file */
224 < char  *s;
223 > loadview(                               /* load view from rad file */
224 >        char  *s
225 > )
226   {
227          char  buf[512];
228          char  *fname;
# Line 301 | Line 234 | char  *s;
234                  s = sskip(s);
235          else
236                  strcat(buf, "1");
237 <        if (*s)
305 <                atos(rifname, sizeof(rifname), s);
306 <        else if (rifname[0] == '\0') {
237 >        if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) {
238                  error(COMMAND, "no previous rad file");
239                  return;
240          }
# Line 320 | Line 251 | char  *s;
251          buf[0] = '\0';
252          fgets(buf, sizeof(buf), fp);
253          pclose(fp);
254 <        copystruct(&nv, &stdview);
254 >        nv = stdview;
255          if (!sscanview(&nv, buf)) {
256                  error(COMMAND, "rad error -- no such view?");
257                  return;
# Line 330 | Line 261 | char  *s;
261  
262  
263   void
264 < getaim(s)                               /* aim camera */
265 < char  *s;
264 > getaim(                         /* aim camera */
265 >        char  *s
266 > )
267   {
268 +        VIEW  nv = ourview;
269          double  zfact;
337        VIEW  nv;
270  
271          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
272                  return;
341        nv.type = ourview.type;
342        VCOPY(nv.vp, ourview.vp);
343        VCOPY(nv.vup, ourview.vup);
344        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
345        nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
346        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
273          zoomview(&nv, zfact);
274          newview(&nv);
275   }
276  
277  
278   void
279 < getmove(s)                              /* move camera */
280 < char  *s;
279 > getfocus(                               /* set focus distance */
280 >        char *s
281 > )
282   {
283 +        char  buf[64];
284 +        double  dist;
285 +
286 +        if (sscanf(s, "%lf", &dist) < 1) {
287 +                int     x, y;
288 +                RAY     thisray;
289 +                if (dev->getcur == NULL)
290 +                        return;
291 +                (*dev->comout)("Pick focus point\n");
292 +                if ((*dev->getcur)(&x, &y) == ABORT)
293 +                        return;
294 +                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
295 +                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
296 +                        error(COMMAND, "not on image");
297 +                        return;
298 +                }
299 +                rayorigin(&thisray, PRIMARY, NULL, NULL);
300 +                if (!localhit(&thisray, &thescene)) {
301 +                        error(COMMAND, "not a local object");
302 +                        return;
303 +                }
304 +                dist = thisray.rot;
305 +        } else if (dist <= .0) {
306 +                error(COMMAND, "focus distance must be positive");
307 +                return;
308 +        }
309 +        ourview.vdist = dist;
310 +        sprintf(buf, "Focus distance set to %f\n", dist);
311 +        (*dev->comout)(buf);
312 + }
313 +
314 +
315 + void
316 + getmove(                                /* move camera */
317 +        char  *s
318 + )
319 + {
320          FVECT  vc;
321          double  mag;
322  
# Line 363 | Line 327 | char  *s;
327  
328  
329   void
330 < getrotate(s)                            /* rotate camera */
331 < char  *s;
330 > getrotate(                              /* rotate camera */
331 >        char  *s
332 > )
333   {
334 <        VIEW  nv;
370 <        FVECT  v1;
334 >        VIEW  nv = ourview;
335          double  angle, elev, zfact;
336          
337          elev = 0.0; zfact = 1.0;
# Line 375 | Line 339 | char  *s;
339                  error(COMMAND, "missing angle");
340                  return;
341          }
378        nv.type = ourview.type;
379        VCOPY(nv.vp, ourview.vp);
380        VCOPY(nv.vup, ourview.vup);
381        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
382        nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
342          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
343 <        if (elev != 0.0) {
344 <                fcross(v1, nv.vdir, ourview.vup);
345 <                normalize(v1);
387 <                spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
388 <        }
389 <        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
343 >        if (elev != 0.0)
344 >                geodesic(nv.vdir, nv.vdir, nv.vup, elev*(PI/180.), GEOD_RAD);
345 >        
346          zoomview(&nv, zfact);
347          newview(&nv);
348   }
349  
350  
351   void
352 < getpivot(s)                             /* pivot viewpoint */
353 < register char  *s;
352 > getpivot(                               /* pivot viewpoint */
353 >        char  *s
354 > )
355   {
356          FVECT  vc;
357          double  angle, elev, mag;
# Line 411 | Line 368 | register char  *s;
368  
369  
370   void
371 < getexposure(s)                          /* get new exposure */
372 < char  *s;
371 > getorigin(                              /* origin viewpoint */
372 >        char  *s
373 > )
374   {
375 +        VIEW    nv = ourview;
376 +        FVECT   voff;
377 +        int     i;
378 +        double  d;
379 +                                        /* check for view origin shift */
380 +        if (sscanf(s, "%lf", &d) == 1) {
381 +                double  d_fore=d, d_right=0, d_up=0;
382 +                sscanf(s, "%*f %lf %lf", &d_right, &d_up);
383 +                d_right /= sqrt(nv.hn2);
384 +                for (i = 3; i--; )
385 +                        nv.vp[i] += d_fore*nv.vdir[i] +
386 +                                        d_right*nv.hvec[i] +
387 +                                        d_up*nv.vup[i];
388 +        } else {                        /* else pick new origin */
389 +                int     x, y;
390 +                RAY     thisray;
391 +                if (dev->getcur == NULL)
392 +                        return;
393 +                (*dev->comout)("Pick point on surface for new origin\n");
394 +                if ((*dev->getcur)(&x, &y) == ABORT)
395 +                        return;
396 +                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
397 +                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
398 +                        error(COMMAND, "not on image");
399 +                        return;
400 +                }
401 +                rayorigin(&thisray, PRIMARY, NULL, NULL);
402 +                if (!localhit(&thisray, &thescene)) {
403 +                        error(COMMAND, "not a local object");
404 +                        return;
405 +                }
406 +                if (thisray.rod < 0.0)  /* don't look through other side */
407 +                        flipsurface(&thisray);
408 +                VSUM(nv.vp, thisray.rop, thisray.ron, 20.0*FTINY);
409 +                VCOPY(nv.vdir, thisray.ron);
410 +                d = DOT(nv.vdir, nv.vup);
411 +                if (d*d >= 1.-2.*FTINY) {
412 +                                        /* need different up vector */
413 +                        nv.vup[0] = nv.vup[1] = nv.vup[2] = 0.0;
414 +                        for (i = 3; i--; )
415 +                                if (nv.vdir[i]*nv.vdir[i] < 0.34)
416 +                                        break;
417 +                        nv.vup[i] = 1.;
418 +                }
419 +        }
420 +        newview(&nv);
421 + }
422 +
423 +
424 + void
425 + getexposure(                            /* get new exposure */
426 +        char  *s
427 + )
428 + {
429          char  buf[128];
430 <        register char  *cp;
419 <        RECT  r;
430 >        char  *cp;
431          int  x, y;
432 <        register PNODE  *p = &ptrunk;
432 >        PNODE  *p = &ptrunk;
433          int  adapt = 0;
434          double  e = 1.0;
435  
# Line 435 | Line 446 | char  *s;
446                  (*dev->comout)("Pick point for exposure\n");
447                  if ((*dev->getcur)(&x, &y) == ABORT)
448                          return;
449 <                r.l = r.d = 0;
439 <                r.r = hresolu; r.u = vresolu;
440 <                p = findrect(x, y, &ptrunk, &r, -1);
449 >                p = findrect(x, y, &ptrunk, -1);
450          } else {
451                  if (*cp == '=') {       /* absolute setting */
452                          p = NULL;
# Line 454 | Line 463 | char  *s;
463                                          return;
464                          }
465                  }
466 <                if (*cp == '+' || *cp == '-')   /* f-stops */
466 >                if ((*cp == '+') | (*cp == '-'))        /* f-stops */
467                          e *= pow(2.0, atof(cp));
468                  else                            /* multiplier */
469                          e *= atof(cp);
470          }
471          if (p != NULL) {                /* relative setting */
472 +                compavg(p);
473                  if (bright(p->v) < 1e-15) {
474                          error(COMMAND, "cannot normalize to zero");
475                          return;
# Line 479 | Line 489 | char  *s;
489   typedef union {int i; double d; COLOR C;}       *MyUptr;
490  
491   int
492 < getparam(str, dsc, typ, p)              /* get variable from user */
493 < char  *str, *dsc;
494 < int  typ;
495 < void  *p;
492 > getparam(               /* get variable from user */
493 >        char  *str,
494 >        char  *dsc,
495 >        int  typ,
496 >        void  *p
497 > )
498   {
499 <        register MyUptr  ptr = (MyUptr)p;
499 >        MyUptr  ptr = (MyUptr)p;
500          int  i0;
501          double  d0, d1, d2;
502          char  buf[48];
# Line 499 | Line 511 | void  *p;
511                          if (sscanf(buf, "%d", &i0) != 1)
512                                  return(0);
513                  }
514 +                if (ptr->i == i0)
515 +                        return(0);
516                  ptr->i = i0;
517 <                return(1);
517 >                break;
518          case 'r':                       /* real */
519                  if (sscanf(str, "%lf", &d0) != 1) {
520                          (*dev->comout)(dsc);
# Line 510 | Line 524 | void  *p;
524                          if (sscanf(buf, "%lf", &d0) != 1)
525                                  return(0);
526                  }
527 +                if (FRELEQ(ptr->d, d0))
528 +                        return(0);
529                  ptr->d = d0;
530 <                return(1);
530 >                break;
531          case 'b':                       /* boolean */
532                  if (sscanf(str, "%1s", buf) != 1) {
533                          (*dev->comout)(dsc);
534                          sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
535                          (*dev->comout)(buf);
536                          (*dev->comin)(buf, NULL);
537 <                        if (buf[0] == '\0' ||
522 <                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
537 >                        if (buf[0] == '\0')
538                                  return(0);
539                  }
540 <                ptr->i = index("yY+1tT", buf[0]) != NULL;
541 <                return(1);
540 >                if (strchr("yY+1tTnN-0fF", buf[0]) == NULL)
541 >                        return(0);
542 >                i0 = strchr("yY+1tT", buf[0]) != NULL;
543 >                if (ptr->i == i0)
544 >                        return(0);
545 >                ptr->i = i0;
546 >                break;
547          case 'C':                       /* color */
548                  if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
549                          (*dev->comout)(dsc);
# Line 536 | Line 556 | void  *p;
556                          if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
557                                  return(0);
558                  }
559 +                if (FRELEQ(colval(ptr->C,RED), d0) &&
560 +                                FRELEQ(colval(ptr->C,GRN), d1) &&
561 +                                FRELEQ(colval(ptr->C,BLU), d2))
562 +                        return(0);
563                  setcolor(ptr->C, d0, d1, d2);
564 <                return(1);
564 >                break;
565 >        default:
566 >                return(0);              /* shouldn't happen */
567          }
568 +        newparam++;
569 +        return(1);
570   }
571  
572  
573   void
574 < setparam(s)                             /* get/set program parameter */
575 < register char  *s;
574 > setparam(                               /* get/set program parameter */
575 >        char  *s
576 > )
577   {
578 +        int  prev_newp = newparam;
579          char  buf[128];
580          
581          if (s[0] == '\0') {
582                  (*dev->comout)(
583 <                "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: ");
583 >                "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: ");
584                  (*dev->comin)(buf, NULL);
585                  s = buf;
586          }
587          switch (s[0]) {
588 +        case 'u':                       /* uncorrelated sampling */
589 +                getparam(s+1, "uncorrelated sampling", 'b',
590 +                                (void *)&rand_samp);
591 +                break;
592          case 'l':                       /* limit */
593                  switch (s[1]) {
594                  case 'w':                       /* weight */
595 <                        getparam(s+2, "limit weight", 'r',
562 <                                        (void *)&minweight);
595 >                        getparam(s+2, "limit weight", 'r', &minweight);
596                          break;
597                  case 'r':                       /* reflection */
598 <                        getparam(s+2, "limit reflection", 'i',
566 <                                        (void *)&maxdepth);
598 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
599                          break;
600                  default:
601                          goto badparam;
# Line 572 | Line 604 | register char  *s;
604          case 'd':                       /* direct */
605                  switch (s[1]) {
606                  case 'j':                       /* jitter */
607 <                        getparam(s+2, "direct jitter", 'r',
576 <                                        (void *)&dstrsrc);
607 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
608                          break;
609                  case 'c':                       /* certainty */
610 <                        getparam(s+2, "direct certainty", 'r',
580 <                                        (void *)&shadcert);
610 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
611                          break;
612                  case 't':                       /* threshold */
613 <                        getparam(s+2, "direct threshold", 'r',
584 <                                        (void *)&shadthresh);
613 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
614                          break;
615                  case 'v':                       /* visibility */
616 <                        getparam(s+2, "direct visibility", 'b',
588 <                                        (void *)&directvis);
616 >                        getparam(s+2, "direct visibility", 'b', &directvis);
617                          break;
618                  case 's':                       /* sampling */
619 <                        getparam(s+2, "direct sampling", 'r',
592 <                                        (void *)&srcsizerat);
619 >                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
620                          break;
621                  default:
622                          goto badparam;
# Line 605 | Line 632 | register char  *s;
632                  case ' ':
633                  case 'y': case 'Y': case 't': case 'T': case '1': case '+':
634                  case 'n': case 'N': case 'f': case 'F': case '0': case '-':
635 <                        getparam(s+1, "black and white", 'b',
636 <                                        (void *)&greyscale);
635 >                        getparam(s+1, "black and white", 'b', &greyscale);
636 >                        newparam = prev_newp;
637                          break;
638                  default:
639                          goto badparam;
640                  }
641                  break;
642          case 'i':                       /* irradiance */
643 <                getparam(s+1, "irradiance", 'b',
617 <                                (void *)&do_irrad);
643 >                getparam(s+1, "irradiance", 'b', &do_irrad);
644                  break;
645          case 'a':                       /* ambient */
646                  switch (s[1]) {
647                  case 'v':                       /* value */
648 <                        getparam(s+2, "ambient value", 'C',
623 <                                        (void *)ambval);
648 >                        getparam(s+2, "ambient value", 'C', ambval);
649                          break;
650                  case 'w':                       /* weight */
651 <                        getparam(s+2, "ambient value weight", 'i',
627 <                                        (void *)&ambvwt);
651 >                        getparam(s+2, "ambient value weight", 'i', &ambvwt);
652                          break;
653                  case 'a':                       /* accuracy */
654 <                        if (getparam(s+2, "ambient accuracy", 'r',
631 <                                        (void *)&ambacc))
654 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
655                                  setambacc(ambacc);
656                          break;
657                  case 'd':                       /* divisions */
658 <                        getparam(s+2, "ambient divisions", 'i',
636 <                                        (void *)&ambdiv);
658 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
659                          break;
660                  case 's':                       /* samples */
661 <                        getparam(s+2, "ambient super-samples", 'i',
640 <                                        (void *)&ambssamp);
661 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
662                          break;
663                  case 'b':                       /* bounces */
664 <                        getparam(s+2, "ambient bounces", 'i',
644 <                                        (void *)&ambounce);
664 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
665                          break;
666                  case 'r':
667 <                        if (getparam(s+2, "ambient resolution", 'i',
648 <                                        (void *)&ambres))
667 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
668                                  setambres(ambres);
669                          break;
670                  default:
# Line 655 | Line 674 | register char  *s;
674          case 'm':                       /* medium */
675                  switch (s[1]) {
676                  case 'e':                       /* extinction coefficient */
677 <                        getparam(s+2, "extinction coefficient", 'C',
659 <                                        (void *)cextinction);
677 >                        getparam(s+2, "extinction coefficient", 'C', cextinction);
678                          break;
679                  case 'a':                       /* scattering albedo */
680 <                        getparam(s+2, "scattering albedo", 'C',
663 <                                        (void *)salbedo);
680 >                        getparam(s+2, "scattering albedo", 'C', salbedo);
681                          break;
682                  case 'g':                       /* scattering eccentricity */
683 <                        getparam(s+2, "scattering eccentricity", 'r',
667 <                                        (void *)&seccg);
683 >                        getparam(s+2, "scattering eccentricity", 'r', &seccg);
684                          break;
685                  case 's':                       /* sampling distance */
686 <                        getparam(s+2, "mist sampling distance", 'r',
671 <                                        (void *)&ssampdist);
686 >                        getparam(s+2, "mist sampling distance", 'r', &ssampdist);
687                          break;
688                  default:
689                          goto badparam;
# Line 677 | Line 692 | register char  *s;
692          case 'p':                       /* pixel */
693                  switch (s[1]) {
694                  case 's':                       /* sample */
695 <                        if (getparam(s+2, "pixel sample", 'i',
681 <                                        (void *)&psample))
695 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
696                                  pdepth = 0;
697                          break;
698                  case 't':                       /* threshold */
699 <                        if (getparam(s+2, "pixel threshold", 'r',
686 <                                        (void *)&maxdiff))
699 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
700                                  pdepth = 0;
701                          break;
702                  default:
703                          goto badparam;
704                  }
705 +                newparam = prev_newp;
706                  break;
707          case 's':                       /* specular */
708                  switch (s[1]) {
709 <                case 'j':                       /* jitter */
710 <                        getparam(s+2, "specular jitter", 'r',
697 <                                        (void *)&specjitter);
709 >                case 's':                       /* sampling */
710 >                        getparam(s+2, "specular sampling", 'r', &specjitter);
711                          break;
712                  case 't':                       /* threshold */
713 <                        getparam(s+2, "specular threshold", 'r',
701 <                                        (void *)&specthresh);
713 >                        getparam(s+2, "specular threshold", 'r', &specthresh);
714                          break;
715                  default:
716                          goto badparam;
# Line 717 | Line 729 | badparam:
729  
730  
731   void
732 < traceray(s)                             /* trace a single ray */
733 < char  *s;
732 > traceray(                               /* trace a single ray */
733 >        char  *s
734 > )
735   {
736 <        char  buf[128];
737 <        int  x, y;
738 <        OBJREC  *ino;
726 <        RAY  thisray;
736 >        RAY     thisray;
737 >        char    buf[512];
738 >        COLOR   col;
739  
740          thisray.rmax = 0.0;
741  
742          if (!sscanvec(s, thisray.rorg) ||
743                          !sscanvec(sskip2(s,3), thisray.rdir)) {
744 +                int  x, y;
745  
746                  if (dev->getcur == NULL)
747                          return;
# Line 747 | Line 760 | char  *s;
760                  return;
761          }
762  
763 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
751 <        
752 <        rayvalue(&thisray);
763 >        ray_trace(&thisray);
764  
765          if (thisray.ro == NULL)
766                  (*dev->comout)("ray hit nothing");
767          else {
768 <                sprintf(buf, "ray hit %s%s %s \"%s\"",
769 <                                thisray.rod < 0.0 ? "back of " : "",
770 <                                thisray.ro->omod == OVOID ? VOIDID :
771 <                                        objptr(thisray.ro->omod)->oname,
768 >                OBJREC  *mat = NULL;
769 >                OBJREC  *mod = NULL;
770 >                char    matspec[256];
771 >                OBJREC  *ino;
772 >
773 >                matspec[0] = '\0';
774 >                if (thisray.ro->omod != OVOID) {
775 >                        mod = objptr(thisray.ro->omod);
776 >                        mat = findmaterial(thisray.ro);
777 >                }
778 >                if (thisray.rod < 0.0)
779 >                        strcpy(matspec, "back of ");
780 >                if (mod != NULL) {
781 >                        strcat(matspec, mod->oname);
782 >                        if (mat != mod && mat != NULL)
783 >                                sprintf(matspec+strlen(matspec),
784 >                                        " (%s)", mat->oname);
785 >                } else
786 >                        strcat(matspec, VOIDID);
787 >                sprintf(buf, "ray hit %s %s \"%s\"", matspec,
788                                  ofun[thisray.ro->otype].funame,
789                                  thisray.ro->oname);
790                  if ((ino = objptr(thisray.robj)) != thisray.ro)
# Line 765 | Line 792 | char  *s;
792                                          ofun[ino->otype].funame, ino->oname);
793                  (*dev->comout)(buf);
794                  (*dev->comin)(buf, NULL);
795 <                if (thisray.rot >= FHUGE)
795 >                if (thisray.rot >= FHUGE*.99)
796                          (*dev->comout)("at infinity");
797                  else {
798 <                        sprintf(buf, "at (%.6g %.6g %.6g) (%.6g)",
798 >                        sprintf(buf, "at (%.3f %.3f %.3f) (%.6g)",
799                                          thisray.rop[0], thisray.rop[1],
800 <                                        thisray.rop[2], thisray.rt);
800 >                                        thisray.rop[2], raydistance(&thisray));
801                          (*dev->comout)(buf);
802                  }
803                  (*dev->comin)(buf, NULL);
804 <                sprintf(buf, "value (%.5g %.5g %.5g) (%.3gL)",
805 <                                colval(thisray.rcol,RED),
806 <                                colval(thisray.rcol,GRN),
807 <                                colval(thisray.rcol,BLU),
808 <                                luminance(thisray.rcol));
804 >                scolor_rgb(col, thisray.rcol);
805 >                sprintf(buf, "value (%.4g %.4g %.4g) (%.3gL)",
806 >                                colval(col,RED),
807 >                                colval(col,GRN),
808 >                                colval(col,BLU),
809 >                                luminance(col));
810                  (*dev->comout)(buf);
811          }
812          (*dev->comin)(buf, NULL);
# Line 786 | Line 814 | char  *s;
814  
815  
816   void
817 < writepict(s)                            /* write the picture to a file */
818 < char  *s;
817 > writepict(                              /* write the picture to a file */
818 >        char  *s
819 > )
820   {
821          static char  buf[128];
822          char  *fname;
823          FILE  *fp;
824          COLR  *scanline;
825          int  y;
826 <
827 <        while (isspace(*s))
799 <                s++;
800 <        if (*s)
801 <                atos(buf, sizeof(buf), s);
802 <        else if (buf[0] == '\0') {
826 >                                /* XXX relies on words.c 2.11 behavior */
827 >        if (nextword(buf, sizeof(buf), s) == NULL && !buf[0]) {
828                  error(COMMAND, "no file");
829                  return;
830          }
# Line 809 | Line 834 | char  *s;
834                  error(COMMAND, errmsg);
835                  return;
836          }
837 < #ifdef MSDOS
813 <        setmode(fileno(fp), O_BINARY);
814 < #endif
837 >        SET_FILE_BINARY(fp);
838          (*dev->comout)("writing \"");
839          (*dev->comout)(fname);
840          (*dev->comout)("\"...\n");
# Line 829 | Line 852 | char  *s;
852                  fputexpos(exposure, fp);
853          if (dev->pixaspect != 1.0)
854                  fputaspect(dev->pixaspect, fp);
855 +        fputprims(stdprims, fp);
856          fputformat(COLRFMT, fp);
857          putc('\n', fp);
858          fprtresolu(hresolu, vresolu, fp);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines