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 |
+ |
int i0; |
310 |
+ |
double d0, d1, d2; |
311 |
+ |
char buf[48]; |
312 |
+ |
|
313 |
+ |
switch (typ) { |
314 |
+ |
case 'i': /* integer */ |
315 |
+ |
if (sscanf(str, "%d", &i0) != 1) { |
316 |
+ |
(*dev->comout)(dsc); |
317 |
+ |
sprintf(buf, " (%d): ", ptr->i); |
318 |
+ |
(*dev->comout)(buf); |
319 |
+ |
(*dev->comin)(buf, NULL); |
320 |
+ |
if (sscanf(buf, "%d", &i0) != 1) |
321 |
+ |
break; |
322 |
+ |
} |
323 |
+ |
ptr->i = i0; |
324 |
+ |
break; |
325 |
+ |
case 'r': /* real */ |
326 |
+ |
if (sscanf(str, "%lf", &d0) != 1) { |
327 |
+ |
(*dev->comout)(dsc); |
328 |
+ |
sprintf(buf, " (%.6g): ", ptr->d); |
329 |
+ |
(*dev->comout)(buf); |
330 |
+ |
(*dev->comin)(buf, NULL); |
331 |
+ |
if (sscanf(buf, "%lf", &d0) != 1) |
332 |
+ |
break; |
333 |
+ |
} |
334 |
+ |
ptr->d = d0; |
335 |
+ |
break; |
336 |
+ |
case 'b': /* boolean */ |
337 |
+ |
if (sscanf(str, "%1s", buf) != 1) { |
338 |
+ |
(*dev->comout)(dsc); |
339 |
+ |
sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n'); |
340 |
+ |
(*dev->comout)(buf); |
341 |
+ |
(*dev->comin)(buf, NULL); |
342 |
+ |
} |
343 |
+ |
ptr->i = tolower(buf[0]) == 'y'; |
344 |
+ |
break; |
345 |
+ |
case 'C': /* color */ |
346 |
+ |
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
347 |
+ |
(*dev->comout)(dsc); |
348 |
+ |
sprintf(buf, " (%.6g %.6g %.6g): ", |
349 |
+ |
colval(ptr->C,RED), |
350 |
+ |
colval(ptr->C,GRN), |
351 |
+ |
colval(ptr->C,BLU)); |
352 |
+ |
(*dev->comout)(buf); |
353 |
+ |
(*dev->comin)(buf, NULL); |
354 |
+ |
if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) |
355 |
+ |
break; |
356 |
+ |
} |
357 |
+ |
setcolor(ptr->C, d0, d1, d2); |
358 |
+ |
break; |
359 |
+ |
} |
360 |
+ |
} |
361 |
+ |
|
362 |
+ |
|
363 |
|
setparam(s) /* get/set program parameter */ |
364 |
|
register char *s; |
365 |
|
{ |
377 |
|
extern int ambdiv; |
378 |
|
extern int ambssamp; |
379 |
|
extern int ambounce; |
380 |
< |
int i0; |
381 |
< |
double d0, d1, d2; |
380 |
> |
extern int directinvis; |
381 |
> |
extern int do_irrad; |
382 |
|
char buf[128]; |
383 |
|
|
384 |
|
if (s[0] == '\0') { |
385 |
< |
(*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: "); |
385 |
> |
(*dev->comout)( |
386 |
> |
"aa ab ad ar as av b dc di dj dt i lr lw sp st: "); |
387 |
|
(*dev->comin)(buf, NULL); |
388 |
|
s = buf; |
389 |
|
} |
391 |
|
case 'l': /* limit */ |
392 |
|
switch (s[1]) { |
393 |
|
case 'w': /* weight */ |
394 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
335 |
< |
sprintf(buf, "limit weight (%.6g): ", |
336 |
< |
minweight); |
337 |
< |
(*dev->comout)(buf); |
338 |
< |
(*dev->comin)(buf, NULL); |
339 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
340 |
< |
break; |
341 |
< |
} |
342 |
< |
minweight = d0; |
394 |
> |
getparam(s+2, "limit weight", 'r', &minweight); |
395 |
|
break; |
396 |
|
case 'r': /* reflection */ |
397 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
346 |
< |
sprintf(buf, "limit reflection (%d): ", |
347 |
< |
maxdepth); |
348 |
< |
(*dev->comout)(buf); |
349 |
< |
(*dev->comin)(buf, NULL); |
350 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
351 |
< |
break; |
352 |
< |
} |
353 |
< |
maxdepth = i0; |
397 |
> |
getparam(s+2, "limit reflection", 'i', &maxdepth); |
398 |
|
break; |
399 |
|
default: |
400 |
|
goto badparam; |
403 |
|
case 'd': /* direct */ |
404 |
|
switch (s[1]) { |
405 |
|
case 'j': /* jitter */ |
406 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
363 |
< |
sprintf(buf, "direct jitter (%.6g): ", |
364 |
< |
dstrsrc); |
365 |
< |
(*dev->comout)(buf); |
366 |
< |
(*dev->comin)(buf, NULL); |
367 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
368 |
< |
break; |
369 |
< |
} |
370 |
< |
dstrsrc = d0; |
406 |
> |
getparam(s+2, "direct jitter", 'r', &dstrsrc); |
407 |
|
break; |
408 |
|
case 'c': /* certainty */ |
409 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
374 |
< |
sprintf(buf, "direct certainty (%.6g): ", |
375 |
< |
shadcert); |
376 |
< |
(*dev->comout)(buf); |
377 |
< |
(*dev->comin)(buf, NULL); |
378 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
379 |
< |
break; |
380 |
< |
} |
381 |
< |
shadcert = d0; |
409 |
> |
getparam(s+2, "direct certainty", 'r', &shadcert); |
410 |
|
break; |
411 |
|
case 't': /* threshold */ |
412 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
385 |
< |
sprintf(buf, "direct threshold (%.6g): ", |
386 |
< |
shadthresh); |
387 |
< |
(*dev->comout)(buf); |
388 |
< |
(*dev->comin)(buf, NULL); |
389 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
390 |
< |
break; |
391 |
< |
} |
392 |
< |
shadthresh = d0; |
412 |
> |
getparam(s+2, "direct threshold", 'r', &shadthresh); |
413 |
|
break; |
414 |
+ |
case 'i': /* invisibility */ |
415 |
+ |
getparam(s+2, "direct invisibility", |
416 |
+ |
'b', &directinvis); |
417 |
+ |
break; |
418 |
|
default: |
419 |
|
goto badparam; |
420 |
|
} |
421 |
|
break; |
422 |
+ |
case 'b': /* black and white */ |
423 |
+ |
getparam(s+1, "black and white", 'b', &greyscale); |
424 |
+ |
break; |
425 |
+ |
case 'i': /* irradiance */ |
426 |
+ |
getparam(s+1, "irradiance", 'b', &do_irrad); |
427 |
+ |
break; |
428 |
|
case 'a': /* ambient */ |
429 |
|
switch (s[1]) { |
430 |
|
case 'v': /* value */ |
431 |
< |
if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
402 |
< |
sprintf(buf, |
403 |
< |
"ambient value (%.6g %.6g %.6g): ", |
404 |
< |
colval(ambval,RED), |
405 |
< |
colval(ambval,GRN), |
406 |
< |
colval(ambval,BLU)); |
407 |
< |
(*dev->comout)(buf); |
408 |
< |
(*dev->comin)(buf, NULL); |
409 |
< |
if (sscanf(buf, "%lf %lf %lf", |
410 |
< |
&d0, &d1, &d2) != 3) |
411 |
< |
break; |
412 |
< |
} |
413 |
< |
setcolor(ambval, d0, d1, d2); |
431 |
> |
getparam(s+2, "ambient value", 'C', ambval); |
432 |
|
break; |
433 |
|
case 'a': /* accuracy */ |
434 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
417 |
< |
sprintf(buf, "ambient accuracy (%.6g): ", |
418 |
< |
ambacc); |
419 |
< |
(*dev->comout)(buf); |
420 |
< |
(*dev->comin)(buf, NULL); |
421 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
422 |
< |
break; |
423 |
< |
} |
424 |
< |
ambacc = d0; |
434 |
> |
getparam(s+2, "ambient accuracy", 'r', &ambacc); |
435 |
|
break; |
436 |
|
case 'd': /* divisions */ |
437 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
428 |
< |
sprintf(buf, "ambient divisions (%d): ", |
429 |
< |
ambdiv); |
430 |
< |
(*dev->comout)(buf); |
431 |
< |
(*dev->comin)(buf, NULL); |
432 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
433 |
< |
break; |
434 |
< |
} |
435 |
< |
ambdiv = i0; |
437 |
> |
getparam(s+2, "ambient divisions", 'i', &ambdiv); |
438 |
|
break; |
439 |
|
case 's': /* samples */ |
440 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
439 |
< |
sprintf(buf, "ambient super-samples (%d): ", |
440 |
< |
ambssamp); |
441 |
< |
(*dev->comout)(buf); |
442 |
< |
(*dev->comin)(buf, NULL); |
443 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
444 |
< |
break; |
445 |
< |
} |
446 |
< |
ambssamp = i0; |
440 |
> |
getparam(s+2, "ambient super-samples", 'i', &ambssamp); |
441 |
|
break; |
442 |
|
case 'b': /* bounces */ |
443 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
450 |
< |
sprintf(buf, "ambient bounces (%d): ", |
451 |
< |
ambounce); |
452 |
< |
(*dev->comout)(buf); |
453 |
< |
(*dev->comin)(buf, NULL); |
454 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
455 |
< |
break; |
456 |
< |
} |
457 |
< |
ambounce = i0; |
443 |
> |
getparam(s+2, "ambient bounces", 'i', &ambounce); |
444 |
|
break; |
445 |
|
case 'r': |
446 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
461 |
< |
sprintf(buf, "ambient resolution (%d): ", |
462 |
< |
ambres); |
463 |
< |
(*dev->comout)(buf); |
464 |
< |
(*dev->comin)(buf, NULL); |
465 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
466 |
< |
break; |
467 |
< |
} |
468 |
< |
ambres = i0; |
446 |
> |
getparam(s+2, "ambient resolution", 'i', &ambres); |
447 |
|
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
448 |
|
break; |
449 |
|
default: |
453 |
|
case 's': /* sample */ |
454 |
|
switch (s[1]) { |
455 |
|
case 'p': /* pixel */ |
456 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
479 |
< |
sprintf(buf, "sample pixel (%d): ", psample); |
480 |
< |
(*dev->comout)(buf); |
481 |
< |
(*dev->comin)(buf, NULL); |
482 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
483 |
< |
break; |
484 |
< |
} |
485 |
< |
psample = i0; |
456 |
> |
getparam(s+2, "sample pixel", 'i', &psample); |
457 |
|
pdepth = 0; |
458 |
|
break; |
459 |
|
case 't': /* threshold */ |
460 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
490 |
< |
sprintf(buf, "sample threshold (%.6g): ", |
491 |
< |
maxdiff); |
492 |
< |
(*dev->comout)(buf); |
493 |
< |
(*dev->comin)(buf, NULL); |
494 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
495 |
< |
break; |
496 |
< |
} |
497 |
< |
maxdiff = d0; |
460 |
> |
getparam(s+2, "sample threshold", 'r', &maxdiff); |
461 |
|
pdepth = 0; |
462 |
|
break; |
463 |
|
default: |