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 |
< |
setmap(m, r, &((FULLXF *)m->os)->b); |
76 |
< |
sa = m->oargs.sarg + 4*n; |
75 |
> |
mf = getdfunc(m); |
76 |
> |
setfunc(m, r); |
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) |
110 |
< |
goto computerr; |
111 |
< |
multv3(nr.rdir, nr.rdir, ((FULLXF *)m->os)->f.xfm); |
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) |
120 |
|
rayvalue(&nr); |
121 |
|
scalecolor(nr.rcol, coef); |
122 |
|
addcolor(r->rcol, nr.rcol); |
123 |
+ |
if (r->ro != NULL && isflat(r->ro->otype)) |
124 |
+ |
r->rt = r->rot + nr.rt; |
125 |
|
return(1); |
126 |
|
computerr: |
127 |
|
objerror(m, WARNING, "compute error"); |
136 |
|
int n; |
137 |
|
{ |
138 |
|
RAY tr; |
139 |
< |
register OBJREC *m; |
140 |
< |
char **sa; |
139 |
> |
OBJREC *m; |
140 |
> |
MFUNC *mf; |
141 |
> |
EPNODE **va; |
142 |
|
FVECT cent, newdir, nv, h; |
143 |
< |
double olddot, newdot, od; |
143 |
> |
double coef, olddot, newdot, od; |
144 |
|
register int i, j; |
114 |
– |
/* get material arguments */ |
115 |
– |
m = objptr(o->omod); |
116 |
– |
dir_check(m); |
117 |
– |
sa = m->oargs.sarg + 4*n; |
145 |
|
/* initialize test ray */ |
146 |
|
getmaxdisk(cent, o); |
147 |
|
if (s->sflags & SDISTANT) |
161 |
|
olddot = DOT(tr.rdir, nv); |
162 |
|
if (olddot <= FTINY && olddot >= -FTINY) |
163 |
|
return(0); /* old dir parallels plane */ |
164 |
+ |
tr.rmax = 0.0; |
165 |
|
rayorigin(&tr, NULL, PRIMARY, 1.0); |
166 |
|
if (!(*ofun[o->otype].funp)(o, &tr)) |
167 |
|
return(0); /* no intersection! */ |
168 |
|
/* compute redirection */ |
169 |
< |
setmap(m, &tr, &((FULLXF *)m->os)->b); |
169 |
> |
m = vsmaterial(o); |
170 |
> |
mf = getdfunc(m); |
171 |
> |
setfunc(m, &tr); |
172 |
> |
varset("DxA", '=', 0.0); |
173 |
> |
varset("DyA", '=', 0.0); |
174 |
> |
varset("DzA", '=', 0.0); |
175 |
|
errno = 0; |
176 |
< |
if (varvalue(sa[0]) <= FTINY) |
177 |
< |
return(0); /* insignificant */ |
176 |
> |
va = mf->ep + 4*n; |
177 |
> |
coef = evalue(va[0]); |
178 |
|
if (errno) |
179 |
|
goto computerr; |
180 |
< |
for (i = 0; i < 3; i++) |
181 |
< |
newdir[i] = varvalue(sa[i+1]); |
182 |
< |
if (errno) |
183 |
< |
goto computerr; |
184 |
< |
multv3(newdir, newdir, ((FULLXF *)m->os)->f.xfm); |
180 |
> |
if (coef <= FTINY) |
181 |
> |
return(0); /* insignificant */ |
182 |
> |
va++; |
183 |
> |
for (i = 0; i < 3; i++) { |
184 |
> |
newdir[i] = evalue(va[i]); |
185 |
> |
if (errno) |
186 |
> |
goto computerr; |
187 |
> |
} |
188 |
> |
if (mf->f != &unitxf) |
189 |
> |
multv3(newdir, newdir, mf->f->xfm); |
190 |
|
/* normalization unnecessary */ |
191 |
|
newdot = DOT(newdir, nv); |
192 |
|
if (newdot <= FTINY && newdot >= -FTINY) |
210 |
|
computerr: |
211 |
|
objerror(m, WARNING, "projection compute error"); |
212 |
|
return(0); |
175 |
– |
} |
176 |
– |
|
177 |
– |
|
178 |
– |
static |
179 |
– |
dir_check(m) /* check arguments and load function file */ |
180 |
– |
register OBJREC *m; |
181 |
– |
{ |
182 |
– |
register FULLXF *mxf; |
183 |
– |
register int ff; |
184 |
– |
|
185 |
– |
ff = m->otype == MAT_DIRECT1 ? 5 : 9; |
186 |
– |
if (ff > m->oargs.nsargs) |
187 |
– |
objerror(m, USER, "too few arguments"); |
188 |
– |
funcfile(m->oargs.sarg[ff-1]); |
189 |
– |
if (m->os == NULL) { |
190 |
– |
mxf = (FULLXF *)malloc(sizeof(FULLXF)); |
191 |
– |
if (mxf == NULL) |
192 |
– |
error(SYSTEM, "out of memory in dir_check"); |
193 |
– |
if (fullxf(mxf, m->oargs.nsargs-ff, m->oargs.sarg+ff) != |
194 |
– |
m->oargs.nsargs-ff) |
195 |
– |
objerror(m, USER, "bad transform"); |
196 |
– |
if (mxf->f.sca < 0.0) |
197 |
– |
mxf->f.sca = -mxf->f.sca; |
198 |
– |
if (mxf->b.sca < 0.0) |
199 |
– |
mxf->b.sca = -mxf->b.sca; |
200 |
– |
m->os = (char *)mxf; |
201 |
– |
} |
213 |
|
} |