52 |
|
#endif |
53 |
|
OBJECT traset[MAXTSET+1]={0}; /* trace include/exclude set */ |
54 |
|
|
55 |
+ |
static int Tflag = 0; /* source tracing enabled? */ |
56 |
+ |
|
57 |
|
static RAY thisray; /* for our convenience */ |
58 |
|
|
59 |
|
static FILE *inpfp = NULL; /* input stream pointer */ |
94 |
|
{ |
95 |
|
if (ray_pnprocs > 0) /* close children if any */ |
96 |
|
ray_pclose(0); |
97 |
+ |
else if (ray_pnprocs < 0) |
98 |
+ |
_exit(code); /* avoid flush() in child */ |
99 |
|
#ifndef NON_POSIX |
100 |
< |
else if (!ray_pnprocs) { |
100 |
> |
else { |
101 |
|
headclean(); /* delete header file */ |
102 |
|
pfclean(); /* clean up persist files */ |
103 |
|
} |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
+ |
static void |
125 |
+ |
trace_sources(void) /* trace rays to light sources, also */ |
126 |
+ |
{ |
127 |
+ |
int sn; |
128 |
+ |
|
129 |
+ |
for (sn = 0; sn < nsources; sn++) |
130 |
+ |
source[sn].sflags |= SFOLLOW; |
131 |
+ |
} |
132 |
+ |
|
133 |
+ |
|
134 |
|
void |
135 |
|
rtrace( /* trace rays from file */ |
136 |
|
char *fname, |
160 |
|
/* set up output */ |
161 |
|
if (castonly || every_out[0] != NULL) |
162 |
|
nproc = 1; /* don't bother multiprocessing */ |
163 |
+ |
if (every_out[0] != NULL) { |
164 |
+ |
trace = ourtrace; /* enable full tree tracing */ |
165 |
+ |
if (Tflag) /* light sources, too? */ |
166 |
+ |
trace_sources(); |
167 |
+ |
} |
168 |
|
if ((nextflush > 0) & (nproc > nextflush)) { |
169 |
|
error(WARNING, "reducing number of processes to match flush interval"); |
170 |
|
nproc = nextflush; |
171 |
|
} |
153 |
– |
switch (outform) { |
154 |
– |
case 'a': putreal = puta; break; |
155 |
– |
case 'f': putreal = putf; break; |
156 |
– |
case 'd': putreal = putd; break; |
157 |
– |
case 'c': |
158 |
– |
if (outvals[1] || !strchr("vrx", outvals[0])) |
159 |
– |
error(USER, "color format only with -ov, -or, -ox"); |
160 |
– |
putreal = putrgbe; break; |
161 |
– |
default: |
162 |
– |
error(CONSISTENCY, "botched output format"); |
163 |
– |
} |
172 |
|
if (nproc > 1) { /* start multiprocessing */ |
173 |
|
ray_popen(nproc); |
174 |
|
ray_fifo_out = printvals; |
167 |
– |
ray_pnbatch = !nextflush; |
175 |
|
} |
176 |
|
if (hresolu > 0) { |
177 |
|
if (vresolu > 0) |
223 |
|
} |
224 |
|
|
225 |
|
|
219 |
– |
static void |
220 |
– |
trace_sources(void) /* trace rays to light sources, also */ |
221 |
– |
{ |
222 |
– |
int sn; |
223 |
– |
|
224 |
– |
for (sn = 0; sn < nsources; sn++) |
225 |
– |
source[sn].sflags |= SFOLLOW; |
226 |
– |
} |
227 |
– |
|
228 |
– |
|
226 |
|
int |
227 |
|
setrtoutput(void) /* set up output tables, return #comp */ |
228 |
|
{ |
233 |
|
if (!*vs) |
234 |
|
error(USER, "empty output specification"); |
235 |
|
|
236 |
+ |
switch (outform) { /* make sure (*putreal)() calls someone! */ |
237 |
+ |
case 'a': putreal = puta; break; |
238 |
+ |
case 'f': putreal = putf; break; |
239 |
+ |
case 'd': putreal = putd; break; |
240 |
+ |
case 'c': |
241 |
+ |
if (outvals[1] || !strchr("vrx", outvals[0])) |
242 |
+ |
error(USER, "color format only with -ov, -or, -ox"); |
243 |
+ |
putreal = putrgbe; break; |
244 |
+ |
default: |
245 |
+ |
error(CONSISTENCY, "botched output format"); |
246 |
+ |
} |
247 |
|
castonly = 1; /* sets castonly as side-effect */ |
248 |
|
do |
249 |
|
switch (*vs) { |
250 |
|
case 'T': /* trace sources */ |
251 |
< |
if (!vs[1]) break; |
244 |
< |
trace_sources(); |
251 |
> |
Tflag++; |
252 |
|
/* fall through */ |
253 |
|
case 't': /* trace */ |
254 |
|
if (!vs[1]) break; |
255 |
|
*table = NULL; |
256 |
|
table = every_out; |
250 |
– |
trace = ourtrace; |
257 |
|
castonly = 0; |
258 |
|
break; |
259 |
|
case 'o': /* origin */ |
425 |
|
) |
426 |
|
{ |
427 |
|
/* set up ray */ |
422 |
– |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
428 |
|
if (imm_irrad) { |
429 |
|
VSUM(thisray.rorg, org, dir, 1.1e-4); |
430 |
|
thisray.rdir[0] = -dir[0]; |
431 |
|
thisray.rdir[1] = -dir[1]; |
432 |
|
thisray.rdir[2] = -dir[2]; |
433 |
|
thisray.rmax = 0.0; |
429 |
– |
thisray.revf = rayirrad; |
434 |
|
} else { |
435 |
|
VCOPY(thisray.rorg, org); |
436 |
|
VCOPY(thisray.rdir, dir); |
437 |
|
thisray.rmax = dmax; |
434 |
– |
if (castonly) |
435 |
– |
thisray.revf = raycast; |
438 |
|
} |
439 |
+ |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
440 |
+ |
if (imm_irrad) |
441 |
+ |
thisray.revf = rayirrad; |
442 |
+ |
else if (castonly) |
443 |
+ |
thisray.revf = raycast; |
444 |
|
if (ray_pnprocs > 1) { /* multiprocessing FIFO? */ |
445 |
|
if (ray_fifo_in(&thisray) < 0) |
446 |
|
error(USER, "lost children"); |
771 |
|
|
772 |
|
|
773 |
|
static void |
774 |
< |
oputp( /* print point */ |
774 |
> |
oputp( /* print intersection point */ |
775 |
|
RAY *r |
776 |
|
) |
777 |
|
{ |
778 |
< |
if (r->rot < FHUGE*.99) |
772 |
< |
(*putreal)(r->rop, 3); |
773 |
< |
else |
774 |
< |
(*putreal)(vdummy, 3); |
778 |
> |
(*putreal)(r->rop, 3); /* set to ray origin if distant or no hit */ |
779 |
|
} |
780 |
|
|
781 |
|
|
784 |
|
RAY *r |
785 |
|
) |
786 |
|
{ |
787 |
< |
if (r->rot < FHUGE*.99) { |
784 |
< |
if (r->rflips & 1) { /* undo any flippin' flips */ |
785 |
< |
FVECT unrm; |
786 |
< |
unrm[0] = -r->ron[0]; |
787 |
< |
unrm[1] = -r->ron[1]; |
788 |
< |
unrm[2] = -r->ron[2]; |
789 |
< |
(*putreal)(unrm, 3); |
790 |
< |
} else |
791 |
< |
(*putreal)(r->ron, 3); |
792 |
< |
} else |
787 |
> |
if (r->ro == NULL) { /* zero vector if clipped or no hit */ |
788 |
|
(*putreal)(vdummy, 3); |
789 |
+ |
return; |
790 |
+ |
} |
791 |
+ |
if (r->rflips & 1) { /* undo any flippin' flips */ |
792 |
+ |
FVECT unrm; |
793 |
+ |
unrm[0] = -r->ron[0]; |
794 |
+ |
unrm[1] = -r->ron[1]; |
795 |
+ |
unrm[2] = -r->ron[2]; |
796 |
+ |
(*putreal)(unrm, 3); |
797 |
+ |
} else |
798 |
+ |
(*putreal)(r->ron, 3); |
799 |
|
} |
800 |
|
|
801 |
|
|
806 |
|
{ |
807 |
|
FVECT pnorm; |
808 |
|
|
809 |
< |
if (r->rot >= FHUGE*.99) { |
809 |
> |
if (r->ro == NULL) { /* clipped or no hit */ |
810 |
|
(*putreal)(vdummy, 3); |
811 |
|
return; |
812 |
|
} |