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, |
23 |
< |
* radiance is computed. The '-i' option indicates that |
23 |
> |
* radiance is computed. The '-i' or '-I' options indicate that |
24 |
|
* irradiance values are desired. |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "ray.h" |
28 |
|
|
29 |
+ |
#include "octree.h" |
30 |
+ |
|
31 |
|
#include "otypes.h" |
32 |
|
|
33 |
+ |
int imm_irrad = 0; /* compute immediate irradiance? */ |
34 |
+ |
|
35 |
|
int inform = 'a'; /* input format */ |
36 |
|
int outform = 'a'; /* output format */ |
37 |
|
char *outvals = "v"; /* output specification */ |
48 |
|
|
49 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
50 |
|
double ambacc = 0.2; /* ambient accuracy */ |
51 |
< |
int ambres = 128; /* ambient resolution */ |
51 |
> |
int ambres = 32; /* ambient resolution */ |
52 |
|
int ambdiv = 128; /* ambient divisions */ |
53 |
|
int ambssamp = 0; /* ambient super-samples */ |
54 |
|
int ambounce = 0; /* ambient bounces */ |
55 |
|
char *amblist[128]; /* ambient include/exclude list */ |
56 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
57 |
|
|
58 |
+ |
extern OBJREC Lamb; /* a Lambertian surface */ |
59 |
+ |
|
60 |
|
static RAY thisray; /* for our convenience */ |
61 |
|
|
62 |
< |
extern int oputo(), oputd(), oputv(), oputl(), |
62 |
> |
static int oputo(), oputd(), oputv(), oputl(), |
63 |
|
oputp(), oputn(), oputs(), oputw(), oputm(); |
64 |
|
|
65 |
|
static int (*ray_out[10])(), (*every_out[10])(); |
66 |
+ |
static int castonly; |
67 |
|
|
68 |
< |
extern int puta(), putf(), putd(); |
68 |
> |
static int puta(), putf(), putd(); |
69 |
|
|
70 |
|
static int (*putreal)(); |
71 |
|
|
102 |
|
while (getvec(orig, inform, fp) == 0 && |
103 |
|
getvec(direc, inform, fp) == 0) { |
104 |
|
|
105 |
< |
if (normalize(direc) == 0.0) |
106 |
< |
error(USER, "zero direction vector"); |
105 |
> |
if (normalize(direc) == 0.0) { /* zero ==> flush */ |
106 |
> |
fflush(stdout); |
107 |
> |
continue; |
108 |
> |
} |
109 |
|
/* compute and print */ |
110 |
< |
if (outvals[0] == 'i') |
110 |
> |
if (imm_irrad) |
111 |
|
irrad(orig, direc); |
112 |
|
else |
113 |
< |
radiance(orig, direc); |
114 |
< |
/* flush if requested */ |
113 |
> |
traceray(orig, direc); |
114 |
> |
/* flush if time */ |
115 |
|
if (--nextflush == 0) { |
116 |
|
fflush(stdout); |
117 |
|
nextflush = hresolu; |
133 |
|
extern int ourtrace(), (*trace)(); |
134 |
|
register int (**table)() = ray_out; |
135 |
|
|
136 |
+ |
castonly = 1; |
137 |
|
while (*vs) |
138 |
|
switch (*vs++) { |
139 |
|
case 't': /* trace */ |
140 |
|
*table = NULL; |
141 |
|
table = every_out; |
142 |
|
trace = ourtrace; |
143 |
+ |
castonly = 0; |
144 |
|
break; |
145 |
|
case 'o': /* origin */ |
146 |
|
*table++ = oputo; |
150 |
|
break; |
151 |
|
case 'v': /* value */ |
152 |
|
*table++ = oputv; |
153 |
+ |
castonly = 0; |
154 |
|
break; |
155 |
|
case 'l': /* length */ |
156 |
|
*table++ = oputl; |
157 |
+ |
castonly = 0; |
158 |
|
break; |
159 |
|
case 'p': /* point */ |
160 |
|
*table++ = oputp; |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
< |
radiance(org, dir) /* compute radiance value */ |
179 |
> |
traceray(org, dir) /* compute and print ray value(s) */ |
180 |
|
FVECT org, dir; |
181 |
|
{ |
182 |
|
register int (**tp)(); |
184 |
|
VCOPY(thisray.rorg, org); |
185 |
|
VCOPY(thisray.rdir, dir); |
186 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
187 |
< |
rayvalue(&thisray); |
187 |
> |
if (castonly) |
188 |
> |
localhit(&thisray, &thescene) || sourcehit(&thisray); |
189 |
> |
else |
190 |
> |
rayvalue(&thisray); |
191 |
|
|
192 |
|
if (ray_out[0] == NULL) |
193 |
|
return; |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
< |
irrad(org, dir) /* compute irradiance value */ |
201 |
> |
irrad(org, dir) /* compute immediate irradiance value */ |
202 |
|
FVECT org, dir; |
203 |
|
{ |
187 |
– |
static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
188 |
– |
static OBJREC Lamb = { |
189 |
– |
OVOID, MAT_PLASTIC, "Lambertian", |
190 |
– |
{0, 5, NULL, Lambfa}, NULL, -1, |
191 |
– |
}; |
204 |
|
register int i; |
205 |
|
|
206 |
|
for (i = 0; i < 3; i++) { |
235 |
|
return(-1); |
236 |
|
break; |
237 |
|
case 'f': /* binary float */ |
238 |
< |
if (fread(vf, sizeof(float), 3, fp) != 3) |
238 |
> |
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
239 |
|
return(-1); |
240 |
|
vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; |
241 |
|
break; |
242 |
|
case 'd': /* binary double */ |
243 |
< |
if (fread(vec, sizeof(double), 3, fp) != 3) |
243 |
> |
if (fread((char *)vec, sizeof(double), 3, fp) != 3) |
244 |
|
return(-1); |
245 |
|
break; |
246 |
|
} |
308 |
|
oputl(r) /* print length */ |
309 |
|
register RAY *r; |
310 |
|
{ |
311 |
< |
if (r->rot < FHUGE) |
300 |
< |
(*putreal)(r->rot); |
301 |
< |
else |
302 |
< |
(*putreal)(0.0); |
311 |
> |
(*putreal)(r->rt); |
312 |
|
} |
313 |
|
|
314 |
|
|
388 |
|
putd(v) /* print binary double */ |
389 |
|
double v; |
390 |
|
{ |
391 |
< |
fwrite(&v, sizeof(v), 1, stdout); |
391 |
> |
fwrite((char *)&v, sizeof(v), 1, stdout); |
392 |
|
} |
393 |
|
|
394 |
|
|
398 |
|
{ |
399 |
|
float f = v; |
400 |
|
|
401 |
< |
fwrite(&f, sizeof(f), 1, stdout); |
401 |
> |
fwrite((char *)&f, sizeof(f), 1, stdout); |
402 |
|
} |