13 |
|
#include <string.h> |
14 |
|
|
15 |
|
#include "platform.h" |
16 |
+ |
#include "rtprocess.h" /* win_popen() */ |
17 |
+ |
#include "paths.h" |
18 |
|
#include "ray.h" |
19 |
|
#include "source.h" |
20 |
|
#include "ambient.h" |
63 |
|
|
64 |
|
|
65 |
|
void |
66 |
< |
getview( /* get/show view parameters */ |
66 |
> |
getview( /* get/show/save view parameters */ |
67 |
|
char *s |
68 |
|
) |
69 |
|
{ |
82 |
|
error(COMMAND, "bad view option(s)"); |
83 |
|
return; |
84 |
|
} |
85 |
< |
if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ |
85 |
> |
if (nextword(buf, sizeof(buf), s) != NULL) { /* write to a file */ |
86 |
|
if ((fname = getpath(buf, NULL, 0)) == NULL || |
87 |
|
(fp = fopen(fname, "a")) == NULL) { |
88 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
164 |
|
char *fname; |
165 |
|
int success; |
166 |
|
VIEW nv; |
167 |
< |
|
168 |
< |
if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ |
167 |
> |
/* get parameters from a file */ |
168 |
> |
if (nextword(buf, sizeof(buf), s) != NULL) { |
169 |
|
nv = stdview; |
170 |
|
if ((fname = getpath(buf, "", R_OK)) == NULL || |
171 |
|
(success = viewfile(fname, &nv, NULL)) == -1) { |
206 |
|
} |
207 |
|
s = sskip(s); |
208 |
|
} |
209 |
< |
while (isspace(*s)) |
208 |
< |
s++; |
209 |
< |
if (*s) |
210 |
< |
atos(rifname, sizeof(rifname), s); |
211 |
< |
else if (rifname[0] == '\0') { |
209 |
> |
if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) { |
210 |
|
error(COMMAND, "no previous rad file"); |
211 |
|
return; |
212 |
|
} |
239 |
|
s = sskip(s); |
240 |
|
else |
241 |
|
strcat(buf, "1"); |
242 |
< |
if (*s) |
245 |
< |
atos(rifname, sizeof(rifname), s); |
246 |
< |
else if (rifname[0] == '\0') { |
242 |
> |
if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) { |
243 |
|
error(COMMAND, "no previous rad file"); |
244 |
|
return; |
245 |
|
} |
337 |
|
) |
338 |
|
{ |
339 |
|
VIEW nv = ourview; |
344 |
– |
FVECT v1; |
340 |
|
double angle, elev, zfact; |
341 |
|
|
342 |
|
elev = 0.0; zfact = 1.0; |
345 |
|
return; |
346 |
|
} |
347 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
348 |
< |
if (elev != 0.0) { |
349 |
< |
fcross(v1, nv.vdir, ourview.vup); |
350 |
< |
normalize(v1); |
356 |
< |
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
357 |
< |
} |
348 |
> |
if (elev != 0.0) |
349 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, elev*(PI/180.), GEOD_RAD); |
350 |
> |
|
351 |
|
zoomview(&nv, zfact); |
352 |
|
newview(&nv); |
353 |
|
} |
420 |
|
e *= atof(cp); |
421 |
|
} |
422 |
|
if (p != NULL) { /* relative setting */ |
423 |
+ |
compavg(p); |
424 |
|
if (bright(p->v) < 1e-15) { |
425 |
|
error(COMMAND, "cannot normalize to zero"); |
426 |
|
return; |
438 |
|
} |
439 |
|
|
440 |
|
typedef union {int i; double d; COLOR C;} *MyUptr; |
441 |
+ |
#define FEQ(x,y) (fabs((x)-(y)) <= FTINY) |
442 |
|
|
443 |
|
int |
444 |
|
getparam( /* get variable from user */ |
463 |
|
if (sscanf(buf, "%d", &i0) != 1) |
464 |
|
return(0); |
465 |
|
} |
466 |
+ |
if (ptr->i == i0) |
467 |
+ |
return(0); |
468 |
|
ptr->i = i0; |
469 |
|
break; |
470 |
|
case 'r': /* real */ |
476 |
|
if (sscanf(buf, "%lf", &d0) != 1) |
477 |
|
return(0); |
478 |
|
} |
479 |
+ |
if (FEQ(ptr->d, d0)) |
480 |
+ |
return(0); |
481 |
|
ptr->d = d0; |
482 |
|
break; |
483 |
|
case 'b': /* boolean */ |
486 |
|
sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n'); |
487 |
|
(*dev->comout)(buf); |
488 |
|
(*dev->comin)(buf, NULL); |
489 |
< |
if (buf[0] == '\0' || |
491 |
< |
strchr("yY+1tTnN-0fF", buf[0]) == NULL) |
489 |
> |
if (buf[0] == '\0') |
490 |
|
return(0); |
491 |
|
} |
492 |
< |
ptr->i = strchr("yY+1tT", buf[0]) != NULL; |
492 |
> |
if (strchr("yY+1tTnN-0fF", buf[0]) == NULL) |
493 |
> |
return(0); |
494 |
> |
i0 = strchr("yY+1tT", buf[0]) != NULL; |
495 |
> |
if (ptr->i == i0) |
496 |
> |
return(0); |
497 |
> |
ptr->i = i0; |
498 |
|
break; |
499 |
|
case 'C': /* color */ |
500 |
|
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
508 |
|
if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) |
509 |
|
return(0); |
510 |
|
} |
511 |
+ |
if (FEQ(colval(ptr->C,RED), d0) && |
512 |
+ |
FEQ(colval(ptr->C,GRN), d1) && |
513 |
+ |
FEQ(colval(ptr->C,BLU), d2)) |
514 |
+ |
return(0); |
515 |
|
setcolor(ptr->C, d0, d1, d2); |
516 |
|
break; |
517 |
|
default: |
527 |
|
char *s |
528 |
|
) |
529 |
|
{ |
530 |
+ |
int prev_newp = newparam; |
531 |
|
char buf[128]; |
532 |
|
|
533 |
|
if (s[0] == '\0') { |
534 |
|
(*dev->comout)( |
535 |
< |
"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: "); |
535 |
> |
"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: "); |
536 |
|
(*dev->comin)(buf, NULL); |
537 |
|
s = buf; |
538 |
|
} |
593 |
|
case 'n': case 'N': case 'f': case 'F': case '0': case '-': |
594 |
|
getparam(s+1, "black and white", 'b', |
595 |
|
(void *)&greyscale); |
596 |
+ |
newparam = prev_newp; |
597 |
|
break; |
598 |
|
default: |
599 |
|
goto badparam; |
676 |
|
default: |
677 |
|
goto badparam; |
678 |
|
} |
679 |
+ |
newparam = prev_newp; |
680 |
|
break; |
681 |
|
case 's': /* specular */ |
682 |
|
switch (s[1]) { |
683 |
< |
case 'j': /* jitter */ |
684 |
< |
getparam(s+2, "specular jitter", 'r', |
683 |
> |
case 's': /* sampling */ |
684 |
> |
getparam(s+2, "specular sampling", 'r', |
685 |
|
(void *)&specjitter); |
686 |
|
break; |
687 |
|
case 't': /* threshold */ |
709 |
|
char *s |
710 |
|
) |
711 |
|
{ |
712 |
< |
char buf[128]; |
713 |
< |
int x, y; |
704 |
< |
OBJREC *ino; |
705 |
< |
RAY thisray; |
712 |
> |
RAY thisray; |
713 |
> |
char buf[512]; |
714 |
|
|
715 |
|
thisray.rmax = 0.0; |
716 |
|
|
717 |
|
if (!sscanvec(s, thisray.rorg) || |
718 |
|
!sscanvec(sskip2(s,3), thisray.rdir)) { |
719 |
+ |
int x, y; |
720 |
|
|
721 |
|
if (dev->getcur == NULL) |
722 |
|
return; |
743 |
|
OBJREC *mat = NULL; |
744 |
|
OBJREC *mod = NULL; |
745 |
|
char matspec[256]; |
746 |
+ |
OBJREC *ino; |
747 |
+ |
|
748 |
|
matspec[0] = '\0'; |
749 |
|
if (thisray.ro->omod != OVOID) { |
750 |
|
mod = objptr(thisray.ro->omod); |
797 |
|
FILE *fp; |
798 |
|
COLR *scanline; |
799 |
|
int y; |
800 |
< |
|
801 |
< |
while (isspace(*s)) |
791 |
< |
s++; |
792 |
< |
if (*s) |
793 |
< |
atos(buf, sizeof(buf), s); |
794 |
< |
else if (buf[0] == '\0') { |
800 |
> |
/* XXX relies on words.c 2.11 behavior */ |
801 |
> |
if (nextword(buf, sizeof(buf), s) == NULL && !buf[0]) { |
802 |
|
error(COMMAND, "no file"); |
803 |
|
return; |
804 |
|
} |