25 |
|
|
26 |
|
#include "platform.h" |
27 |
|
#include "ray.h" |
28 |
+ |
#include "ambient.h" |
29 |
+ |
#include "source.h" |
30 |
|
#include "otypes.h" |
31 |
|
#include "resolu.h" |
32 |
|
|
48 |
|
|
49 |
|
void (*trace)() = NULL; /* trace call */ |
50 |
|
|
49 |
– |
extern void ambnotify(), tranotify(); |
50 |
– |
void (*addobjnotify[])() = {ambnotify, tranotify, NULL}; |
51 |
|
char *tralist[128]; /* list of modifers to trace (or no) */ |
52 |
|
int traincl = -1; /* include == 1, exclude == 0 */ |
53 |
|
#define MAXTSET 511 /* maximum number in trace set */ |
80 |
|
char *ambfile = NULL; /* ambient file name */ |
81 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
82 |
|
int ambvwt = 0; /* initial weight for ambient value */ |
83 |
< |
double ambacc = 0.1; /* ambient accuracy */ |
83 |
> |
double ambacc = 0.15; /* ambient accuracy */ |
84 |
|
int ambres = 256; /* ambient resolution */ |
85 |
|
int ambdiv = 1024; /* ambient divisions */ |
86 |
|
int ambssamp = 512; /* ambient super-samples */ |
87 |
|
int ambounce = 0; /* ambient bounces */ |
88 |
< |
char *amblist[128]; /* ambient include/exclude list */ |
88 |
> |
char *amblist[AMBLLEN]; /* ambient include/exclude list */ |
89 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
90 |
|
|
91 |
+ |
static int castonly = 0; |
92 |
|
|
93 |
|
static RAY thisray; /* for our convenience */ |
94 |
|
|
95 |
< |
static void oputo(), oputd(), oputv(), oputl(), oputL(), oputc(), |
96 |
< |
oputp(), oputn(), oputN(), oputs(), oputw(), oputm(); |
95 |
> |
typedef void putf_t(double v); |
96 |
> |
static putf_t puta, putd, putf; |
97 |
|
|
98 |
< |
static void ourtrace(), tabin(); |
99 |
< |
static void (*ray_out[16])(), (*every_out[16])(); |
100 |
< |
static int castonly = 0; |
98 |
> |
typedef void oputf_t(RAY *r); |
99 |
> |
static oputf_t oputo, oputd, oputv, oputl, oputL, oputc, oputp, |
100 |
> |
oputn, oputN, oputs, oputw, oputW, oputm, oputM, oputtilde; |
101 |
|
|
102 |
< |
static void puta(), putf(), putd(); |
102 |
> |
static void setoutput(char *vs); |
103 |
> |
static void tranotify(OBJECT obj); |
104 |
> |
static void bogusray(void); |
105 |
> |
static void rad(FVECT org, FVECT dir, double dmax); |
106 |
> |
static void irrad(FVECT org, FVECT dir); |
107 |
> |
static void printvals(RAY *r); |
108 |
> |
static int getvec(FVECT vec, int fmt, FILE *fp); |
109 |
> |
static void tabin(RAY *r); |
110 |
> |
static void ourtrace(RAY *r); |
111 |
|
|
112 |
< |
static void (*putreal)(); |
112 |
> |
static oputf_t *ray_out[16], *every_out[16]; |
113 |
> |
static putf_t *putreal; |
114 |
|
|
115 |
< |
void bogusray(), rad(), irrad(), printvals(); |
115 |
> |
void (*addobjnotify[])() = {ambnotify, tranotify, NULL}; |
116 |
|
|
117 |
|
|
118 |
|
void |
119 |
< |
quit(code) /* quit program */ |
120 |
< |
int code; |
119 |
> |
quit( /* quit program */ |
120 |
> |
int code |
121 |
> |
) |
122 |
|
{ |
123 |
|
#ifndef NON_POSIX /* XXX we don't clean up elsewhere? */ |
124 |
|
headclean(); /* delete header file */ |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
< |
char * |
132 |
< |
formstr(f) /* return format identifier */ |
133 |
< |
int f; |
131 |
> |
extern char * |
132 |
> |
formstr( /* return format identifier */ |
133 |
> |
int f |
134 |
> |
) |
135 |
|
{ |
136 |
|
switch (f) { |
137 |
|
case 'a': return("ascii"); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
< |
void |
147 |
< |
rtrace(fname) /* trace rays from file */ |
148 |
< |
char *fname; |
146 |
> |
extern void |
147 |
> |
rtrace( /* trace rays from file */ |
148 |
> |
char *fname |
149 |
> |
) |
150 |
|
{ |
151 |
|
long vcount = hresolu>1 ? hresolu*vresolu : vresolu; |
152 |
|
long nextflush = hresolu; |
213 |
|
} |
214 |
|
fflush(stdout); |
215 |
|
if (vcount > 0) |
216 |
< |
error(USER, "read error"); |
216 |
> |
error(USER, "unexpected EOF on input"); |
217 |
|
if (fname != NULL) |
218 |
|
fclose(fp); |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
< |
setoutput(vs) /* set up output tables */ |
223 |
< |
register char *vs; |
222 |
> |
static void |
223 |
> |
trace_sources(void) /* trace rays to light sources, also */ |
224 |
|
{ |
225 |
< |
extern void (*trace)(); |
226 |
< |
register void (**table)() = ray_out; |
225 |
> |
int sn; |
226 |
> |
|
227 |
> |
for (sn = 0; sn < nsources; sn++) |
228 |
> |
source[sn].sflags |= SFOLLOW; |
229 |
> |
} |
230 |
|
|
231 |
+ |
|
232 |
+ |
static void |
233 |
+ |
setoutput( /* set up output tables */ |
234 |
+ |
register char *vs |
235 |
+ |
) |
236 |
+ |
{ |
237 |
+ |
register oputf_t **table = ray_out; |
238 |
+ |
|
239 |
|
castonly = 1; |
240 |
|
while (*vs) |
241 |
|
switch (*vs++) { |
242 |
+ |
case 'T': /* trace sources */ |
243 |
+ |
if (!*vs) break; |
244 |
+ |
trace_sources(); |
245 |
+ |
/* fall through */ |
246 |
|
case 't': /* trace */ |
247 |
+ |
if (!*vs) break; |
248 |
|
*table = NULL; |
249 |
|
table = every_out; |
250 |
|
trace = ourtrace; |
286 |
|
case 'w': /* weight */ |
287 |
|
*table++ = oputw; |
288 |
|
break; |
289 |
+ |
case 'W': /* coefficient */ |
290 |
+ |
*table++ = oputW; |
291 |
+ |
if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0)) |
292 |
+ |
error(WARNING, |
293 |
+ |
"-otW accuracy depends on -aa 0 -as 0"); |
294 |
+ |
break; |
295 |
|
case 'm': /* modifier */ |
296 |
|
*table++ = oputm; |
297 |
|
break; |
298 |
+ |
case 'M': /* material */ |
299 |
+ |
*table++ = oputM; |
300 |
+ |
break; |
301 |
+ |
case '~': /* tilde */ |
302 |
+ |
*table++ = oputtilde; |
303 |
+ |
break; |
304 |
|
} |
305 |
|
*table = NULL; |
306 |
|
} |
307 |
|
|
308 |
|
|
309 |
< |
void |
310 |
< |
bogusray() /* print out empty record */ |
309 |
> |
static void |
310 |
> |
bogusray(void) /* print out empty record */ |
311 |
|
{ |
312 |
|
thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] = |
313 |
|
thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0; |
314 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
314 |
> |
thisray.rmax = 0.0; |
315 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
316 |
|
printvals(&thisray); |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
< |
void |
321 |
< |
rad(org, dir, dmax) /* compute and print ray value(s) */ |
322 |
< |
FVECT org, dir; |
323 |
< |
double dmax; |
320 |
> |
static void |
321 |
> |
rad( /* compute and print ray value(s) */ |
322 |
> |
FVECT org, |
323 |
> |
FVECT dir, |
324 |
> |
double dmax |
325 |
> |
) |
326 |
|
{ |
327 |
|
VCOPY(thisray.rorg, org); |
328 |
|
VCOPY(thisray.rdir, dir); |
329 |
|
thisray.rmax = dmax; |
330 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
330 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
331 |
|
if (castonly) { |
332 |
|
if (!localhit(&thisray, &thescene)) { |
333 |
|
if (thisray.ro == &Aftplane) { /* clipped */ |
342 |
|
} |
343 |
|
|
344 |
|
|
345 |
< |
void |
346 |
< |
irrad(org, dir) /* compute immediate irradiance value */ |
347 |
< |
FVECT org, dir; |
345 |
> |
static void |
346 |
> |
irrad( /* compute immediate irradiance value */ |
347 |
> |
FVECT org, |
348 |
> |
FVECT dir |
349 |
> |
) |
350 |
|
{ |
351 |
|
register int i; |
352 |
|
|
354 |
|
thisray.rorg[i] = org[i] + dir[i]; |
355 |
|
thisray.rdir[i] = -dir[i]; |
356 |
|
} |
357 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
357 |
> |
thisray.rmax = 0.0; |
358 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
359 |
|
/* pretend we hit surface */ |
360 |
|
thisray.rot = 1.0-1e-4; |
361 |
|
thisray.rod = 1.0; |
368 |
|
} |
369 |
|
|
370 |
|
|
371 |
< |
void |
372 |
< |
printvals(r) /* print requested ray values */ |
373 |
< |
RAY *r; |
371 |
> |
static void |
372 |
> |
printvals( /* print requested ray values */ |
373 |
> |
RAY *r |
374 |
> |
) |
375 |
|
{ |
376 |
< |
register void (**tp)(); |
376 |
> |
register oputf_t **tp; |
377 |
|
|
378 |
|
if (ray_out[0] == NULL) |
379 |
|
return; |
384 |
|
} |
385 |
|
|
386 |
|
|
387 |
< |
int |
388 |
< |
getvec(vec, fmt, fp) /* get a vector from fp */ |
389 |
< |
register FVECT vec; |
390 |
< |
int fmt; |
391 |
< |
FILE *fp; |
387 |
> |
static int |
388 |
> |
getvec( /* get a vector from fp */ |
389 |
> |
register FVECT vec, |
390 |
> |
int fmt, |
391 |
> |
FILE *fp |
392 |
> |
) |
393 |
|
{ |
394 |
|
static float vf[3]; |
395 |
|
static double vd[3]; |
422 |
|
} |
423 |
|
|
424 |
|
|
425 |
< |
void |
426 |
< |
tranotify(obj) /* record new modifier */ |
427 |
< |
OBJECT obj; |
425 |
> |
static void |
426 |
> |
tranotify( /* record new modifier */ |
427 |
> |
OBJECT obj |
428 |
> |
) |
429 |
|
{ |
430 |
|
static int hitlimit = 0; |
431 |
|
register OBJREC *o = objptr(obj); |
452 |
|
|
453 |
|
|
454 |
|
static void |
455 |
< |
ourtrace(r) /* print ray values */ |
456 |
< |
RAY *r; |
455 |
> |
ourtrace( /* print ray values */ |
456 |
> |
RAY *r |
457 |
> |
) |
458 |
|
{ |
459 |
< |
register void (**tp)(); |
459 |
> |
register oputf_t **tp; |
460 |
|
|
461 |
|
if (every_out[0] == NULL) |
462 |
|
return; |
468 |
|
tabin(r); |
469 |
|
for (tp = every_out; *tp != NULL; tp++) |
470 |
|
(**tp)(r); |
471 |
< |
putchar('\n'); |
471 |
> |
if (outform == 'a') |
472 |
> |
putchar('\n'); |
473 |
|
} |
474 |
|
|
475 |
|
|
476 |
|
static void |
477 |
< |
tabin(r) /* tab in appropriate amount */ |
478 |
< |
RAY *r; |
477 |
> |
tabin( /* tab in appropriate amount */ |
478 |
> |
RAY *r |
479 |
> |
) |
480 |
|
{ |
481 |
< |
register RAY *rp; |
481 |
> |
const RAY *rp; |
482 |
|
|
483 |
|
for (rp = r->parent; rp != NULL; rp = rp->parent) |
484 |
|
putchar('\t'); |
486 |
|
|
487 |
|
|
488 |
|
static void |
489 |
< |
oputo(r) /* print origin */ |
490 |
< |
RAY *r; |
489 |
> |
oputo( /* print origin */ |
490 |
> |
RAY *r |
491 |
> |
) |
492 |
|
{ |
493 |
|
(*putreal)(r->rorg[0]); |
494 |
|
(*putreal)(r->rorg[1]); |
497 |
|
|
498 |
|
|
499 |
|
static void |
500 |
< |
oputd(r) /* print direction */ |
501 |
< |
RAY *r; |
500 |
> |
oputd( /* print direction */ |
501 |
> |
RAY *r |
502 |
> |
) |
503 |
|
{ |
504 |
|
(*putreal)(r->rdir[0]); |
505 |
|
(*putreal)(r->rdir[1]); |
508 |
|
|
509 |
|
|
510 |
|
static void |
511 |
< |
oputv(r) /* print value */ |
512 |
< |
RAY *r; |
511 |
> |
oputv( /* print value */ |
512 |
> |
RAY *r |
513 |
> |
) |
514 |
|
{ |
459 |
– |
COLR cout; |
460 |
– |
|
515 |
|
if (outform == 'c') { |
516 |
+ |
COLR cout; |
517 |
|
setcolr(cout, colval(r->rcol,RED), |
518 |
|
colval(r->rcol,GRN), |
519 |
|
colval(r->rcol,BLU)); |
527 |
|
|
528 |
|
|
529 |
|
static void |
530 |
< |
oputl(r) /* print effective distance */ |
531 |
< |
RAY *r; |
530 |
> |
oputl( /* print effective distance */ |
531 |
> |
RAY *r |
532 |
> |
) |
533 |
|
{ |
534 |
|
(*putreal)(r->rt); |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
|
static void |
539 |
< |
oputL(r) /* print single ray length */ |
540 |
< |
RAY *r; |
539 |
> |
oputL( /* print single ray length */ |
540 |
> |
RAY *r |
541 |
> |
) |
542 |
|
{ |
543 |
|
(*putreal)(r->rot); |
544 |
|
} |
545 |
|
|
546 |
|
|
547 |
|
static void |
548 |
< |
oputc(r) /* print local coordinates */ |
549 |
< |
RAY *r; |
548 |
> |
oputc( /* print local coordinates */ |
549 |
> |
RAY *r |
550 |
> |
) |
551 |
|
{ |
552 |
|
(*putreal)(r->uv[0]); |
553 |
|
(*putreal)(r->uv[1]); |
555 |
|
|
556 |
|
|
557 |
|
static void |
558 |
< |
oputp(r) /* print point */ |
559 |
< |
RAY *r; |
558 |
> |
oputp( /* print point */ |
559 |
> |
RAY *r |
560 |
> |
) |
561 |
|
{ |
562 |
|
if (r->rot < FHUGE) { |
563 |
|
(*putreal)(r->rop[0]); |
572 |
|
|
573 |
|
|
574 |
|
static void |
575 |
< |
oputN(r) /* print unperturbed normal */ |
576 |
< |
RAY *r; |
575 |
> |
oputN( /* print unperturbed normal */ |
576 |
> |
RAY *r |
577 |
> |
) |
578 |
|
{ |
579 |
|
if (r->rot < FHUGE) { |
580 |
|
(*putreal)(r->ron[0]); |
589 |
|
|
590 |
|
|
591 |
|
static void |
592 |
< |
oputn(r) /* print perturbed normal */ |
593 |
< |
RAY *r; |
592 |
> |
oputn( /* print perturbed normal */ |
593 |
> |
RAY *r |
594 |
> |
) |
595 |
|
{ |
596 |
|
FVECT pnorm; |
597 |
|
|
609 |
|
|
610 |
|
|
611 |
|
static void |
612 |
< |
oputs(r) /* print name */ |
613 |
< |
RAY *r; |
612 |
> |
oputs( /* print name */ |
613 |
> |
RAY *r |
614 |
> |
) |
615 |
|
{ |
616 |
|
if (r->ro != NULL) |
617 |
|
fputs(r->ro->oname, stdout); |
622 |
|
|
623 |
|
|
624 |
|
static void |
625 |
< |
oputw(r) /* print weight */ |
626 |
< |
RAY *r; |
625 |
> |
oputw( /* print weight */ |
626 |
> |
RAY *r |
627 |
> |
) |
628 |
|
{ |
629 |
|
(*putreal)(r->rweight); |
630 |
|
} |
631 |
|
|
632 |
|
|
633 |
|
static void |
634 |
< |
oputm(r) /* print modifier */ |
635 |
< |
RAY *r; |
634 |
> |
oputW( /* print contribution */ |
635 |
> |
RAY *r |
636 |
> |
) |
637 |
|
{ |
638 |
+ |
COLOR contr; |
639 |
+ |
|
640 |
+ |
raycontrib(contr, r, PRIMARY); |
641 |
+ |
(*putreal)(colval(contr,RED)); |
642 |
+ |
(*putreal)(colval(contr,GRN)); |
643 |
+ |
(*putreal)(colval(contr,BLU)); |
644 |
+ |
} |
645 |
+ |
|
646 |
+ |
|
647 |
+ |
static void |
648 |
+ |
oputm( /* print modifier */ |
649 |
+ |
RAY *r |
650 |
+ |
) |
651 |
+ |
{ |
652 |
|
if (r->ro != NULL) |
653 |
|
if (r->ro->omod != OVOID) |
654 |
|
fputs(objptr(r->ro->omod)->oname, stdout); |
661 |
|
|
662 |
|
|
663 |
|
static void |
664 |
< |
puta(v) /* print ascii value */ |
665 |
< |
double v; |
664 |
> |
oputM( /* print material */ |
665 |
> |
RAY *r |
666 |
> |
) |
667 |
> |
{ |
668 |
> |
OBJREC *mat; |
669 |
> |
|
670 |
> |
if (r->ro != NULL) { |
671 |
> |
if ((mat = findmaterial(r->ro)) != NULL) |
672 |
> |
fputs(mat->oname, stdout); |
673 |
> |
else |
674 |
> |
fputs(VOIDID, stdout); |
675 |
> |
} else |
676 |
> |
putchar('*'); |
677 |
> |
putchar('\t'); |
678 |
> |
} |
679 |
> |
|
680 |
> |
|
681 |
> |
static void |
682 |
> |
oputtilde( /* output tilde (spacer) */ |
683 |
> |
RAY *r |
684 |
> |
) |
685 |
> |
{ |
686 |
> |
fputs("~\t", stdout); |
687 |
> |
} |
688 |
> |
|
689 |
> |
|
690 |
> |
static void |
691 |
> |
puta( /* print ascii value */ |
692 |
> |
double v |
693 |
> |
) |
694 |
|
{ |
695 |
|
printf("%e\t", v); |
696 |
|
} |