16 |
|
* xorg yorg zorg xdir ydir zdir |
17 |
|
* |
18 |
|
* The direction need not be normalized. Output is flexible. |
19 |
+ |
* If the direction vector is (0,0,0), then the output is flushed. |
20 |
|
* All values default to ascii representation of real |
21 |
|
* numbers. Binary representations can be selected |
22 |
|
* with '-ff' for float or '-fd' for double. By default, |
26 |
|
|
27 |
|
#include "ray.h" |
28 |
|
|
29 |
+ |
#include "octree.h" |
30 |
+ |
|
31 |
|
#include "otypes.h" |
32 |
|
|
33 |
|
int inform = 'a'; /* input format */ |
38 |
|
int vresolu = 0; /* vertical resolution */ |
39 |
|
|
40 |
|
double dstrsrc = 0.0; /* square source distribution */ |
41 |
+ |
double shadthresh = .05; /* shadow threshold */ |
42 |
+ |
double shadcert = .5; /* shadow certainty */ |
43 |
|
|
44 |
|
int maxdepth = 6; /* maximum recursion depth */ |
45 |
|
double minweight = 4e-3; /* minimum ray weight */ |
46 |
|
|
47 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
48 |
|
double ambacc = 0.2; /* ambient accuracy */ |
49 |
< |
int ambres = 128; /* ambient resolution */ |
49 |
> |
int ambres = 32; /* ambient resolution */ |
50 |
|
int ambdiv = 128; /* ambient divisions */ |
51 |
|
int ambssamp = 0; /* ambient super-samples */ |
52 |
|
int ambounce = 0; /* ambient bounces */ |
55 |
|
|
56 |
|
static RAY thisray; /* for our convenience */ |
57 |
|
|
58 |
< |
extern int oputo(), oputd(), oputv(), oputl(), |
58 |
> |
static int oputo(), oputd(), oputv(), oputl(), |
59 |
|
oputp(), oputn(), oputs(), oputw(), oputm(); |
60 |
|
|
61 |
|
static int (*ray_out[10])(), (*every_out[10])(); |
62 |
+ |
static int castonly; |
63 |
|
|
64 |
< |
extern int puta(), putf(), putd(); |
64 |
> |
static int puta(), putf(), putd(); |
65 |
|
|
66 |
|
static int (*putreal)(); |
67 |
|
|
79 |
|
long vcount = hresolu>1 ? hresolu*vresolu : vresolu; |
80 |
|
long nextflush = hresolu; |
81 |
|
FILE *fp; |
82 |
< |
FVECT orig, direc, vcol; |
82 |
> |
FVECT orig, direc; |
83 |
|
/* set up input */ |
84 |
|
if (fname == NULL) |
85 |
|
fp = stdin; |
98 |
|
while (getvec(orig, inform, fp) == 0 && |
99 |
|
getvec(direc, inform, fp) == 0) { |
100 |
|
|
101 |
< |
if (normalize(direc) == 0.0) |
102 |
< |
error(USER, "zero direction vector"); |
101 |
> |
if (normalize(direc) == 0.0) { /* zero ==> flush */ |
102 |
> |
fflush(stdout); |
103 |
> |
continue; |
104 |
> |
} |
105 |
|
/* compute and print */ |
106 |
|
if (outvals[0] == 'i') |
107 |
|
irrad(orig, direc); |
108 |
|
else |
109 |
|
radiance(orig, direc); |
110 |
< |
/* flush if requested */ |
110 |
> |
/* flush if time */ |
111 |
|
if (--nextflush == 0) { |
112 |
|
fflush(stdout); |
113 |
|
nextflush = hresolu; |
129 |
|
extern int ourtrace(), (*trace)(); |
130 |
|
register int (**table)() = ray_out; |
131 |
|
|
132 |
+ |
castonly = 1; |
133 |
|
while (*vs) |
134 |
|
switch (*vs++) { |
135 |
|
case 't': /* trace */ |
136 |
|
*table = NULL; |
137 |
|
table = every_out; |
138 |
|
trace = ourtrace; |
139 |
+ |
castonly = 0; |
140 |
|
break; |
141 |
|
case 'o': /* origin */ |
142 |
|
*table++ = oputo; |
146 |
|
break; |
147 |
|
case 'v': /* value */ |
148 |
|
*table++ = oputv; |
149 |
+ |
castonly = 0; |
150 |
|
break; |
151 |
|
case 'l': /* length */ |
152 |
|
*table++ = oputl; |
153 |
+ |
castonly = 0; |
154 |
|
break; |
155 |
|
case 'p': /* point */ |
156 |
|
*table++ = oputp; |
180 |
|
VCOPY(thisray.rorg, org); |
181 |
|
VCOPY(thisray.rdir, dir); |
182 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
183 |
< |
rayvalue(&thisray); |
183 |
> |
if (castonly) |
184 |
> |
localhit(&thisray, &thescene) || sourcehit(&thisray); |
185 |
> |
else |
186 |
> |
rayvalue(&thisray); |
187 |
|
|
188 |
|
if (ray_out[0] == NULL) |
189 |
|
return; |
236 |
|
return(-1); |
237 |
|
break; |
238 |
|
case 'f': /* binary float */ |
239 |
< |
if (fread(vf, sizeof(float), 3, fp) != 3) |
239 |
> |
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
240 |
|
return(-1); |
241 |
|
vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; |
242 |
|
break; |
243 |
|
case 'd': /* binary double */ |
244 |
< |
if (fread(vec, sizeof(double), 3, fp) != 3) |
244 |
> |
if (fread((char *)vec, sizeof(double), 3, fp) != 3) |
245 |
|
return(-1); |
246 |
|
break; |
247 |
|
} |
309 |
|
oputl(r) /* print length */ |
310 |
|
register RAY *r; |
311 |
|
{ |
312 |
< |
if (r->rot < FHUGE) |
298 |
< |
(*putreal)(r->rot); |
299 |
< |
else |
300 |
< |
(*putreal)(0.0); |
312 |
> |
(*putreal)(r->rt); |
313 |
|
} |
314 |
|
|
315 |
|
|
389 |
|
putd(v) /* print binary double */ |
390 |
|
double v; |
391 |
|
{ |
392 |
< |
fwrite(&v, sizeof(v), 1, stdout); |
392 |
> |
fwrite((char *)&v, sizeof(v), 1, stdout); |
393 |
|
} |
394 |
|
|
395 |
|
|
399 |
|
{ |
400 |
|
float f = v; |
401 |
|
|
402 |
< |
fwrite(&f, sizeof(f), 1, stdout); |
402 |
> |
fwrite((char *)&f, sizeof(f), 1, stdout); |
403 |
|
} |