1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
15 |
|
#include "otypes.h" |
16 |
|
|
17 |
|
|
18 |
< |
typedef struct { |
19 |
< |
double xfm[4][4]; /* transform matrix */ |
20 |
< |
double sca; /* scalefactor */ |
21 |
< |
} XF; |
18 |
> |
XF unitxf = { /* identity transform */ |
19 |
> |
1.0, 0.0, 0.0, 0.0, |
20 |
> |
0.0, 1.0, 0.0, 0.0, |
21 |
> |
0.0, 0.0, 1.0, 0.0, |
22 |
> |
0.0, 0.0, 0.0, 1.0, |
23 |
> |
1.0 |
24 |
> |
}; |
25 |
|
|
26 |
< |
static OBJREC *fobj; /* current function object */ |
27 |
< |
static RAY *fray; /* current function ray */ |
28 |
< |
static XF fxf; /* current transformation */ |
26 |
> |
XF funcxf; /* current transformation */ |
27 |
> |
static OBJREC *fobj = NULL; /* current function object */ |
28 |
> |
static RAY *fray = NULL; /* current function ray */ |
29 |
|
|
30 |
|
|
31 |
< |
setmap(m, r, xfm, sca) /* set channels for function call */ |
31 |
> |
setmap(m, r, bx) /* set channels for function call */ |
32 |
|
OBJREC *m; |
33 |
|
register RAY *r; |
34 |
< |
double xfm[4][4]; |
32 |
< |
double sca; |
34 |
> |
XF *bx; |
35 |
|
{ |
36 |
< |
extern double l_noise3(), l_noise3a(), l_noise3b(), l_noise3c(); |
35 |
< |
extern double l_hermite(), l_fnoise3(), l_arg(); |
36 |
> |
extern double l_arg(); |
37 |
|
extern long eclock; |
38 |
|
static char *initfile = "rayinit.cal"; |
39 |
< |
|
39 |
> |
static long lastrno = -1; |
40 |
> |
/* check to see if already set */ |
41 |
> |
if (m == fobj && r->rno == lastrno) |
42 |
> |
return; |
43 |
> |
/* initialize if first call */ |
44 |
|
if (initfile != NULL) { |
45 |
|
loadfunc(initfile); |
46 |
< |
scompile(NULL, "Dx=$1;Dy=$2;Dz=$3;"); |
47 |
< |
scompile(NULL, "Nx=$4;Ny=$5;Nz=$6;"); |
48 |
< |
scompile(NULL, "Px=$7;Py=$8;Pz=$9;"); |
49 |
< |
scompile(NULL, "T=$10;Rdot=$11;"); |
50 |
< |
funset("arg", 1, l_arg); |
51 |
< |
funset("noise3", 3, l_noise3); |
52 |
< |
funset("noise3a", 3, l_noise3a); |
53 |
< |
funset("noise3b", 3, l_noise3b); |
54 |
< |
funset("noise3c", 3, l_noise3c); |
55 |
< |
funset("hermite", 5, l_hermite); |
51 |
< |
funset("fnoise3", 3, l_fnoise3); |
46 |
> |
scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0); |
47 |
> |
scompile("Nx=$4;Ny=$5;Nz=$6;", NULL, 0); |
48 |
> |
scompile("Px=$7;Py=$8;Pz=$9;", NULL, 0); |
49 |
> |
scompile("T=$10;Rdot=$11;", NULL, 0); |
50 |
> |
scompile("S=$12;Tx=$13;Ty=$14;Tz=$15;", NULL, 0); |
51 |
> |
scompile("Ix=$16;Iy=$17;Iz=$18;", NULL, 0); |
52 |
> |
scompile("Jx=$19;Jy=$20;Jz=$21;", NULL, 0); |
53 |
> |
scompile("Kx=$22;Ky=$23;Kz=$24;", NULL, 0); |
54 |
> |
funset("arg", 1, '=', l_arg); |
55 |
> |
setnoisefuncs(); |
56 |
|
initfile = NULL; |
57 |
|
} |
58 |
|
fobj = m; |
59 |
|
fray = r; |
60 |
< |
fxf.sca = r->robs * sca; |
61 |
< |
multmat4(fxf.xfm, r->robx, xfm); |
60 |
> |
if (r->rox != NULL) |
61 |
> |
if (bx != &unitxf) { |
62 |
> |
funcxf.sca = r->rox->b.sca * bx->sca; |
63 |
> |
multmat4(funcxf.xfm, r->rox->b.xfm, bx->xfm); |
64 |
> |
} else |
65 |
> |
copystruct(&funcxf, &r->rox->b); |
66 |
> |
else |
67 |
> |
copystruct(&funcxf, bx); |
68 |
> |
lastrno = r->rno; |
69 |
|
eclock++; /* notify expression evaluator */ |
70 |
|
} |
71 |
|
|
83 |
|
for (n = m->oargs.nsargs, sa = m->oargs.sarg; |
84 |
|
n > 0 && **sa != '-'; n--, sa++) |
85 |
|
; |
86 |
< |
mxf = (XF *)malloc(sizeof(XF)); |
87 |
< |
if (mxf == NULL) |
88 |
< |
goto memerr; |
89 |
< |
mxf->sca = 1.0; |
90 |
< |
setident4(mxf->xfm); |
91 |
< |
if (invxf(mxf->xfm, &mxf->sca, n, sa) != n) |
92 |
< |
objerror(m, USER, "bad transform"); |
93 |
< |
if (mxf->sca < 0.0) |
94 |
< |
mxf->sca = -mxf->sca; |
86 |
> |
if (n == 0) |
87 |
> |
mxf = &unitxf; |
88 |
> |
else { |
89 |
> |
mxf = (XF *)malloc(sizeof(XF)); |
90 |
> |
if (mxf == NULL) |
91 |
> |
goto memerr; |
92 |
> |
if (invxf(mxf, n, sa) != n) |
93 |
> |
objerror(m, USER, "bad transform"); |
94 |
> |
if (mxf->sca < 0.0) |
95 |
> |
mxf->sca = -mxf->sca; |
96 |
> |
} |
97 |
|
m->os = (char *)mxf; |
98 |
|
} |
99 |
< |
setmap(m, r, mxf->xfm, mxf->sca); |
99 |
> |
setmap(m, r, mxf); |
100 |
|
return; |
101 |
|
memerr: |
102 |
|
error(SYSTEM, "out of memory in setfunc"); |
90 |
– |
#undef mxf |
103 |
|
} |
104 |
|
|
105 |
|
|
109 |
|
extern char *libpath; /* library search path */ |
110 |
|
char *ffname; |
111 |
|
|
112 |
< |
if ((ffname = getpath(fname, libpath)) == NULL) { |
112 |
> |
if ((ffname = getpath(fname, libpath, R_OK)) == NULL) { |
113 |
|
sprintf(errmsg, "cannot find function file \"%s\"", fname); |
114 |
|
error(USER, errmsg); |
115 |
|
} |
140 |
|
chanvalue(n) /* return channel n to calcomp */ |
141 |
|
register int n; |
142 |
|
{ |
143 |
< |
double res; |
143 |
> |
double sum; |
144 |
|
register RAY *r; |
145 |
|
|
146 |
< |
n--; /* for convenience */ |
146 |
> |
if (--n < 0) |
147 |
> |
goto badchan; |
148 |
|
|
149 |
< |
if (n < 0 || n > 10) |
137 |
< |
error(USER, "illegal channel number"); |
149 |
> |
if (n < 3) /* ray direction */ |
150 |
|
|
151 |
< |
if (n == 9) { /* distance */ |
151 |
> |
return( ( fray->rdir[0]*funcxf.xfm[0][n] + |
152 |
> |
fray->rdir[1]*funcxf.xfm[1][n] + |
153 |
> |
fray->rdir[2]*funcxf.xfm[2][n] ) |
154 |
> |
/ funcxf.sca ); |
155 |
|
|
156 |
< |
res = fray->rot; |
142 |
< |
for (r = fray->parent; r != NULL; r = r->parent) |
143 |
< |
res += r->rot; |
144 |
< |
res *= fxf.sca; |
156 |
> |
if (n < 6) /* surface normal */ |
157 |
|
|
158 |
< |
} else if (n == 10) { /* dot product */ |
158 |
> |
return( ( fray->ron[0]*funcxf.xfm[0][n-3] + |
159 |
> |
fray->ron[1]*funcxf.xfm[1][n-3] + |
160 |
> |
fray->ron[2]*funcxf.xfm[2][n-3] ) |
161 |
> |
/ funcxf.sca ); |
162 |
|
|
163 |
< |
res = fray->rod; |
163 |
> |
if (n < 9) /* intersection */ |
164 |
|
|
165 |
< |
} else if (n < 3) { /* ray direction */ |
166 |
< |
res = ( fray->rdir[0]*fxf.xfm[0][n] + |
167 |
< |
fray->rdir[1]*fxf.xfm[1][n] + |
168 |
< |
fray->rdir[2]*fxf.xfm[2][n] ) |
169 |
< |
/ fxf.sca ; |
170 |
< |
} else if (n < 6) { /* surface normal */ |
171 |
< |
res = ( fray->ron[0]*fxf.xfm[0][n-3] + |
172 |
< |
fray->ron[1]*fxf.xfm[1][n-3] + |
173 |
< |
fray->ron[2]*fxf.xfm[2][n-3] ) |
174 |
< |
/ fxf.sca ; |
175 |
< |
} else { /* intersection */ |
176 |
< |
res = fray->rop[0]*fxf.xfm[0][n-6] + |
162 |
< |
fray->rop[1]*fxf.xfm[1][n-6] + |
163 |
< |
fray->rop[2]*fxf.xfm[2][n-6] + |
164 |
< |
fxf.xfm[3][n-6] ; |
165 |
> |
return( fray->rop[0]*funcxf.xfm[0][n-6] + |
166 |
> |
fray->rop[1]*funcxf.xfm[1][n-6] + |
167 |
> |
fray->rop[2]*funcxf.xfm[2][n-6] + |
168 |
> |
funcxf.xfm[3][n-6] ); |
169 |
> |
|
170 |
> |
if (n == 9) { /* distance */ |
171 |
> |
|
172 |
> |
sum = fray->rot; |
173 |
> |
for (r = fray->parent; r != NULL; r = r->parent) |
174 |
> |
sum += r->rot; |
175 |
> |
return(sum * funcxf.sca); |
176 |
> |
|
177 |
|
} |
178 |
+ |
if (n == 10) /* dot product */ |
179 |
+ |
return(fray->rod); |
180 |
|
|
181 |
< |
return(res); |
181 |
> |
if (n == 11) /* scale */ |
182 |
> |
return(funcxf.sca); |
183 |
> |
|
184 |
> |
if (n < 15) /* origin */ |
185 |
> |
return(funcxf.xfm[3][n-12]); |
186 |
> |
|
187 |
> |
if (n < 18) /* i unit vector */ |
188 |
> |
return(funcxf.xfm[0][n-15] / funcxf.sca); |
189 |
> |
|
190 |
> |
if (n < 21) /* j unit vector */ |
191 |
> |
return(funcxf.xfm[1][n-15] / funcxf.sca); |
192 |
> |
|
193 |
> |
if (n < 24) /* k unit vector */ |
194 |
> |
return(funcxf.xfm[2][n-21] / funcxf.sca); |
195 |
> |
badchan: |
196 |
> |
error(USER, "illegal channel number"); |
197 |
|
} |