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 fndx(m) ((m)->otype == MAT_DIRECT1 ? 4 : 8) |
39 |
> |
#define getdfunc(m) ( (m)->otype == MAT_DIRECT1 ? \ |
40 |
> |
getfunc(m, 4, 0xf, 1) : \ |
41 |
> |
getfunc(m, 8, 0xff, 1) ) |
42 |
|
|
43 |
|
|
42 |
– |
static |
43 |
– |
dir_check(m) /* check arguments and load function file */ |
44 |
– |
register OBJREC *m; |
45 |
– |
{ |
46 |
– |
register FULLXF *mxf; |
47 |
– |
register int ff; |
48 |
– |
|
49 |
– |
ff = fndx(m)+1; |
50 |
– |
if (ff > m->oargs.nsargs) |
51 |
– |
objerror(m, USER, "too few arguments"); |
52 |
– |
if (m->os == NULL) { |
53 |
– |
mxf = (FULLXF *)malloc(sizeof(FULLXF)); |
54 |
– |
if (mxf == NULL) |
55 |
– |
error(SYSTEM, "out of memory in dir_check"); |
56 |
– |
if (fullxf(mxf, m->oargs.nsargs-ff, m->oargs.sarg+ff) != |
57 |
– |
m->oargs.nsargs-ff) |
58 |
– |
objerror(m, USER, "bad transform"); |
59 |
– |
if (mxf->f.sca < 0.0) |
60 |
– |
mxf->f.sca = -mxf->f.sca; |
61 |
– |
if (mxf->b.sca < 0.0) |
62 |
– |
mxf->b.sca = -mxf->b.sca; |
63 |
– |
m->os = (char *)mxf; |
64 |
– |
} |
65 |
– |
} |
66 |
– |
|
67 |
– |
|
44 |
|
m_direct(m, r) /* shade redirected ray */ |
45 |
|
register OBJREC *m; |
46 |
|
register RAY *r; |
48 |
|
/* check if source ray */ |
49 |
|
if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) |
50 |
|
return; /* got the wrong guy */ |
75 |
– |
dir_check(m); |
51 |
|
/* compute first projection */ |
52 |
|
if (m->otype == MAT_DIRECT1 || |
53 |
|
(r->rsrc < 0 || source[r->rsrc].sa.sv.pn == 0)) |
64 |
|
RAY *r; |
65 |
|
int n; |
66 |
|
{ |
67 |
< |
register char **sa; |
67 |
> |
MFUNC *mf; |
68 |
> |
register EPNODE **va; |
69 |
> |
FVECT nsdir; |
70 |
|
RAY nr; |
71 |
|
double coef; |
72 |
|
register int j; |
73 |
|
/* set up function */ |
74 |
< |
setmap(m, r, &((FULLXF *)m->os)->b); |
75 |
< |
funcfile(m->oargs.sarg[fndx(m)]); |
76 |
< |
sa = m->oargs.sarg + 4*n; |
74 |
> |
mf = getdfunc(m); |
75 |
> |
setfunc(m, r); |
76 |
> |
/* assign direction variable */ |
77 |
> |
if (r->rsrc >= 0) { |
78 |
> |
register SRCREC *sp = source + source[r->rsrc].sa.sv.sn; |
79 |
> |
|
80 |
> |
if (sp->sflags & SDISTANT) |
81 |
> |
VCOPY(nsdir, sp->sloc); |
82 |
> |
else { |
83 |
> |
for (j = 0; j < 3; j++) |
84 |
> |
nsdir[j] = sp->sloc[j] - r->rop[j]; |
85 |
> |
normalize(nsdir); |
86 |
> |
} |
87 |
> |
if (r->rox != NULL) |
88 |
> |
multv3(nsdir, nsdir, r->rox->b.xfm); |
89 |
> |
if (mf->b != &unitxf) |
90 |
> |
multv3(nsdir, nsdir, mf->b->xfm); |
91 |
> |
} else |
92 |
> |
nsdir[0] = nsdir[1] = nsdir[2] = 0.0; |
93 |
> |
varset("DxA", '=', nsdir[0]); |
94 |
> |
varset("DyA", '=', nsdir[1]); |
95 |
> |
varset("DzA", '=', nsdir[2]); |
96 |
|
/* compute coefficient */ |
97 |
|
errno = 0; |
98 |
< |
coef = varvalue(sa[0]); |
98 |
> |
va = mf->ep + 4*n; |
99 |
> |
coef = evalue(va[0]); |
100 |
|
if (errno) |
101 |
|
goto computerr; |
102 |
|
if (coef <= FTINY || rayorigin(&nr, r, TRANS, coef) < 0) |
103 |
|
return(0); |
104 |
< |
/* compute direction */ |
105 |
< |
errno = 0; |
106 |
< |
for (j = 0; j < 3; j++) |
107 |
< |
nr.rdir[j] = varvalue(sa[j+1]); |
108 |
< |
if (errno) |
109 |
< |
goto computerr; |
110 |
< |
multv3(nr.rdir, nr.rdir, ((FULLXF *)m->os)->f.xfm); |
104 |
> |
va++; /* compute direction */ |
105 |
> |
for (j = 0; j < 3; j++) { |
106 |
> |
nr.rdir[j] = evalue(va[j]); |
107 |
> |
if (errno) |
108 |
> |
goto computerr; |
109 |
> |
} |
110 |
> |
if (mf->f != &unitxf) |
111 |
> |
multv3(nr.rdir, nr.rdir, mf->f->xfm); |
112 |
|
if (r->rox != NULL) |
113 |
|
multv3(nr.rdir, nr.rdir, r->rox->f.xfm); |
114 |
|
if (normalize(nr.rdir) == 0.0) |
133 |
|
int n; |
134 |
|
{ |
135 |
|
RAY tr; |
136 |
< |
register OBJREC *m; |
137 |
< |
char **sa; |
136 |
> |
OBJREC *m; |
137 |
> |
MFUNC *mf; |
138 |
> |
EPNODE **va; |
139 |
|
FVECT cent, newdir, nv, h; |
140 |
< |
double olddot, newdot, od; |
140 |
> |
double coef, olddot, newdot, od; |
141 |
|
register int i, j; |
143 |
– |
/* get material arguments */ |
144 |
– |
m = objptr(o->omod); |
145 |
– |
dir_check(m); |
146 |
– |
sa = m->oargs.sarg + 4*n; |
142 |
|
/* initialize test ray */ |
143 |
|
getmaxdisk(cent, o); |
144 |
|
if (s->sflags & SDISTANT) |
162 |
|
if (!(*ofun[o->otype].funp)(o, &tr)) |
163 |
|
return(0); /* no intersection! */ |
164 |
|
/* compute redirection */ |
165 |
< |
setmap(m, &tr, &((FULLXF *)m->os)->b); |
166 |
< |
funcfile(m->oargs.sarg[fndx(m)]); |
165 |
> |
m = vsmaterial(o); |
166 |
> |
mf = getdfunc(m); |
167 |
> |
setfunc(m, &tr); |
168 |
> |
varset("DxA", '=', 0.0); |
169 |
> |
varset("DyA", '=', 0.0); |
170 |
> |
varset("DzA", '=', 0.0); |
171 |
|
errno = 0; |
172 |
< |
if (varvalue(sa[0]) <= FTINY) |
173 |
< |
return(0); /* insignificant */ |
172 |
> |
va = mf->ep + 4*n; |
173 |
> |
coef = evalue(va[0]); |
174 |
|
if (errno) |
175 |
|
goto computerr; |
176 |
< |
for (i = 0; i < 3; i++) |
177 |
< |
newdir[i] = varvalue(sa[i+1]); |
178 |
< |
if (errno) |
179 |
< |
goto computerr; |
180 |
< |
multv3(newdir, newdir, ((FULLXF *)m->os)->f.xfm); |
176 |
> |
if (coef <= FTINY) |
177 |
> |
return(0); /* insignificant */ |
178 |
> |
va++; |
179 |
> |
for (i = 0; i < 3; i++) { |
180 |
> |
newdir[i] = evalue(va[i]); |
181 |
> |
if (errno) |
182 |
> |
goto computerr; |
183 |
> |
} |
184 |
> |
if (mf->f != &unitxf) |
185 |
> |
multv3(newdir, newdir, mf->f->xfm); |
186 |
|
/* normalization unnecessary */ |
187 |
|
newdot = DOT(newdir, nv); |
188 |
|
if (newdot <= FTINY && newdot >= -FTINY) |