| 16 |
|
|
| 17 |
|
|
| 18 |
|
typedef struct { |
| 19 |
– |
double sca; /* scalefactor */ |
| 19 |
|
double xfm[4][4]; /* transform matrix */ |
| 20 |
+ |
double sca; /* scalefactor */ |
| 21 |
|
} XF; |
| 22 |
|
|
| 23 |
|
static OBJREC *fobj; /* current function object */ |
| 25 |
|
static XF fxf; /* current transformation */ |
| 26 |
|
|
| 27 |
|
|
| 28 |
< |
setmap(m, r, sca, xfm) /* set channels for function call */ |
| 28 |
> |
setmap(m, r, xfm, sca) /* set channels for function call */ |
| 29 |
|
OBJREC *m; |
| 30 |
|
register RAY *r; |
| 31 |
– |
double sca; |
| 31 |
|
double xfm[4][4]; |
| 32 |
+ |
double sca; |
| 33 |
|
{ |
| 34 |
|
extern double l_noise3(), l_noise3a(), l_noise3b(), l_noise3c(); |
| 35 |
|
extern double l_hermite(), l_fnoise3(), l_arg(); |
| 42 |
|
scompile(NULL, "Nx=$4;Ny=$5;Nz=$6;"); |
| 43 |
|
scompile(NULL, "Px=$7;Py=$8;Pz=$9;"); |
| 44 |
|
scompile(NULL, "T=$10;Rdot=$11;"); |
| 45 |
+ |
scompile(NULL, "S=$12;Tx=$13;Ty=$14;Tz=$15;"); |
| 46 |
+ |
scompile(NULL, "Ix=$16;Iy=$17;Iz=$18;"); |
| 47 |
+ |
scompile(NULL, "Jx=$19;Jy=$20;Jz=$21;"); |
| 48 |
+ |
scompile(NULL, "Kx=$22;Ky=$23;Kz=$24;"); |
| 49 |
|
funset("arg", 1, l_arg); |
| 50 |
|
funset("noise3", 3, l_noise3); |
| 51 |
|
funset("noise3a", 3, l_noise3a); |
| 57 |
|
} |
| 58 |
|
fobj = m; |
| 59 |
|
fray = r; |
| 60 |
< |
fxf.sca = r->ros * sca; |
| 61 |
< |
multmat4(fxf.xfm, r->rox, xfm); |
| 60 |
> |
fxf.sca = r->robs * sca; |
| 61 |
> |
multmat4(fxf.xfm, r->robx, xfm); |
| 62 |
|
eclock++; /* notify expression evaluator */ |
| 63 |
|
} |
| 64 |
|
|
| 70 |
|
register XF *mxf; |
| 71 |
|
|
| 72 |
|
if ((mxf = (XF *)m->os) == NULL) { |
| 73 |
< |
register int n = m->oargs.nsargs; |
| 74 |
< |
register char **sa = m->oargs.sarg; |
| 73 |
> |
register int n; |
| 74 |
> |
register char **sa; |
| 75 |
|
|
| 76 |
< |
while (n > 0 && **sa != '-') { |
| 77 |
< |
n--; |
| 78 |
< |
sa++; |
| 75 |
< |
} |
| 76 |
> |
for (n = m->oargs.nsargs, sa = m->oargs.sarg; |
| 77 |
> |
n > 0 && **sa != '-'; n--, sa++) |
| 78 |
> |
; |
| 79 |
|
mxf = (XF *)malloc(sizeof(XF)); |
| 80 |
|
if (mxf == NULL) |
| 81 |
|
goto memerr; |
| 79 |
– |
mxf->sca = 1.0; |
| 80 |
– |
setident4(mxf->xfm); |
| 82 |
|
if (invxf(mxf->xfm, &mxf->sca, n, sa) != n) |
| 83 |
|
objerror(m, USER, "bad transform"); |
| 84 |
|
if (mxf->sca < 0.0) |
| 85 |
|
mxf->sca = -mxf->sca; |
| 86 |
|
m->os = (char *)mxf; |
| 87 |
|
} |
| 88 |
< |
setmap(m, r, mxf->sca, mxf->xfm); |
| 88 |
> |
setmap(m, r, mxf->xfm, mxf->sca); |
| 89 |
|
return; |
| 90 |
|
memerr: |
| 91 |
|
error(SYSTEM, "out of memory in setfunc"); |
| 99 |
|
extern char *libpath; /* library search path */ |
| 100 |
|
char *ffname; |
| 101 |
|
|
| 102 |
< |
if ((ffname = getpath(fname, libpath)) == NULL) { |
| 102 |
> |
if ((ffname = getpath(fname, libpath, R_OK)) == NULL) { |
| 103 |
|
sprintf(errmsg, "cannot find function file \"%s\"", fname); |
| 104 |
|
error(USER, errmsg); |
| 105 |
|
} |
| 130 |
|
chanvalue(n) /* return channel n to calcomp */ |
| 131 |
|
register int n; |
| 132 |
|
{ |
| 133 |
< |
double res; |
| 133 |
> |
double sum; |
| 134 |
|
register RAY *r; |
| 135 |
|
|
| 136 |
< |
n--; /* for convenience */ |
| 136 |
> |
n--; /* for convenience */ |
| 137 |
|
|
| 138 |
< |
if (n < 0 || n > 10) |
| 138 |
> |
if (n < 0 || n > 23) |
| 139 |
|
error(USER, "illegal channel number"); |
| 140 |
|
|
| 141 |
< |
if (n == 9) { /* distance */ |
| 141 |
> |
if (n == 9) { /* distance */ |
| 142 |
|
|
| 143 |
< |
res = fray->rot; |
| 143 |
> |
sum = fray->rot; |
| 144 |
|
for (r = fray->parent; r != NULL; r = r->parent) |
| 145 |
< |
res += r->rot; |
| 146 |
< |
res *= fxf.sca; |
| 145 |
> |
sum += r->rot; |
| 146 |
> |
return(sum * fxf.sca); |
| 147 |
|
|
| 148 |
< |
} else if (n == 10) { /* dot product */ |
| 148 |
> |
} |
| 149 |
> |
if (n == 10) /* dot product */ |
| 150 |
> |
return(fray->rod); |
| 151 |
|
|
| 152 |
< |
res = fray->rod; |
| 152 |
> |
if (n < 3) /* ray direction */ |
| 153 |
|
|
| 154 |
< |
} else if (n < 3) { /* ray direction */ |
| 155 |
< |
res = ( fray->rdir[0]*fxf.xfm[0][n] + |
| 156 |
< |
fray->rdir[1]*fxf.xfm[1][n] + |
| 157 |
< |
fray->rdir[2]*fxf.xfm[2][n] ) |
| 155 |
< |
/ fxf.sca ; |
| 156 |
< |
} else if (n < 6) { /* surface normal */ |
| 157 |
< |
res = ( fray->ron[0]*fxf.xfm[0][n-3] + |
| 158 |
< |
fray->ron[1]*fxf.xfm[1][n-3] + |
| 159 |
< |
fray->ron[2]*fxf.xfm[2][n-3] ) |
| 160 |
< |
/ fxf.sca ; |
| 161 |
< |
} else { /* intersection */ |
| 162 |
< |
res = fray->rop[0]*fxf.xfm[0][n-6] + |
| 163 |
< |
fray->rop[1]*fxf.xfm[1][n-6] + |
| 164 |
< |
fray->rop[2]*fxf.xfm[2][n-6] + |
| 165 |
< |
fxf.xfm[3][n-6] ; |
| 166 |
< |
} |
| 154 |
> |
return( ( fray->rdir[0]*fxf.xfm[0][n] + |
| 155 |
> |
fray->rdir[1]*fxf.xfm[1][n] + |
| 156 |
> |
fray->rdir[2]*fxf.xfm[2][n] ) |
| 157 |
> |
/ fxf.sca ); |
| 158 |
|
|
| 159 |
< |
return(res); |
| 159 |
> |
if (n < 6) /* surface normal */ |
| 160 |
> |
|
| 161 |
> |
return( ( fray->ron[0]*fxf.xfm[0][n-3] + |
| 162 |
> |
fray->ron[1]*fxf.xfm[1][n-3] + |
| 163 |
> |
fray->ron[2]*fxf.xfm[2][n-3] ) |
| 164 |
> |
/ fxf.sca ); |
| 165 |
> |
|
| 166 |
> |
if (n < 9) /* intersection */ |
| 167 |
> |
|
| 168 |
> |
return( fray->rop[0]*fxf.xfm[0][n-6] + |
| 169 |
> |
fray->rop[1]*fxf.xfm[1][n-6] + |
| 170 |
> |
fray->rop[2]*fxf.xfm[2][n-6] + |
| 171 |
> |
fxf.xfm[3][n-6] ); |
| 172 |
> |
|
| 173 |
> |
if (n == 11) /* scale */ |
| 174 |
> |
return(fxf.sca); |
| 175 |
> |
|
| 176 |
> |
if (n < 15) /* origin */ |
| 177 |
> |
return(fxf.xfm[3][n-12]); |
| 178 |
> |
|
| 179 |
> |
if (n < 18) /* i unit vector */ |
| 180 |
> |
return(fxf.xfm[0][n-15] / fxf.sca); |
| 181 |
> |
|
| 182 |
> |
if (n < 21) /* j unit vector */ |
| 183 |
> |
return(fxf.xfm[1][n-15] / fxf.sca); |
| 184 |
> |
|
| 185 |
> |
if (n < 24) /* k unit vector */ |
| 186 |
> |
return(fxf.xfm[2][n-21] / fxf.sca); |
| 187 |
|
} |