1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
18 |
|
|
19 |
|
|
20 |
|
#define INITFILE "rayinit.cal" |
21 |
– |
#define REFVNAME "`FILE_REFCNT" |
21 |
|
#define CALSUF ".cal" |
22 |
|
#define LCALSUF 4 |
23 |
+ |
char REFVNAME[] = "`FILE_REFCNT"; |
24 |
|
|
25 |
|
XF unitxf = { /* identity transform */ |
26 |
< |
1.0, 0.0, 0.0, 0.0, |
27 |
< |
0.0, 1.0, 0.0, 0.0, |
28 |
< |
0.0, 0.0, 1.0, 0.0, |
29 |
< |
0.0, 0.0, 0.0, 1.0, |
26 |
> |
{{1.0, 0.0, 0.0, 0.0}, |
27 |
> |
{0.0, 1.0, 0.0, 0.0}, |
28 |
> |
{0.0, 0.0, 1.0, 0.0}, |
29 |
> |
{0.0, 0.0, 0.0, 1.0}}, |
30 |
|
1.0 |
31 |
|
}; |
32 |
|
|
54 |
|
/* check to see if done already */ |
55 |
|
if ((f = (MFUNC *)m->os) != NULL) |
56 |
|
return(f); |
57 |
+ |
fobj = NULL; fray = NULL; |
58 |
|
if (initfile[0]) { /* initialize on first call */ |
59 |
|
setcontext(""); |
60 |
|
scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0); |
61 |
|
scompile("Nx=$4;Ny=$5;Nz=$6;", NULL, 0); |
62 |
|
scompile("Px=$7;Py=$8;Pz=$9;", NULL, 0); |
63 |
< |
scompile("T=$10;Rdot=$11;", NULL, 0); |
63 |
> |
scompile("T=$10;Ts=$25;Rdot=$11;", NULL, 0); |
64 |
|
scompile("S=$12;Tx=$13;Ty=$14;Tz=$15;", NULL, 0); |
65 |
|
scompile("Ix=$16;Iy=$17;Iz=$18;", NULL, 0); |
66 |
|
scompile("Jx=$19;Jy=$20;Jz=$21;", NULL, 0); |
69 |
|
funset("erf", 1, ':', l_erf); |
70 |
|
funset("erfc", 1, ':', l_erfc); |
71 |
|
setnoisefuncs(); |
72 |
+ |
setprismfuncs(); |
73 |
|
loadfunc(initfile); |
74 |
|
initfile[0] = '\0'; |
75 |
|
} |
82 |
|
if (i == 1 && arg[ff][0] == '.') |
83 |
|
setcontext(f->ctx = ""); /* "." means no file */ |
84 |
|
else { |
85 |
< |
strcpy(sbuf,m->oargs.sarg[ff]); /* file name is context */ |
85 |
> |
strcpy(sbuf,arg[ff]); /* file name is context */ |
86 |
|
if (i > LCALSUF && !strcmp(sbuf+i-LCALSUF, CALSUF)) |
87 |
|
sbuf[i-LCALSUF] = '\0'; /* remove suffix */ |
88 |
|
setcontext(f->ctx = savestr(sbuf)); |
89 |
|
if (!vardefined(REFVNAME)) { /* file loaded? */ |
90 |
< |
loadfunc(m->oargs.sarg[ff]); |
90 |
> |
loadfunc(arg[ff]); |
91 |
|
varset(REFVNAME, '=', 1.0); |
92 |
|
} else /* reference_count++ */ |
93 |
|
varset(REFVNAME, '=', varvalue(REFVNAME)+1.0); |
129 |
|
m->os = (char *)f; |
130 |
|
return(f); |
131 |
|
toofew: |
132 |
< |
objerror(m, USER, "too few arguments"); |
132 |
> |
objerror(m, USER, "too few string arguments"); |
133 |
|
memerr: |
134 |
|
error(SYSTEM, "out of memory in getfunc"); |
135 |
|
} |
167 |
|
OBJREC *m; |
168 |
|
register RAY *r; |
169 |
|
{ |
170 |
< |
static long lastrno = -1; |
170 |
> |
static unsigned long lastrno = ~0; |
171 |
|
register MFUNC *f; |
172 |
|
/* get function */ |
173 |
|
if ((f = (MFUNC *)m->os) == NULL) |
213 |
|
extern double argument(); |
214 |
|
register int n; |
215 |
|
|
216 |
+ |
if (fobj == NULL) |
217 |
+ |
syntax("arg(n) used in constant expression"); |
218 |
+ |
|
219 |
|
n = argument(1) + .5; /* round to integer */ |
220 |
|
|
221 |
|
if (n < 1) |
254 |
|
double sum; |
255 |
|
register RAY *r; |
256 |
|
|
257 |
+ |
if (fray == NULL) |
258 |
+ |
syntax("ray parameter used in constant expression"); |
259 |
+ |
|
260 |
|
if (--n < 0) |
261 |
|
goto badchan; |
262 |
|
|
281 |
|
fray->rop[2]*funcxf.xfm[2][n-6] + |
282 |
|
funcxf.xfm[3][n-6] ); |
283 |
|
|
284 |
< |
if (n == 9) { /* distance */ |
277 |
< |
|
284 |
> |
if (n == 9) { /* total distance */ |
285 |
|
sum = fray->rot; |
286 |
|
for (r = fray->parent; r != NULL; r = r->parent) |
287 |
|
sum += r->rot; |
288 |
|
return(sum * funcxf.sca); |
289 |
|
|
290 |
|
} |
291 |
+ |
|
292 |
|
if (n == 10) /* dot product (range [-1,1]) */ |
293 |
|
return( fray->rod <= -1.0 ? -1.0 : |
294 |
|
fray->rod >= 1.0 ? 1.0 : |
308 |
|
|
309 |
|
if (n < 24) /* k unit vector */ |
310 |
|
return(funcxf.xfm[2][n-21] / funcxf.sca); |
311 |
+ |
|
312 |
+ |
if (n == 24) { /* single ray (shadow) distance */ |
313 |
+ |
sum = fray->rot; |
314 |
+ |
for (r = fray->parent; r != NULL && r->crtype&SHADOW; |
315 |
+ |
r = r->parent) |
316 |
+ |
sum += r->rot; |
317 |
+ |
return(sum * funcxf.sca); |
318 |
+ |
} |
319 |
|
badchan: |
320 |
|
error(USER, "illegal channel number"); |
321 |
|
} |