21 |
|
* irradiance values are desired. |
22 |
|
*/ |
23 |
|
|
24 |
< |
#include "ray.h" |
24 |
> |
#include <time.h> |
25 |
|
|
26 |
+ |
#include "platform.h" |
27 |
+ |
#include "ray.h" |
28 |
+ |
#include "ambient.h" |
29 |
+ |
#include "source.h" |
30 |
|
#include "otypes.h" |
27 |
– |
|
31 |
|
#include "resolu.h" |
32 |
|
|
33 |
|
CUBE thescene; /* our scene */ |
48 |
|
|
49 |
|
void (*trace)() = NULL; /* trace call */ |
50 |
|
|
48 |
– |
extern void ambnotify(), tranotify(); |
49 |
– |
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 */ |
57 |
|
int vresolu = 0; /* vertical resolution */ |
58 |
|
|
59 |
|
double dstrsrc = 0.0; /* square source distribution */ |
60 |
< |
double shadthresh = .05; /* shadow threshold */ |
61 |
< |
double shadcert = .5; /* shadow certainty */ |
60 |
> |
double shadthresh = .03; /* shadow threshold */ |
61 |
> |
double shadcert = .75; /* shadow certainty */ |
62 |
|
int directrelay = 2; /* number of source relays */ |
63 |
|
int vspretest = 512; /* virtual source pretest density */ |
64 |
|
int directvis = 1; /* sources visible? */ |
74 |
|
|
75 |
|
int backvis = 1; /* back face visibility */ |
76 |
|
|
77 |
< |
int maxdepth = 6; /* maximum recursion depth */ |
78 |
< |
double minweight = 4e-3; /* minimum ray weight */ |
77 |
> |
int maxdepth = 8; /* maximum recursion depth */ |
78 |
> |
double minweight = 2e-3; /* minimum ray weight */ |
79 |
|
|
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.2; /* ambient accuracy */ |
84 |
< |
int ambres = 128; /* ambient resolution */ |
85 |
< |
int ambdiv = 512; /* ambient divisions */ |
86 |
< |
int ambssamp = 0; /* ambient super-samples */ |
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(), |
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, |
100 |
> |
oputp, oputn, oputN, oputs, oputw, oputm; |
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 NIX |
123 |
> |
#ifndef NON_POSIX /* XXX we don't clean up elsewhere? */ |
124 |
|
headclean(); /* delete header file */ |
125 |
|
pfclean(); /* clean up persist files */ |
126 |
|
#endif |
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; |
160 |
|
sprintf(errmsg, "cannot open input file \"%s\"", fname); |
161 |
|
error(SYSTEM, errmsg); |
162 |
|
} |
163 |
< |
#ifdef MSDOS |
163 |
> |
#ifdef _WIN32 |
164 |
|
if (inform != 'a') |
165 |
< |
setmode(fileno(fp), O_BINARY); |
165 |
> |
SET_FILE_BINARY(fp); |
166 |
|
#endif |
167 |
|
/* set up output */ |
168 |
|
setoutput(outvals); |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
< |
setoutput(vs) /* set up output tables */ |
223 |
< |
register char *vs; |
222 |
> |
static void |
223 |
> |
setoutput( /* set up output tables */ |
224 |
> |
register char *vs |
225 |
> |
) |
226 |
|
{ |
227 |
< |
extern void (*trace)(); |
212 |
< |
register void (**table)() = ray_out; |
227 |
> |
register oputf_t **table = ray_out; |
228 |
|
|
229 |
|
castonly = 1; |
230 |
|
while (*vs) |
249 |
|
*table++ = oputl; |
250 |
|
castonly = 0; |
251 |
|
break; |
252 |
+ |
case 'c': /* local coordinates */ |
253 |
+ |
*table++ = oputc; |
254 |
+ |
break; |
255 |
|
case 'L': /* single ray length */ |
256 |
|
*table++ = oputL; |
257 |
|
break; |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
< |
void |
283 |
< |
bogusray() /* print out empty record */ |
282 |
> |
static void |
283 |
> |
bogusray(void) /* print out empty record */ |
284 |
|
{ |
285 |
|
thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] = |
286 |
|
thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0; |
289 |
|
} |
290 |
|
|
291 |
|
|
292 |
< |
void |
293 |
< |
rad(org, dir, dmax) /* compute and print ray value(s) */ |
294 |
< |
FVECT org, dir; |
295 |
< |
double dmax; |
292 |
> |
static void |
293 |
> |
rad( /* compute and print ray value(s) */ |
294 |
> |
FVECT org, |
295 |
> |
FVECT dir, |
296 |
> |
double dmax |
297 |
> |
) |
298 |
|
{ |
299 |
|
VCOPY(thisray.rorg, org); |
300 |
|
VCOPY(thisray.rdir, dir); |
301 |
|
thisray.rmax = dmax; |
302 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
303 |
|
if (castonly) { |
304 |
< |
if (!localhit(&thisray, &thescene)) |
304 |
> |
if (!localhit(&thisray, &thescene)) { |
305 |
|
if (thisray.ro == &Aftplane) { /* clipped */ |
306 |
|
thisray.ro = NULL; |
307 |
|
thisray.rot = FHUGE; |
308 |
|
} else |
309 |
|
sourcehit(&thisray); |
310 |
+ |
} |
311 |
|
} else |
312 |
|
rayvalue(&thisray); |
313 |
|
printvals(&thisray); |
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
< |
void |
318 |
< |
irrad(org, dir) /* compute immediate irradiance value */ |
319 |
< |
FVECT org, dir; |
317 |
> |
static void |
318 |
> |
irrad( /* compute immediate irradiance value */ |
319 |
> |
FVECT org, |
320 |
> |
FVECT dir |
321 |
> |
) |
322 |
|
{ |
323 |
|
register int i; |
324 |
|
|
339 |
|
} |
340 |
|
|
341 |
|
|
342 |
< |
void |
343 |
< |
printvals(r) /* print requested ray values */ |
344 |
< |
RAY *r; |
342 |
> |
static void |
343 |
> |
printvals( /* print requested ray values */ |
344 |
> |
RAY *r |
345 |
> |
) |
346 |
|
{ |
347 |
< |
register void (**tp)(); |
347 |
> |
register oputf_t **tp; |
348 |
|
|
349 |
|
if (ray_out[0] == NULL) |
350 |
|
return; |
355 |
|
} |
356 |
|
|
357 |
|
|
358 |
< |
int |
359 |
< |
getvec(vec, fmt, fp) /* get a vector from fp */ |
360 |
< |
register FVECT vec; |
361 |
< |
int fmt; |
362 |
< |
FILE *fp; |
358 |
> |
static int |
359 |
> |
getvec( /* get a vector from fp */ |
360 |
> |
register FVECT vec, |
361 |
> |
int fmt, |
362 |
> |
FILE *fp |
363 |
> |
) |
364 |
|
{ |
365 |
|
static float vf[3]; |
366 |
|
static double vd[3]; |
393 |
|
} |
394 |
|
|
395 |
|
|
396 |
< |
void |
397 |
< |
tranotify(obj) /* record new modifier */ |
398 |
< |
OBJECT obj; |
396 |
> |
static void |
397 |
> |
tranotify( /* record new modifier */ |
398 |
> |
OBJECT obj |
399 |
> |
) |
400 |
|
{ |
401 |
|
static int hitlimit = 0; |
402 |
|
register OBJREC *o = objptr(obj); |
423 |
|
|
424 |
|
|
425 |
|
static void |
426 |
< |
ourtrace(r) /* print ray values */ |
427 |
< |
RAY *r; |
426 |
> |
ourtrace( /* print ray values */ |
427 |
> |
RAY *r |
428 |
> |
) |
429 |
|
{ |
430 |
< |
register void (**tp)(); |
430 |
> |
register oputf_t **tp; |
431 |
|
|
432 |
|
if (every_out[0] == NULL) |
433 |
|
return; |
444 |
|
|
445 |
|
|
446 |
|
static void |
447 |
< |
tabin(r) /* tab in appropriate amount */ |
448 |
< |
RAY *r; |
447 |
> |
tabin( /* tab in appropriate amount */ |
448 |
> |
RAY *r |
449 |
> |
) |
450 |
|
{ |
451 |
|
register RAY *rp; |
452 |
|
|
456 |
|
|
457 |
|
|
458 |
|
static void |
459 |
< |
oputo(r) /* print origin */ |
460 |
< |
register RAY *r; |
459 |
> |
oputo( /* print origin */ |
460 |
> |
RAY *r |
461 |
> |
) |
462 |
|
{ |
463 |
|
(*putreal)(r->rorg[0]); |
464 |
|
(*putreal)(r->rorg[1]); |
467 |
|
|
468 |
|
|
469 |
|
static void |
470 |
< |
oputd(r) /* print direction */ |
471 |
< |
register RAY *r; |
470 |
> |
oputd( /* print direction */ |
471 |
> |
RAY *r |
472 |
> |
) |
473 |
|
{ |
474 |
|
(*putreal)(r->rdir[0]); |
475 |
|
(*putreal)(r->rdir[1]); |
478 |
|
|
479 |
|
|
480 |
|
static void |
481 |
< |
oputv(r) /* print value */ |
482 |
< |
register RAY *r; |
481 |
> |
oputv( /* print value */ |
482 |
> |
RAY *r |
483 |
> |
) |
484 |
|
{ |
485 |
|
COLR cout; |
486 |
|
|
498 |
|
|
499 |
|
|
500 |
|
static void |
501 |
< |
oputl(r) /* print effective distance */ |
502 |
< |
register RAY *r; |
501 |
> |
oputl( /* print effective distance */ |
502 |
> |
RAY *r |
503 |
> |
) |
504 |
|
{ |
505 |
|
(*putreal)(r->rt); |
506 |
|
} |
507 |
|
|
508 |
|
|
509 |
|
static void |
510 |
< |
oputL(r) /* print single ray length */ |
511 |
< |
register RAY *r; |
510 |
> |
oputL( /* print single ray length */ |
511 |
> |
RAY *r |
512 |
> |
) |
513 |
|
{ |
514 |
|
(*putreal)(r->rot); |
515 |
|
} |
516 |
|
|
517 |
|
|
518 |
|
static void |
519 |
< |
oputp(r) /* print point */ |
520 |
< |
register RAY *r; |
519 |
> |
oputc( /* print local coordinates */ |
520 |
> |
RAY *r |
521 |
> |
) |
522 |
|
{ |
523 |
+ |
(*putreal)(r->uv[0]); |
524 |
+ |
(*putreal)(r->uv[1]); |
525 |
+ |
} |
526 |
+ |
|
527 |
+ |
|
528 |
+ |
static void |
529 |
+ |
oputp( /* print point */ |
530 |
+ |
RAY *r |
531 |
+ |
) |
532 |
+ |
{ |
533 |
|
if (r->rot < FHUGE) { |
534 |
|
(*putreal)(r->rop[0]); |
535 |
|
(*putreal)(r->rop[1]); |
543 |
|
|
544 |
|
|
545 |
|
static void |
546 |
< |
oputN(r) /* print unperturbed normal */ |
547 |
< |
register RAY *r; |
546 |
> |
oputN( /* print unperturbed normal */ |
547 |
> |
RAY *r |
548 |
> |
) |
549 |
|
{ |
550 |
|
if (r->rot < FHUGE) { |
551 |
|
(*putreal)(r->ron[0]); |
560 |
|
|
561 |
|
|
562 |
|
static void |
563 |
< |
oputn(r) /* print perturbed normal */ |
564 |
< |
RAY *r; |
563 |
> |
oputn( /* print perturbed normal */ |
564 |
> |
RAY *r |
565 |
> |
) |
566 |
|
{ |
567 |
|
FVECT pnorm; |
568 |
|
|
580 |
|
|
581 |
|
|
582 |
|
static void |
583 |
< |
oputs(r) /* print name */ |
584 |
< |
register RAY *r; |
583 |
> |
oputs( /* print name */ |
584 |
> |
RAY *r |
585 |
> |
) |
586 |
|
{ |
587 |
|
if (r->ro != NULL) |
588 |
|
fputs(r->ro->oname, stdout); |
593 |
|
|
594 |
|
|
595 |
|
static void |
596 |
< |
oputw(r) /* print weight */ |
597 |
< |
register RAY *r; |
596 |
> |
oputw( /* print weight */ |
597 |
> |
RAY *r |
598 |
> |
) |
599 |
|
{ |
600 |
|
(*putreal)(r->rweight); |
601 |
|
} |
602 |
|
|
603 |
|
|
604 |
|
static void |
605 |
< |
oputm(r) /* print modifier */ |
606 |
< |
register RAY *r; |
605 |
> |
oputm( /* print modifier */ |
606 |
> |
RAY *r |
607 |
> |
) |
608 |
|
{ |
609 |
|
if (r->ro != NULL) |
610 |
|
if (r->ro->omod != OVOID) |
618 |
|
|
619 |
|
|
620 |
|
static void |
621 |
< |
puta(v) /* print ascii value */ |
622 |
< |
double v; |
621 |
> |
puta( /* print ascii value */ |
622 |
> |
double v |
623 |
> |
) |
624 |
|
{ |
625 |
|
printf("%e\t", v); |
626 |
|
} |