| 11 |
|
#include "paths.h" |
| 12 |
|
#include "otypes.h" |
| 13 |
|
#include "func.h" |
| 14 |
+ |
#include <ctype.h> |
| 15 |
|
|
| 16 |
|
|
| 17 |
|
#define INITFILE "rayinit.cal" |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
void |
| 40 |
< |
initfunc() /* initialize function evaluation */ |
| 40 |
> |
initfunc(void) /* initialize function evaluation */ |
| 41 |
|
{ |
| 42 |
|
if (!rayinitcal[0]) /* already done? */ |
| 43 |
|
return; |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
|
| 66 |
+ |
/* Set parameters for current evaluation */ |
| 67 |
+ |
void |
| 68 |
+ |
set_eparams(char *prms) |
| 69 |
+ |
{ |
| 70 |
+ |
static char *last_params = NULL; |
| 71 |
+ |
char vname[RMAXWORD]; |
| 72 |
+ |
double value; |
| 73 |
+ |
char *cpd; |
| 74 |
+ |
/* check if already set */ |
| 75 |
+ |
if (prms == NULL || !*prms) |
| 76 |
+ |
return; |
| 77 |
+ |
if (prms == last_params || (last_params != NULL && |
| 78 |
+ |
!strcmp(prms, last_params))) |
| 79 |
+ |
return; |
| 80 |
+ |
last_params = prms; /* XXX assumes static string */ |
| 81 |
+ |
/* assign each variable */ |
| 82 |
+ |
while (*prms) { |
| 83 |
+ |
if (isspace(*prms)) { |
| 84 |
+ |
++prms; continue; |
| 85 |
+ |
} |
| 86 |
+ |
if (!isalpha(*prms)) |
| 87 |
+ |
goto bad_params; |
| 88 |
+ |
cpd = vname; |
| 89 |
+ |
while (*prms && (*prms != '=') & !isspace(*prms)) { |
| 90 |
+ |
if (!isid(*prms) | (cpd-vname >= RMAXWORD-1)) |
| 91 |
+ |
goto bad_params; |
| 92 |
+ |
*cpd++ = *prms++; |
| 93 |
+ |
} |
| 94 |
+ |
*cpd = '\0'; |
| 95 |
+ |
while (isspace(*prms)) prms++; |
| 96 |
+ |
if (*prms++ != '=') |
| 97 |
+ |
goto bad_params; |
| 98 |
+ |
value = atof(prms); |
| 99 |
+ |
if ((prms = fskip(prms)) == NULL) |
| 100 |
+ |
goto bad_params; |
| 101 |
+ |
while (isspace(*prms)) prms++; |
| 102 |
+ |
prms += (*prms == ',') | (*prms == ';') | (*prms == ':'); |
| 103 |
+ |
varset(vname, '=', value); |
| 104 |
+ |
} |
| 105 |
+ |
eclock++; /* notify expression evaluator */ |
| 106 |
+ |
return; |
| 107 |
+ |
bad_params: |
| 108 |
+ |
sprintf(errmsg, "bad parameter list '%s'", last_params); |
| 109 |
+ |
error(USER, errmsg); |
| 110 |
+ |
} |
| 111 |
+ |
|
| 112 |
+ |
|
| 113 |
|
MFUNC * |
| 114 |
|
getfunc( /* get function for this modifier */ |
| 115 |
|
OBJREC *m, |
| 261 |
|
) |
| 262 |
|
{ |
| 263 |
|
static RNUMBER lastrno = ~0; |
| 264 |
+ |
|
| 265 |
+ |
if (rayinitcal[0]) /* initialize on first call */ |
| 266 |
+ |
initfunc(); |
| 267 |
|
/* set evaluator context */ |
| 268 |
|
setcontext(ctx); |
| 269 |
|
/* check if ray already set */ |
| 287 |
|
|
| 288 |
|
if ((ffname = getpath(fname, getrlibpath(), R_OK)) == NULL) { |
| 289 |
|
sprintf(errmsg, "cannot find function file \"%s\"", fname); |
| 290 |
< |
error(USER, errmsg); |
| 290 |
> |
error(SYSTEM, errmsg); |
| 291 |
|
} |
| 292 |
|
fcompile(ffname); |
| 293 |
|
} |
| 299 |
|
int n; |
| 300 |
|
|
| 301 |
|
if (fobj == NULL) |
| 302 |
< |
error(USER, "arg(n) called without a context"); |
| 302 |
> |
error(USER, |
| 303 |
> |
"bad call to arg(n) - illegal constant in .cal file?"); |
| 304 |
|
|
| 305 |
|
n = argument(1) + .5; /* round to integer */ |
| 306 |
|
|
| 354 |
|
fray->ron[2]*funcxf.xfm[2][n-3] ) |
| 355 |
|
/ funcxf.sca ); |
| 356 |
|
|
| 357 |
< |
if (n <= 8) /* intersection */ |
| 357 |
> |
if (n <= 8) { /* intersection point */ |
| 358 |
> |
if (fray->rot >= FHUGE*.99) |
| 359 |
> |
return(0.0); /* XXX should be runtime error? */ |
| 360 |
|
|
| 361 |
|
return( fray->rop[0]*funcxf.xfm[0][n-6] + |
| 362 |
|
fray->rop[1]*funcxf.xfm[1][n-6] + |
| 363 |
|
fray->rop[2]*funcxf.xfm[2][n-6] + |
| 364 |
|
funcxf.xfm[3][n-6] ); |
| 365 |
+ |
} |
| 366 |
|
|
| 367 |
|
if (n == 9) /* total distance */ |
| 368 |
|
return(raydist(fray,PRIMARY) * funcxf.sca); |