9 |
|
|
10 |
|
#include "ray.h" |
11 |
|
#include "otypes.h" |
12 |
+ |
#include "otspecial.h" |
13 |
|
#include "rtotypes.h" |
14 |
|
#include "source.h" |
15 |
|
|
30 |
|
VSMATERIAL mirror_vs = {mir_proj, 1}; |
31 |
|
|
32 |
|
|
33 |
< |
extern int |
33 |
> |
int |
34 |
|
m_mirror( /* shade mirrored ray */ |
35 |
< |
register OBJREC *m, |
36 |
< |
register RAY *r |
35 |
> |
OBJREC *m, |
36 |
> |
RAY *r |
37 |
|
) |
38 |
|
{ |
39 |
< |
COLOR mcolor; |
39 |
> |
SCOLOR mcolor; |
40 |
|
RAY nr; |
41 |
|
int rpure = 1; |
42 |
< |
register int i; |
42 |
> |
int i; |
43 |
|
/* check arguments */ |
44 |
|
if (m->oargs.nfargs != 3 || m->oargs.nsargs > 1) |
45 |
|
objerror(m, USER, "bad number of arguments"); |
46 |
|
/* check for substitute material */ |
47 |
+ |
/* but avoid double-counting */ |
48 |
|
if (m->oargs.nsargs > 0 && |
49 |
|
(r->rsrc < 0 || source[r->rsrc].so != r->ro)) { |
50 |
< |
if (!strcmp(m->oargs.sarg[0], VOIDID)) { |
51 |
< |
raytrans(r); |
50 |
> |
int passOK = (r->rod < 0.) | |
51 |
> |
!(r->crtype & (AMBIENT|SPECULAR)); |
52 |
> |
if (strcmp(m->oargs.sarg[0], VOIDID)) { |
53 |
> |
OBJECT altmod = lastmod(objndx(m), m->oargs.sarg[0]); |
54 |
> |
OBJREC *altmat; |
55 |
> |
if (passOK) /* no double-count hazard? */ |
56 |
> |
return(rayshade(r, altmod)); |
57 |
> |
if (altmod == OVOID || /* else check alternate type */ |
58 |
> |
(altmat = findmaterial(objptr(altmod))) == NULL) |
59 |
> |
return(0); |
60 |
> |
if (istransp(altmat)) /* pass "transparent" materials */ |
61 |
> |
return(rayshade(r, altmod)); |
62 |
> |
} else if (passOK) { |
63 |
> |
raytrans(r); /* "safe" void passage */ |
64 |
|
return(1); |
65 |
|
} |
52 |
– |
return(rayshade(r, lastmod(objndx(m), m->oargs.sarg[0]))); |
66 |
|
} |
67 |
|
/* check for bad source ray */ |
68 |
|
if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) |
69 |
|
return(1); |
70 |
|
|
71 |
< |
if (r->rod < 0.) /* back is black */ |
71 |
> |
if (r->rod < 0.) { /* back is black */ |
72 |
> |
if (!backvis) |
73 |
> |
raytrans(r); /* unless back visibility is off */ |
74 |
|
return(1); |
75 |
+ |
} |
76 |
|
/* get modifiers */ |
77 |
|
raytexture(r, m->omod); |
78 |
|
/* assign material color */ |
79 |
< |
setcolor(mcolor, m->oargs.farg[0], |
79 |
> |
setscolor(mcolor, m->oargs.farg[0], |
80 |
|
m->oargs.farg[1], |
81 |
|
m->oargs.farg[2]); |
82 |
< |
multcolor(mcolor, r->pcol); |
82 |
> |
smultscolor(mcolor, r->pcol); |
83 |
|
/* compute reflected ray */ |
84 |
|
if (r->rsrc >= 0) { /* relayed light source */ |
85 |
|
rayorigin(&nr, REFLECTED, r, mcolor); |
94 |
|
|
95 |
|
if (rayorigin(&nr, REFLECTED, r, mcolor) < 0) |
96 |
|
return(1); |
97 |
< |
if (DOT(r->pert,r->pert) > FTINY*FTINY) { |
97 |
> |
if (!(r->crtype & AMBIENT) && |
98 |
> |
DOT(r->pert,r->pert) > FTINY*FTINY) { |
99 |
|
pdot = raynormal(pnorm, r); /* use textures */ |
100 |
|
for (i = 0; i < 3; i++) |
101 |
|
nr.rdir[i] = r->rdir[i] + 2.*pdot*pnorm[i]; |
108 |
|
} |
109 |
|
checknorm(nr.rdir); |
110 |
|
rayvalue(&nr); |
111 |
< |
multcolor(nr.rcol, nr.rcoef); |
112 |
< |
addcolor(r->rcol, nr.rcol); |
111 |
> |
smultscolor(nr.rcol, nr.rcoef); |
112 |
> |
copyscolor(r->mcol, nr.rcol); |
113 |
> |
saddscolor(r->rcol, nr.rcol); |
114 |
> |
r->rmt = r->rot; |
115 |
|
if (rpure && r->ro != NULL && isflat(r->ro->otype)) |
116 |
< |
r->rt = r->rot + nr.rt; |
116 |
> |
r->rmt += raydistance(&nr); |
117 |
|
return(1); |
118 |
|
} |
119 |
|
|
121 |
|
static int |
122 |
|
mir_proj( /* compute a mirror's projection */ |
123 |
|
MAT4 pm, |
124 |
< |
register OBJREC *o, |
124 |
> |
OBJREC *o, |
125 |
|
SRCREC *s, |
126 |
|
int n |
127 |
|
) |
157 |
|
|
158 |
|
static void |
159 |
|
mirrorproj( /* get mirror projection for surface */ |
160 |
< |
register MAT4 m, |
160 |
> |
MAT4 m, |
161 |
|
FVECT nv, |
162 |
|
double offs |
163 |
|
) |
164 |
|
{ |
165 |
< |
register int i, j; |
165 |
> |
int i, j; |
166 |
|
/* assign matrix */ |
167 |
|
setident4(m); |
168 |
|
for (j = 0; j < 3; j++) { |