1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* raytrace.c - routines for tracing and shading rays. |
6 |
|
* |
7 |
< |
* 8/7/85 |
7 |
> |
* External symbols declared in ray.h |
8 |
|
*/ |
9 |
|
|
10 |
+ |
#include "copyright.h" |
11 |
+ |
|
12 |
|
#include "ray.h" |
13 |
|
|
15 |
– |
#include "octree.h" |
16 |
– |
|
14 |
|
#include "otypes.h" |
15 |
|
|
16 |
|
#include "otspecial.h" |
17 |
|
|
18 |
|
#define MAXCSET ((MAXSET+1)*2-1) /* maximum check set size */ |
19 |
|
|
23 |
– |
extern CUBE thescene; /* our scene */ |
24 |
– |
extern int maxdepth; /* maximum recursion depth */ |
25 |
– |
extern double minweight; /* minimum ray weight */ |
26 |
– |
extern int do_irrad; /* compute irradiance? */ |
27 |
– |
extern COLOR ambval; /* ambient value */ |
28 |
– |
|
29 |
– |
extern COLOR cextinction; /* global extinction coefficient */ |
30 |
– |
extern COLOR salbedo; /* global scattering albedo */ |
31 |
– |
extern double seccg; /* global scattering eccentricity */ |
32 |
– |
extern double ssampdist; /* scatter sampling distance */ |
33 |
– |
|
20 |
|
unsigned long raynum = 0; /* next unique ray number */ |
21 |
|
unsigned long nrays = 0; /* number of calls to localhit */ |
22 |
|
|
28 |
|
|
29 |
|
OBJREC Aftplane; /* aft clipping plane object */ |
30 |
|
|
31 |
< |
static int raymove(), checkset(), checkhit(); |
31 |
> |
static int raymove(), checkhit(); |
32 |
> |
static void checkset(); |
33 |
|
|
34 |
|
#ifndef MAXLOOP |
35 |
|
#define MAXLOOP 0 /* modifier loop detection */ |
38 |
|
#define RAYHIT (-1) /* return value for intercepted ray */ |
39 |
|
|
40 |
|
|
41 |
+ |
int |
42 |
|
rayorigin(r, ro, rt, rw) /* start new ray from old one */ |
43 |
|
register RAY *r, *ro; |
44 |
|
int rt; |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
+ |
void |
93 |
|
rayclear(r) /* clear a ray for (re)evaluation */ |
94 |
|
register RAY *r; |
95 |
|
{ |
96 |
|
r->rno = raynum++; |
97 |
|
r->newcset = r->clipset; |
98 |
+ |
r->hitf = rayhit; |
99 |
|
r->robj = OVOID; |
100 |
|
r->ro = NULL; |
101 |
+ |
r->rox = NULL; |
102 |
|
r->rt = r->rot = FHUGE; |
103 |
|
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
104 |
+ |
r->uv[0] = r->uv[1] = 0.0; |
105 |
|
setcolor(r->pcol, 1.0, 1.0, 1.0); |
106 |
|
setcolor(r->rcol, 0.0, 0.0, 0.0); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
+ |
void |
111 |
|
raytrace(r) /* trace a ray and compute its value */ |
112 |
|
RAY *r; |
113 |
|
{ |
121 |
– |
extern int (*trace)(); |
122 |
– |
|
114 |
|
if (localhit(r, &thescene)) |
115 |
|
raycont(r); /* hit local surface, evaluate */ |
116 |
|
else if (r->ro == &Aftplane) { |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
+ |
void |
130 |
|
raycont(r) /* check for clipped object and continue */ |
131 |
|
register RAY *r; |
132 |
|
{ |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
+ |
void |
140 |
|
raytrans(r) /* transmit ray as is */ |
141 |
|
register RAY *r; |
142 |
|
{ |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
+ |
int |
155 |
|
rayshade(r, mod) /* shade ray r with material mod */ |
156 |
|
register RAY *r; |
157 |
|
int mod; |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
+ |
void |
199 |
|
rayparticipate(r) /* compute ray medium participation */ |
200 |
|
register RAY *r; |
201 |
|
{ |
259 |
|
} |
260 |
|
|
261 |
|
|
262 |
+ |
int |
263 |
|
raymixture(r, fore, back, coef) /* mix modifiers */ |
264 |
|
register RAY *r; |
265 |
|
OBJECT fore, back; |
360 |
|
} |
361 |
|
|
362 |
|
|
363 |
+ |
void |
364 |
|
newrayxf(r) /* get new tranformation matrix for ray */ |
365 |
|
RAY *r; |
366 |
|
{ |
380 |
|
if (rp->rox == &xp->xf) { /* xp in use */ |
381 |
|
xp = xp->next; /* move to next */ |
382 |
|
if (xp == xflast) { /* need new one */ |
383 |
< |
xp = (struct xfn *)bmalloc(sizeof(struct xfn)); |
383 |
> |
xp = (struct xfn *)malloc(sizeof(struct xfn)); |
384 |
|
if (xp == NULL) |
385 |
|
error(SYSTEM, |
386 |
|
"out of memory in newrayxf"); |
397 |
|
} |
398 |
|
|
399 |
|
|
400 |
+ |
void |
401 |
|
flipsurface(r) /* reverse surface orientation */ |
402 |
|
register RAY *r; |
403 |
|
{ |
411 |
|
} |
412 |
|
|
413 |
|
|
414 |
+ |
void |
415 |
+ |
rayhit(oset, r) /* standard ray hit test */ |
416 |
+ |
OBJECT *oset; |
417 |
+ |
RAY *r; |
418 |
+ |
{ |
419 |
+ |
OBJREC *o; |
420 |
+ |
int i; |
421 |
+ |
|
422 |
+ |
for (i = oset[0]; i > 0; i--) { |
423 |
+ |
o = objptr(oset[i]); |
424 |
+ |
if ((*ofun[o->otype].funp)(o, r)) |
425 |
+ |
r->robj = oset[i]; |
426 |
+ |
} |
427 |
+ |
} |
428 |
+ |
|
429 |
+ |
|
430 |
+ |
int |
431 |
|
localhit(r, scene) /* check for hit in the octree */ |
432 |
|
register RAY *r; |
433 |
|
register CUBE *scene; |
575 |
|
} |
576 |
|
|
577 |
|
|
578 |
< |
static |
578 |
> |
static int |
579 |
|
checkhit(r, cu, cxs) /* check for hit in full cube */ |
580 |
|
register RAY *r; |
581 |
|
CUBE *cu; |
582 |
|
OBJECT *cxs; |
583 |
|
{ |
584 |
|
OBJECT oset[MAXSET+1]; |
570 |
– |
register OBJREC *o; |
571 |
– |
register int i; |
585 |
|
|
586 |
|
objset(oset, cu->cutree); |
587 |
< |
checkset(oset, cxs); /* eliminate double-checking */ |
588 |
< |
for (i = oset[0]; i > 0; i--) { |
589 |
< |
o = objptr(oset[i]); |
590 |
< |
if ((*ofun[o->otype].funp)(o, r)) |
591 |
< |
r->robj = oset[i]; |
579 |
< |
} |
580 |
< |
if (r->ro == NULL) |
587 |
> |
checkset(oset, cxs); /* avoid double-checking */ |
588 |
> |
|
589 |
> |
(*r->hitf)(oset, r); /* test for hit in set */ |
590 |
> |
|
591 |
> |
if (r->robj == OVOID) |
592 |
|
return(0); /* no scores yet */ |
593 |
|
|
594 |
|
return(incube(cu, r->rop)); /* hit OK if in current cube */ |
595 |
|
} |
596 |
|
|
597 |
|
|
598 |
< |
static |
598 |
> |
static void |
599 |
|
checkset(os, cs) /* modify checked set and set to check */ |
600 |
|
register OBJECT *os; /* os' = os - cs */ |
601 |
|
register OBJECT *cs; /* cs' = cs + os */ |