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 '-oi' or '-oI' 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 inform = 'a'; /* input format */ |
59 |
|
oputp(), oputn(), oputs(), oputw(), oputm(); |
60 |
|
|
61 |
|
static int (*ray_out[10])(), (*every_out[10])(); |
62 |
+ |
static int castonly; |
63 |
|
|
64 |
|
static int puta(), putf(), putd(); |
65 |
|
|
66 |
|
static int (*putreal)(); |
67 |
|
|
68 |
+ |
static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
69 |
+ |
static OBJREC Lamb = { |
70 |
+ |
OVOID, MAT_PLASTIC, "Lambertian", |
71 |
+ |
{0, 5, NULL, Lambfa}, NULL, -1, |
72 |
+ |
}; /* a Lambertian surface */ |
73 |
|
|
74 |
+ |
|
75 |
|
quit(code) /* quit program */ |
76 |
|
int code; |
77 |
|
{ |
111 |
|
/* compute and print */ |
112 |
|
if (outvals[0] == 'i') |
113 |
|
irrad(orig, direc); |
114 |
+ |
else if (outvals[0] == 'I') |
115 |
+ |
Irrad(orig, direc); |
116 |
|
else |
117 |
|
radiance(orig, direc); |
118 |
|
/* flush if time */ |
137 |
|
extern int ourtrace(), (*trace)(); |
138 |
|
register int (**table)() = ray_out; |
139 |
|
|
140 |
+ |
castonly = 1; |
141 |
|
while (*vs) |
142 |
|
switch (*vs++) { |
143 |
|
case 't': /* trace */ |
144 |
|
*table = NULL; |
145 |
|
table = every_out; |
146 |
|
trace = ourtrace; |
147 |
+ |
castonly = 0; |
148 |
|
break; |
149 |
|
case 'o': /* origin */ |
150 |
|
*table++ = oputo; |
154 |
|
break; |
155 |
|
case 'v': /* value */ |
156 |
|
*table++ = oputv; |
157 |
+ |
castonly = 0; |
158 |
|
break; |
159 |
|
case 'l': /* length */ |
160 |
|
*table++ = oputl; |
161 |
+ |
castonly = 0; |
162 |
|
break; |
163 |
|
case 'p': /* point */ |
164 |
|
*table++ = oputp; |
188 |
|
VCOPY(thisray.rorg, org); |
189 |
|
VCOPY(thisray.rdir, dir); |
190 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
191 |
< |
rayvalue(&thisray); |
191 |
> |
if (castonly) |
192 |
> |
localhit(&thisray, &thescene) || sourcehit(&thisray); |
193 |
> |
else |
194 |
> |
rayvalue(&thisray); |
195 |
|
|
196 |
|
if (ray_out[0] == NULL) |
197 |
|
return; |
205 |
|
irrad(org, dir) /* compute irradiance value */ |
206 |
|
FVECT org, dir; |
207 |
|
{ |
190 |
– |
static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
191 |
– |
static OBJREC Lamb = { |
192 |
– |
OVOID, MAT_PLASTIC, "Lambertian", |
193 |
– |
{0, 5, NULL, Lambfa}, NULL, -1, |
194 |
– |
}; |
208 |
|
register int i; |
209 |
|
|
210 |
|
for (i = 0; i < 3; i++) { |
220 |
|
thisray.rop[i] = org[i] + 1e-4*dir[i]; |
221 |
|
/* compute and print */ |
222 |
|
(*ofun[Lamb.otype].funp)(&Lamb, &thisray); |
223 |
+ |
oputv(&thisray); |
224 |
+ |
if (outform == 'a') |
225 |
+ |
putchar('\n'); |
226 |
+ |
} |
227 |
+ |
|
228 |
+ |
|
229 |
+ |
Irrad(org, dir) /* compute irradiance value after intersection */ |
230 |
+ |
FVECT org, dir; |
231 |
+ |
{ |
232 |
+ |
/* compute intersection */ |
233 |
+ |
VCOPY(thisray.rorg, org); |
234 |
+ |
VCOPY(thisray.rdir, dir); |
235 |
+ |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
236 |
+ |
localhit(&thisray, &thescene); |
237 |
+ |
if (thisray.ro != NULL) /* pretend we hit Lambertian surf. */ |
238 |
+ |
(*ofun[Lamb.otype].funp)(&Lamb, &thisray); |
239 |
|
oputv(&thisray); |
240 |
|
if (outform == 'a') |
241 |
|
putchar('\n'); |