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"; |
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] && buf[0] != ourview.type) { |
76 |
|
nv.type = buf[0]; |
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) |
86 |
|
change++; |
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) |
95 |
|
change++; |
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) |
104 |
|
change++; |
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) |
113 |
|
change++; |
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, "%lf %lf", &nv.hoff, &nv.voff) == 2) |
123 |
|
change++; |
151 |
|
newview(&nv); |
152 |
|
return; |
153 |
|
} |
154 |
< |
if (oldview.horiz == 0) { /* no old view! */ |
154 |
> |
if (oldview.type == 0) { /* no old view! */ |
155 |
|
error(COMMAND, "no previous view"); |
156 |
|
return; |
157 |
|
} |
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.hoff = ourview.hoff; nv.voff = ourview.voff; |
178 |
< |
if ((nv.type = ourview.type) == VT_PAR) { |
179 |
< |
nv.horiz = ourview.horiz / zfact; |
178 |
< |
nv.vert = ourview.vert / zfact; |
179 |
< |
} else { |
180 |
< |
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
181 |
< |
(PI/180./2.); |
182 |
< |
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
183 |
< |
(PI/180./2.); |
184 |
< |
} |
178 |
> |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
179 |
> |
zoomview(&nv, zfact); |
180 |
|
newview(&nv); |
181 |
|
} |
182 |
|
|
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.hoff = ourview.hoff; nv.voff = ourview.voff; |
216 |
|
normalize(v1); |
217 |
|
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
218 |
|
} |
219 |
< |
if ((nv.type = ourview.type) == VT_PAR) { |
220 |
< |
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 |
< |
} |
219 |
> |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
220 |
> |
zoomview(&nv, zfact); |
221 |
|
newview(&nv); |
222 |
|
} |
223 |
|
|
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') |
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 |
|
{ |
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 dc dj dt lr lw sp st: "); |
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) { |
346 |
< |
sprintf(buf, "limit weight (%.6g): ", |
347 |
< |
minweight); |
348 |
< |
(*dev->comout)(buf); |
349 |
< |
(*dev->comin)(buf); |
350 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
351 |
< |
break; |
352 |
< |
} |
353 |
< |
minweight = d0; |
398 |
> |
getparam(s+2, "limit weight", 'r', &minweight); |
399 |
|
break; |
400 |
|
case 'r': /* reflection */ |
401 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
357 |
< |
sprintf(buf, "limit reflection (%d): ", |
358 |
< |
maxdepth); |
359 |
< |
(*dev->comout)(buf); |
360 |
< |
(*dev->comin)(buf); |
361 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
362 |
< |
break; |
363 |
< |
} |
364 |
< |
maxdepth = i0; |
401 |
> |
getparam(s+2, "limit reflection", 'i', &maxdepth); |
402 |
|
break; |
403 |
|
default: |
404 |
|
goto badparam; |
407 |
|
case 'd': /* direct */ |
408 |
|
switch (s[1]) { |
409 |
|
case 'j': /* jitter */ |
410 |
< |
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; |
410 |
> |
getparam(s+2, "direct jitter", 'r', &dstrsrc); |
411 |
|
break; |
412 |
|
case 'c': /* certainty */ |
413 |
< |
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; |
413 |
> |
getparam(s+2, "direct certainty", 'r', &shadcert); |
414 |
|
break; |
415 |
|
case 't': /* threshold */ |
416 |
< |
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; |
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; |
424 |
|
} |
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) { |
413 |
< |
sprintf(buf, |
414 |
< |
"ambient value (%.6g %.6g %.6g): ", |
415 |
< |
colval(ambval,RED), |
416 |
< |
colval(ambval,GRN), |
417 |
< |
colval(ambval,BLU)); |
418 |
< |
(*dev->comout)(buf); |
419 |
< |
(*dev->comin)(buf); |
420 |
< |
if (sscanf(buf, "%lf %lf %lf", |
421 |
< |
&d0, &d1, &d2) != 3) |
422 |
< |
break; |
423 |
< |
} |
424 |
< |
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) { |
428 |
< |
sprintf(buf, "ambient accuracy (%.6g): ", |
429 |
< |
ambacc); |
430 |
< |
(*dev->comout)(buf); |
431 |
< |
(*dev->comin)(buf); |
432 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
433 |
< |
break; |
434 |
< |
} |
435 |
< |
ambacc = d0; |
438 |
> |
getparam(s+2, "ambient accuracy", 'r', &ambacc); |
439 |
|
break; |
440 |
|
case 'd': /* divisions */ |
441 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
439 |
< |
sprintf(buf, "ambient divisions (%d): ", |
440 |
< |
ambdiv); |
441 |
< |
(*dev->comout)(buf); |
442 |
< |
(*dev->comin)(buf); |
443 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
444 |
< |
break; |
445 |
< |
} |
446 |
< |
ambdiv = i0; |
441 |
> |
getparam(s+2, "ambient divisions", 'i', &ambdiv); |
442 |
|
break; |
443 |
|
case 's': /* samples */ |
444 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
450 |
< |
sprintf(buf, "ambient super-samples (%d): ", |
451 |
< |
ambssamp); |
452 |
< |
(*dev->comout)(buf); |
453 |
< |
(*dev->comin)(buf); |
454 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
455 |
< |
break; |
456 |
< |
} |
457 |
< |
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) { |
461 |
< |
sprintf(buf, "ambient bounces (%d): ", |
462 |
< |
ambounce); |
463 |
< |
(*dev->comout)(buf); |
464 |
< |
(*dev->comin)(buf); |
465 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
466 |
< |
break; |
467 |
< |
} |
468 |
< |
ambounce = i0; |
447 |
> |
getparam(s+2, "ambient bounces", 'i', &ambounce); |
448 |
|
break; |
449 |
|
case 'r': |
450 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
472 |
< |
sprintf(buf, "ambient resolution (%d): ", |
473 |
< |
ambres); |
474 |
< |
(*dev->comout)(buf); |
475 |
< |
(*dev->comin)(buf); |
476 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
477 |
< |
break; |
478 |
< |
} |
479 |
< |
ambres = i0; |
450 |
> |
getparam(s+2, "ambient resolution", 'i', &ambres); |
451 |
|
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
452 |
|
break; |
453 |
|
default: |
457 |
|
case 's': /* sample */ |
458 |
|
switch (s[1]) { |
459 |
|
case 'p': /* pixel */ |
460 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
490 |
< |
sprintf(buf, "sample pixel (%d): ", psample); |
491 |
< |
(*dev->comout)(buf); |
492 |
< |
(*dev->comin)(buf); |
493 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
494 |
< |
break; |
495 |
< |
} |
496 |
< |
psample = i0; |
460 |
> |
getparam(s+2, "sample pixel", 'i', &psample); |
461 |
|
pdepth = 0; |
462 |
|
break; |
463 |
|
case 't': /* threshold */ |
464 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
501 |
< |
sprintf(buf, "sample threshold (%.6g): ", |
502 |
< |
maxdiff); |
503 |
< |
(*dev->comout)(buf); |
504 |
< |
(*dev->comin)(buf); |
505 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
506 |
< |
break; |
507 |
< |
} |
508 |
< |
maxdiff = d0; |
464 |
> |
getparam(s+2, "sample threshold", 'r', &maxdiff); |
465 |
|
pdepth = 0; |
466 |
|
break; |
467 |
|
default: |
472 |
|
break; |
473 |
|
default:; |
474 |
|
badparam: |
475 |
+ |
*sskip(s) = '\0'; |
476 |
|
sprintf(errmsg, "%s: unknown variable", s); |
477 |
|
error(COMMAND, errmsg); |
478 |
|
break; |
497 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
498 |
|
return; |
499 |
|
|
500 |
< |
viewray(thisray.rorg, thisray.rdir, &ourview, |
501 |
< |
(x+.5)/hresolu, (y+.5)/vresolu); |
502 |
< |
|
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; |
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 { |
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 |
|
|
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 |
|
|