1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1994 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
15 |
|
|
16 |
|
#include "source.h" |
17 |
|
|
18 |
+ |
#include "func.h" |
19 |
+ |
|
20 |
|
/* |
21 |
|
* The arguments for MAT_DIRECT1 are: |
22 |
|
* |
32 |
|
*/ |
33 |
|
|
34 |
|
|
33 |
– |
extern double varvalue(); |
34 |
– |
|
35 |
|
int dir_proj(); |
36 |
|
VSMATERIAL direct1_vs = {dir_proj, 1}; |
37 |
|
VSMATERIAL direct2_vs = {dir_proj, 2}; |
38 |
|
|
39 |
+ |
#define getdfunc(m) ( (m)->otype == MAT_DIRECT1 ? \ |
40 |
+ |
getfunc(m, 4, 0xf, 1) : \ |
41 |
+ |
getfunc(m, 8, 0xff, 1) ) |
42 |
|
|
43 |
+ |
|
44 |
|
m_direct(m, r) /* shade redirected ray */ |
45 |
|
register OBJREC *m; |
46 |
|
register RAY *r; |
47 |
|
{ |
48 |
|
/* check if source ray */ |
49 |
|
if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) |
50 |
< |
return; /* got the wrong guy */ |
47 |
< |
dir_check(m); |
50 |
> |
return(1); /* got the wrong guy */ |
51 |
|
/* compute first projection */ |
52 |
|
if (m->otype == MAT_DIRECT1 || |
53 |
|
(r->rsrc < 0 || source[r->rsrc].sa.sv.pn == 0)) |
56 |
|
if (m->otype == MAT_DIRECT2 && |
57 |
|
(r->rsrc < 0 || source[r->rsrc].sa.sv.pn == 1)) |
58 |
|
redirect(m, r, 1); |
59 |
+ |
return(1); |
60 |
|
} |
61 |
|
|
62 |
|
|
65 |
|
RAY *r; |
66 |
|
int n; |
67 |
|
{ |
68 |
< |
register char **sa; |
68 |
> |
MFUNC *mf; |
69 |
> |
register EPNODE **va; |
70 |
> |
FVECT nsdir; |
71 |
|
RAY nr; |
72 |
|
double coef; |
73 |
|
register int j; |
74 |
|
/* set up function */ |
75 |
+ |
mf = getdfunc(m); |
76 |
|
setfunc(m, r); |
77 |
< |
sa = m->oargs.sarg + 4*n; |
77 |
> |
/* assign direction variable */ |
78 |
> |
if (r->rsrc >= 0) { |
79 |
> |
register SRCREC *sp = source + source[r->rsrc].sa.sv.sn; |
80 |
> |
|
81 |
> |
if (sp->sflags & SDISTANT) |
82 |
> |
VCOPY(nsdir, sp->sloc); |
83 |
> |
else { |
84 |
> |
for (j = 0; j < 3; j++) |
85 |
> |
nsdir[j] = sp->sloc[j] - r->rop[j]; |
86 |
> |
normalize(nsdir); |
87 |
> |
} |
88 |
> |
multv3(nsdir, nsdir, funcxf.xfm); |
89 |
> |
varset("DxA", '=', nsdir[0]/funcxf.sca); |
90 |
> |
varset("DyA", '=', nsdir[1]/funcxf.sca); |
91 |
> |
varset("DzA", '=', nsdir[2]/funcxf.sca); |
92 |
> |
} else { |
93 |
> |
varset("DxA", '=', 0.0); |
94 |
> |
varset("DyA", '=', 0.0); |
95 |
> |
varset("DzA", '=', 0.0); |
96 |
> |
} |
97 |
|
/* compute coefficient */ |
98 |
|
errno = 0; |
99 |
< |
coef = varvalue(sa[0]); |
99 |
> |
va = mf->ep + 4*n; |
100 |
> |
coef = evalue(va[0]); |
101 |
|
if (errno) |
102 |
|
goto computerr; |
103 |
|
if (coef <= FTINY || rayorigin(&nr, r, TRANS, coef) < 0) |
104 |
|
return(0); |
105 |
< |
/* compute direction */ |
106 |
< |
errno = 0; |
107 |
< |
for (j = 0; j < 3; j++) |
108 |
< |
nr.rdir[j] = varvalue(sa[j+1]); |
109 |
< |
if (errno || normalize(nr.rdir) == 0.0) |
105 |
> |
va++; /* compute direction */ |
106 |
> |
for (j = 0; j < 3; j++) { |
107 |
> |
nr.rdir[j] = evalue(va[j]); |
108 |
> |
if (errno) |
109 |
> |
goto computerr; |
110 |
> |
} |
111 |
> |
if (mf->f != &unitxf) |
112 |
> |
multv3(nr.rdir, nr.rdir, mf->f->xfm); |
113 |
> |
if (r->rox != NULL) |
114 |
> |
multv3(nr.rdir, nr.rdir, r->rox->f.xfm); |
115 |
> |
if (normalize(nr.rdir) == 0.0) |
116 |
|
goto computerr; |
117 |
|
/* compute value */ |
118 |
|
if (r->rsrc >= 0) |
134 |
|
int n; |
135 |
|
{ |
136 |
|
RAY tr; |
137 |
< |
register OBJREC *m; |
138 |
< |
char **sa; |
137 |
> |
OBJREC *m; |
138 |
> |
MFUNC *mf; |
139 |
> |
EPNODE **va; |
140 |
|
FVECT cent, newdir, nv, h; |
141 |
< |
double olddot, newdot, od; |
141 |
> |
double coef, olddot, newdot, od; |
142 |
|
register int i, j; |
109 |
– |
/* get material arguments */ |
110 |
– |
m = objptr(o->omod); |
111 |
– |
dir_check(m); |
112 |
– |
sa = m->oargs.sarg + 4*n; |
143 |
|
/* initialize test ray */ |
144 |
|
getmaxdisk(cent, o); |
145 |
|
if (s->sflags & SDISTANT) |
159 |
|
olddot = DOT(tr.rdir, nv); |
160 |
|
if (olddot <= FTINY && olddot >= -FTINY) |
161 |
|
return(0); /* old dir parallels plane */ |
162 |
+ |
tr.rmax = 0.0; |
163 |
|
rayorigin(&tr, NULL, PRIMARY, 1.0); |
164 |
|
if (!(*ofun[o->otype].funp)(o, &tr)) |
165 |
|
return(0); /* no intersection! */ |
166 |
|
/* compute redirection */ |
167 |
+ |
m = vsmaterial(o); |
168 |
+ |
mf = getdfunc(m); |
169 |
|
setfunc(m, &tr); |
170 |
+ |
varset("DxA", '=', 0.0); |
171 |
+ |
varset("DyA", '=', 0.0); |
172 |
+ |
varset("DzA", '=', 0.0); |
173 |
|
errno = 0; |
174 |
< |
if (varvalue(sa[0]) <= FTINY) |
175 |
< |
return(0); /* insignificant */ |
174 |
> |
va = mf->ep + 4*n; |
175 |
> |
coef = evalue(va[0]); |
176 |
|
if (errno) |
177 |
|
goto computerr; |
178 |
< |
for (i = 0; i < 3; i++) |
179 |
< |
newdir[i] = varvalue(sa[i+1]); |
180 |
< |
if (errno) |
181 |
< |
goto computerr; |
178 |
> |
if (coef <= FTINY) |
179 |
> |
return(0); /* insignificant */ |
180 |
> |
va++; |
181 |
> |
for (i = 0; i < 3; i++) { |
182 |
> |
newdir[i] = evalue(va[i]); |
183 |
> |
if (errno) |
184 |
> |
goto computerr; |
185 |
> |
} |
186 |
> |
if (mf->f != &unitxf) |
187 |
> |
multv3(newdir, newdir, mf->f->xfm); |
188 |
> |
/* normalization unnecessary */ |
189 |
|
newdot = DOT(newdir, nv); |
190 |
|
if (newdot <= FTINY && newdot >= -FTINY) |
191 |
|
return(0); /* new dir parallels plane */ |
192 |
|
/* everything OK -- compute shear */ |
193 |
|
for (i = 0; i < 3; i++) |
194 |
< |
h[i] = tr.rdir[i]/olddot + newdir[i]/newdot; |
194 |
> |
h[i] = newdir[i]/newdot - tr.rdir[i]/olddot; |
195 |
|
setident4(pm); |
196 |
|
for (j = 0; j < 3; j++) { |
197 |
|
for (i = 0; i < 3; i++) |
208 |
|
computerr: |
209 |
|
objerror(m, WARNING, "projection compute error"); |
210 |
|
return(0); |
168 |
– |
} |
169 |
– |
|
170 |
– |
|
171 |
– |
static |
172 |
– |
dir_check(m) /* check arguments and load function file */ |
173 |
– |
register OBJREC *m; |
174 |
– |
{ |
175 |
– |
register int ff; |
176 |
– |
|
177 |
– |
ff = m->otype == MAT_DIRECT1 ? 4 : 8; |
178 |
– |
if (ff >= m->oargs.nsargs) |
179 |
– |
objerror(m, USER, "too few arguments"); |
180 |
– |
if (!vardefined(m->oargs.sarg[0])) |
181 |
– |
loadfunc(m->oargs.sarg[ff]); |
211 |
|
} |