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.1 by greg, Thu Feb 2 10:41:37 1989 UTC vs.
Revision 1.12 by greg, Fri Oct 27 11:48:19 1989 UTC

# 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, ourview.hresolu, ourview.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);
62                          return;
63                  }
64 <                fputs(VIEWSTR, fp);
64 >                fputs(progname, fp);
65                  fprintview(&ourview, fp);
66                  fputs("\n", fp);
67                  fclose(fp);
# Line 94 | Line 71 | char  *s;
71          (*dev->comout)(buf);
72          (*dev->comin)(buf);
73          if (buf[0] == CTRL(C)) return;
74 <        if (buf[0])
74 >        if (buf[0] && buf[0] != ourview.type) {
75                  nv.type = buf[0];
76 <        else
76 >                change++;
77 >        } else
78                  nv.type = ourview.type;
79          sprintf(buf, "view point (%.6g %.6g %.6g): ",
80                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
81          (*dev->comout)(buf);
82          (*dev->comin)(buf);
83          if (buf[0] == CTRL(C)) return;
84 <        if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) != 3)
84 >        if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
85 >                change++;
86 >        else
87                  VCOPY(nv.vp, ourview.vp);
88          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
89                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
90          (*dev->comout)(buf);
91          (*dev->comin)(buf);
92          if (buf[0] == CTRL(C)) return;
93 <        if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) != 3)
93 >        if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
94 >                change++;
95 >        else
96                  VCOPY(nv.vdir, ourview.vdir);
97          sprintf(buf, "view up (%.6g %.6g %.6g): ",
98                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
99          (*dev->comout)(buf);
100          (*dev->comin)(buf);
101          if (buf[0] == CTRL(C)) return;
102 <        if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) != 3)
102 >        if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
103 >                change++;
104 >        else
105                  VCOPY(nv.vup, ourview.vup);
106          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
107                          ourview.horiz, ourview.vert);
108          (*dev->comout)(buf);
109          (*dev->comin)(buf);
110          if (buf[0] == CTRL(C)) return;
111 <        if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) != 2) {
111 >        if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
112 >                change++;
113 >        else {
114                  nv.horiz = ourview.horiz; nv.vert = ourview.vert;
115          }
116          sprintf(buf, "x and y resolution (%d %d): ",
# Line 132 | Line 118 | char  *s;
118          (*dev->comout)(buf);
119          (*dev->comin)(buf);
120          if (buf[0] == CTRL(C)) return;
121 <        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) != 2) {
121 >        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2)
122 >                change++;
123 >        else {
124                  nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
125          }
126 <        newview(&nv);
126 >        if (change)
127 >                newview(&nv);
128   }
129  
130  
# Line 143 | Line 132 | lastview(s)                            /* return to a previous view */
132   char  *s;
133   {
134          char  buf[128];
135 <        char  *fname, *getpath();
135 >        char  *fname;
136          int  success;
137          VIEW  nv;
138  
139          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
140                  bcopy(&stdview, &nv, sizeof(VIEW));
141 <                if ((fname = getpath(buf, NULL)) == NULL ||
141 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
142                                  (success = viewfile(fname, &nv)) == -1) {
143                          sprintf(errmsg, "cannot open \"%s\"", buf);
144                          error(COMMAND, errmsg);
# Line 172 | Line 161 | char  *s;
161   }
162  
163  
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
164   getaim(s)                               /* aim camera */
165   char  *s;
166   {
# Line 252 | Line 194 | char  *s;
194  
195          if (getinterest(s, 0, vc, &mag) < 0)
196                  return;
197 <        moveview(0.0, mag, vc);
197 >        moveview(0.0, 0.0, mag, vc);
198   }
199  
200  
201   getrotate(s)                            /* rotate camera */
202   char  *s;
203   {
204 <        extern double  normalize();
204 >        extern double  normalize(), tan(), atan();
205          VIEW  nv;
206          FVECT  v1;
207 <        double  angle, elev;
207 >        double  angle, elev, zfact;
208          
209 <        elev = 0.0;
210 <        if (sscanf(s, "%lf %lf", &angle, &elev) < 1) {
209 >        elev = 0.0; zfact = 1.0;
210 >        if (sscanf(s, "%lf %lf %lf", &angle, &elev, &zfact) < 1) {
211                  error(COMMAND, "missing angle");
212                  return;
213          }
272        nv.type = ourview.type;
214          VCOPY(nv.vp, ourview.vp);
215          VCOPY(nv.vup, ourview.vup);
275        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
216          nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
217          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
218          if (elev != 0.0) {
# Line 280 | Line 220 | char  *s;
220                  normalize(v1);
221                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
222          }
223 +        if ((nv.type = ourview.type) == VT_PAR) {
224 +                nv.horiz = ourview.horiz / zfact;
225 +                nv.vert = ourview.vert / zfact;
226 +        } else {
227 +                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
228 +                                (PI/180./2.);
229 +                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
230 +                                (PI/180./2.);
231 +        }
232          newview(&nv);
233   }
234  
# Line 288 | Line 237 | getpivot(s)                            /* pivot viewpoint */
237   register char  *s;
238   {
239          FVECT  vc;
240 <        double  angle, mag;
240 >        double  angle, elev, mag;
241  
242 <        if (sscanf(s, "%lf", &angle) != 1) {
242 >        elev = 0.0;
243 >        if (sscanf(s, "%lf %lf", &angle, &elev) < 1) {
244                  error(COMMAND, "missing angle");
245                  return;
246          }
247 <        if (getinterest(sskip(s), 0, vc, &mag) < 0)
247 >        if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0)
248                  return;
249 <        moveview(angle, mag, vc);
249 >        moveview(angle, elev, mag, vc);
250   }
251  
252  
# Line 348 | Line 298 | char  *s;
298                          e *= atof(cp);
299          }
300          if (p != NULL) {                /* relative setting */
301 <                if (intens(p->v) <= FTINY) {
301 >                if (bright(p->v) <= FTINY) {
302                          error(COMMAND, "cannot normalize to zero");
303                          return;
304                  }
305 <                e *= 0.5 / intens(p->v);
305 >                e *= 0.5 / bright(p->v);
306          }
307          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
308                  return;
# Line 370 | Line 320 | register char  *s;
320          extern double  minweight;
321          extern int  maxdepth;
322          extern double  dstrsrc;
323 +        extern double  shadthresh;
324 +        extern double  shadcert;
325          extern COLOR  ambval;
326          extern double  ambacc;
327          extern double  minarad;
# Line 382 | Line 334 | register char  *s;
334          char  buf[128];
335          
336          if (s[0] == '\0') {
337 <                (*dev->comout)("aa ab ad ar as av ds lr lw sd sp: ");
337 >                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
338                  (*dev->comin)(buf);
339                  s = buf;
340          }
# Line 415 | Line 367 | register char  *s;
367                          goto badparam;
368                  }
369                  break;
370 <        case 'd':                       /* distribute source */
371 <                if (s[1] != 's')
370 >        case 'd':                       /* direct */
371 >                switch (s[1]) {
372 >                case 'j':                       /* jitter */
373 >                        if (sscanf(s+2, "%lf", &d0) != 1) {
374 >                                sprintf(buf, "direct jitter (%.6g): ",
375 >                                                dstrsrc);
376 >                                (*dev->comout)(buf);
377 >                                (*dev->comin)(buf);
378 >                                if (sscanf(buf, "%lf", &d0) != 1)
379 >                                        break;
380 >                        }
381 >                        dstrsrc = d0;
382 >                        break;
383 >                case 'c':                       /* certainty */
384 >                        if (sscanf(s+2, "%lf", &d0) != 1) {
385 >                                sprintf(buf, "direct certainty (%.6g): ",
386 >                                                shadcert);
387 >                                (*dev->comout)(buf);
388 >                                (*dev->comin)(buf);
389 >                                if (sscanf(buf, "%lf", &d0) != 1)
390 >                                        break;
391 >                        }
392 >                        shadcert = d0;
393 >                        break;
394 >                case 't':                       /* threshold */
395 >                        if (sscanf(s+2, "%lf", &d0) != 1) {
396 >                                sprintf(buf, "direct threshold (%.6g): ",
397 >                                                shadthresh);
398 >                                (*dev->comout)(buf);
399 >                                (*dev->comin)(buf);
400 >                                if (sscanf(buf, "%lf", &d0) != 1)
401 >                                        break;
402 >                        }
403 >                        shadthresh = d0;
404 >                        break;
405 >                default:
406                          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;
407                  }
428                dstrsrc = d0;
408                  break;
409          case 'a':                       /* ambient */
410                  switch (s[1]) {
# Line 517 | Line 496 | register char  *s;
496                          psample = i0;
497                          pdepth = 0;
498                          break;
499 <                case 'd':                       /* difference */
499 >                case 't':                       /* threshold */
500                          if (sscanf(s+2, "%lf", &d0) != 1) {
501 <                                sprintf(buf, "sample difference (%.6g): ",
501 >                                sprintf(buf, "sample threshold (%.6g): ",
502                                                  maxdiff);
503                                  (*dev->comout)(buf);
504                                  (*dev->comin)(buf);
# Line 603 | Line 582 | writepict(s)                           /* write the picture to a file */
582   char  *s;
583   {
584          static char  buf[128];
585 <        char  *fname, *getpath();
585 >        char  *fname;
586          FILE  *fp;
587          COLR  *scanline;
588          int  y;
# Line 612 | Line 591 | char  *s;
591                  error(COMMAND, "no file");
592                  return;
593          }
594 <        if ((fname = getpath(buf, NULL)) == NULL ||
594 >        if ((fname = getpath(buf, NULL, 0)) == NULL ||
595                          (fp = fopen(fname, "w")) == NULL) {
596                  sprintf(errmsg, "cannot open \"%s\"", buf);
597                  error(COMMAND, errmsg);
# Line 624 | Line 603 | char  *s;
603                                                  /* write header */
604          fputs(progname, fp);
605          fprintview(&ourview, fp);
606 <        fputs("\n", fp);
606 >        putc('\n', fp);
607          if (exposure != 1.0)
608                  fprintf(fp, "EXPOSURE=%e\n", exposure);
609 <        fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
609 >        putc('\n', fp);
610 >        fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, fp);
611  
612          scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
613          if (scanline == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines