| 30 |
|
static OBJREC *fobj = NULL; /* current function object */ |
| 31 |
|
static RAY *fray = NULL; /* current function ray */ |
| 32 |
|
|
| 33 |
+ |
static char rayinitcal[] = INITFILE; |
| 34 |
+ |
|
| 35 |
|
static double l_erf(char *), l_erfc(char *), l_arg(char *); |
| 36 |
|
|
| 37 |
|
|
| 38 |
+ |
void |
| 39 |
+ |
initfunc() /* initialize function evaluation */ |
| 40 |
+ |
{ |
| 41 |
+ |
if (!rayinitcal[0]) /* already done? */ |
| 42 |
+ |
return; |
| 43 |
+ |
esupport |= E_VARIABLE|E_FUNCTION|E_INCHAN|E_RCONST|E_REDEFW; |
| 44 |
+ |
esupport &= ~(E_OUTCHAN); |
| 45 |
+ |
setcontext(""); |
| 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;Ts=$25;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 |
+ |
scompile("Lu=$26;Lv=$27;", NULL, 0); |
| 55 |
+ |
funset("arg", 1, '=', l_arg); |
| 56 |
+ |
funset("erf", 1, ':', l_erf); |
| 57 |
+ |
funset("erfc", 1, ':', l_erfc); |
| 58 |
+ |
setnoisefuncs(); |
| 59 |
+ |
setprismfuncs(); |
| 60 |
+ |
loadfunc(rayinitcal); |
| 61 |
+ |
rayinitcal[0] = '\0'; |
| 62 |
+ |
} |
| 63 |
+ |
|
| 64 |
+ |
|
| 65 |
|
MFUNC * |
| 66 |
|
getfunc( /* get function for this modifier */ |
| 67 |
|
OBJREC *m, |
| 70 |
|
int dofwd |
| 71 |
|
) |
| 72 |
|
{ |
| 44 |
– |
static char initfile[] = INITFILE; |
| 73 |
|
char sbuf[MAXSTR]; |
| 74 |
|
char **arg; |
| 75 |
|
MFUNC *f; |
| 79 |
|
if ((f = (MFUNC *)m->os) != NULL) |
| 80 |
|
return(f); |
| 81 |
|
fobj = NULL; fray = NULL; |
| 82 |
< |
if (initfile[0]) { /* initialize on first call */ |
| 83 |
< |
esupport |= E_VARIABLE|E_FUNCTION|E_INCHAN|E_RCONST|E_REDEFW; |
| 56 |
< |
esupport &= ~(E_OUTCHAN); |
| 57 |
< |
setcontext(""); |
| 58 |
< |
scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0); |
| 59 |
< |
scompile("Nx=$4;Ny=$5;Nz=$6;", NULL, 0); |
| 60 |
< |
scompile("Px=$7;Py=$8;Pz=$9;", NULL, 0); |
| 61 |
< |
scompile("T=$10;Ts=$25;Rdot=$11;", NULL, 0); |
| 62 |
< |
scompile("S=$12;Tx=$13;Ty=$14;Tz=$15;", NULL, 0); |
| 63 |
< |
scompile("Ix=$16;Iy=$17;Iz=$18;", NULL, 0); |
| 64 |
< |
scompile("Jx=$19;Jy=$20;Jz=$21;", NULL, 0); |
| 65 |
< |
scompile("Kx=$22;Ky=$23;Kz=$24;", NULL, 0); |
| 66 |
< |
scompile("Lu=$26;Lv=$27;", NULL, 0); |
| 67 |
< |
funset("arg", 1, '=', l_arg); |
| 68 |
< |
funset("erf", 1, ':', l_erf); |
| 69 |
< |
funset("erfc", 1, ':', l_erfc); |
| 70 |
< |
setnoisefuncs(); |
| 71 |
< |
setprismfuncs(); |
| 72 |
< |
loadfunc(initfile); |
| 73 |
< |
initfile[0] = '\0'; |
| 74 |
< |
} |
| 82 |
> |
if (rayinitcal[0]) /* initialize on first call */ |
| 83 |
> |
initfunc(); |
| 84 |
|
if ((na = m->oargs.nsargs) <= ff) |
| 85 |
|
goto toofew; |
| 86 |
|
arg = m->oargs.sarg; |
| 87 |
|
if ((f = (MFUNC *)calloc(1, sizeof(MFUNC))) == NULL) |
| 88 |
|
goto memerr; |
| 89 |
|
i = strlen(arg[ff]); /* set up context */ |
| 90 |
< |
if (i == 1 && arg[ff][0] == '.') |
| 90 |
> |
if (i == 1 && arg[ff][0] == '.') { |
| 91 |
|
setcontext(f->ctx = ""); /* "." means no file */ |
| 92 |
< |
else { |
| 92 |
> |
} else { |
| 93 |
|
strcpy(sbuf,arg[ff]); /* file name is context */ |
| 94 |
|
if (i > LCALSUF && !strcmp(sbuf+i-LCALSUF, CALSUF)) |
| 95 |
|
sbuf[i-LCALSUF] = '\0'; /* remove suffix */ |
| 117 |
|
i = ff+1; |
| 118 |
|
while (i < na && arg[i][0] != '-') |
| 119 |
|
i++; |
| 120 |
< |
if (i == na) /* no transform */ |
| 121 |
< |
f->f = f->b = &unitxf; |
| 122 |
< |
else { /* get transform */ |
| 123 |
< |
if ((f->b = (XF *)malloc(sizeof(XF))) == NULL) |
| 120 |
> |
if (i == na) { /* no transform */ |
| 121 |
> |
f->fxp = f->bxp = &unitxf; |
| 122 |
> |
} else { /* get transform */ |
| 123 |
> |
if ((f->bxp = (XF *)malloc(sizeof(XF))) == NULL) |
| 124 |
|
goto memerr; |
| 125 |
< |
if (invxf(f->b, na-i, arg+i) != na-i) |
| 125 |
> |
if (invxf(f->bxp, na-i, arg+i) != na-i) |
| 126 |
|
objerror(m, USER, "bad transform"); |
| 127 |
< |
if (f->b->sca < 0.0) |
| 128 |
< |
f->b->sca = -f->b->sca; |
| 127 |
> |
if (f->bxp->sca < 0.0) |
| 128 |
> |
f->bxp->sca = -f->bxp->sca; |
| 129 |
|
if (dofwd) { /* do both transforms */ |
| 130 |
< |
if ((f->f = (XF *)malloc(sizeof(XF))) == NULL) |
| 130 |
> |
if ((f->fxp = (XF *)malloc(sizeof(XF))) == NULL) |
| 131 |
|
goto memerr; |
| 132 |
< |
xf(f->f, na-i, arg+i); |
| 133 |
< |
if (f->f->sca < 0.0) |
| 134 |
< |
f->f->sca = -f->f->sca; |
| 132 |
> |
xf(f->fxp, na-i, arg+i); |
| 133 |
> |
if (f->fxp->sca < 0.0) |
| 134 |
> |
f->fxp->sca = -f->fxp->sca; |
| 135 |
|
} |
| 136 |
|
} |
| 137 |
|
m->os = (char *)f; |
| 165 |
|
dcleanup(2); /* remove definitions */ |
| 166 |
|
freestr(f->ctx); |
| 167 |
|
} |
| 168 |
< |
if (f->b != &unitxf) |
| 169 |
< |
free((void *)f->b); |
| 170 |
< |
if ((f->f != NULL) & (f->f != &unitxf)) |
| 171 |
< |
free((void *)f->f); |
| 168 |
> |
if (f->bxp != &unitxf) |
| 169 |
> |
free((void *)f->bxp); |
| 170 |
> |
if ((f->fxp != NULL) & (f->fxp != &unitxf)) |
| 171 |
> |
free((void *)f->fxp); |
| 172 |
|
free((void *)f); |
| 173 |
|
m->os = NULL; |
| 174 |
|
} |
| 176 |
|
|
| 177 |
|
int |
| 178 |
|
setfunc( /* set channels for function call */ |
| 179 |
< |
OBJREC *m, /* can be NULL */ |
| 180 |
< |
RAY *r |
| 179 |
> |
OBJREC *m, |
| 180 |
> |
RAY *r |
| 181 |
|
) |
| 182 |
|
{ |
| 183 |
< |
static RNUMBER lastrno = ~0; |
| 184 |
< |
MFUNC *f; |
| 183 |
> |
static RNUMBER lastrno = ~0; |
| 184 |
> |
MFUNC *f; |
| 185 |
|
/* get function if any */ |
| 186 |
< |
if (m != NULL) { |
| 187 |
< |
if ((f = (MFUNC *)m->os) == NULL) |
| 188 |
< |
objerror(m, CONSISTENCY, "setfunc called before getfunc"); |
| 189 |
< |
setcontext(f->ctx); /* set evaluator context */ |
| 181 |
< |
} else |
| 182 |
< |
setcontext(""); |
| 186 |
> |
if ((f = (MFUNC *)m->os) == NULL) |
| 187 |
> |
objerror(m, CONSISTENCY, "setfunc called before getfunc"); |
| 188 |
> |
|
| 189 |
> |
setcontext(f->ctx); /* set evaluator context */ |
| 190 |
|
/* check to see if matrix set */ |
| 191 |
|
if ((m == fobj) & (r->rno == lastrno)) |
| 192 |
|
return(0); |
| 193 |
|
fobj = m; |
| 194 |
|
fray = r; |
| 195 |
< |
if (r->rox != NULL) |
| 196 |
< |
if (f->b != &unitxf) { |
| 197 |
< |
funcxf.sca = r->rox->b.sca * f->b->sca; |
| 198 |
< |
multmat4(funcxf.xfm, r->rox->b.xfm, f->b->xfm); |
| 195 |
> |
if (r->rox != NULL) { |
| 196 |
> |
if (f->bxp != &unitxf) { |
| 197 |
> |
funcxf.sca = r->rox->b.sca * f->bxp->sca; |
| 198 |
> |
multmat4(funcxf.xfm, r->rox->b.xfm, f->bxp->xfm); |
| 199 |
|
} else |
| 200 |
|
funcxf = r->rox->b; |
| 201 |
< |
else |
| 202 |
< |
funcxf = *(f->b); |
| 201 |
> |
} else |
| 202 |
> |
funcxf = *f->bxp; |
| 203 |
|
lastrno = r->rno; |
| 204 |
|
eclock++; /* notify expression evaluator */ |
| 205 |
|
return(1); |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
|
| 209 |
+ |
int |
| 210 |
+ |
worldfunc( /* special function context sans object */ |
| 211 |
+ |
char *ctx, |
| 212 |
+ |
RAY *r |
| 213 |
+ |
) |
| 214 |
+ |
{ |
| 215 |
+ |
static RNUMBER lastrno = ~0; |
| 216 |
+ |
|
| 217 |
+ |
if (rayinitcal[0]) /* initialize on first call */ |
| 218 |
+ |
initfunc(); |
| 219 |
+ |
/* set evaluator context */ |
| 220 |
+ |
setcontext(ctx); |
| 221 |
+ |
/* check if ray already set */ |
| 222 |
+ |
if ((fobj == NULL) & (r->rno == lastrno)) |
| 223 |
+ |
return(0); |
| 224 |
+ |
fobj = NULL; |
| 225 |
+ |
fray = r; |
| 226 |
+ |
funcxf = unitxf; |
| 227 |
+ |
lastrno = r->rno; |
| 228 |
+ |
eclock++; /* notify expression evaluator */ |
| 229 |
+ |
return(1); |
| 230 |
+ |
} |
| 231 |
+ |
|
| 232 |
+ |
|
| 233 |
|
void |
| 234 |
|
loadfunc( /* load definition file */ |
| 235 |
|
char *fname |
| 305 |
|
fray->ron[2]*funcxf.xfm[2][n-3] ) |
| 306 |
|
/ funcxf.sca ); |
| 307 |
|
|
| 308 |
< |
if (n <= 8) /* intersection */ |
| 308 |
> |
if (n <= 8) { /* intersection point */ |
| 309 |
> |
if (fray->rot >= FHUGE) |
| 310 |
> |
return(0.0); /* XXX should be runtime error? */ |
| 311 |
|
|
| 312 |
|
return( fray->rop[0]*funcxf.xfm[0][n-6] + |
| 313 |
|
fray->rop[1]*funcxf.xfm[1][n-6] + |
| 314 |
|
fray->rop[2]*funcxf.xfm[2][n-6] + |
| 315 |
|
funcxf.xfm[3][n-6] ); |
| 316 |
+ |
} |
| 317 |
|
|
| 318 |
|
if (n == 9) /* total distance */ |
| 319 |
|
return(raydist(fray,PRIMARY) * funcxf.sca); |