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