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); |
81 |
|
if (i == 1 && arg[ff][0] == '.') |
82 |
|
setcontext(f->ctx = ""); /* "." means no file */ |
83 |
|
else { |
84 |
< |
strcpy(sbuf,m->oargs.sarg[ff]); /* file name is context */ |
84 |
> |
strcpy(sbuf,arg[ff]); /* file name is context */ |
85 |
|
if (i > LCALSUF && !strcmp(sbuf+i-LCALSUF, CALSUF)) |
86 |
|
sbuf[i-LCALSUF] = '\0'; /* remove suffix */ |
87 |
|
setcontext(f->ctx = savestr(sbuf)); |
88 |
|
if (!vardefined(REFVNAME)) { /* file loaded? */ |
89 |
< |
loadfunc(m->oargs.sarg[ff]); |
89 |
> |
loadfunc(arg[ff]); |
90 |
|
varset(REFVNAME, '=', 1.0); |
91 |
|
} else /* reference_count++ */ |
92 |
|
varset(REFVNAME, '=', varvalue(REFVNAME)+1.0); |
112 |
|
f->f = f->b = &unitxf; |
113 |
|
else { /* get transform */ |
114 |
|
if ((f->b = (XF *)malloc(sizeof(XF))) == NULL) |
115 |
< |
goto memerr;; |
115 |
> |
goto memerr; |
116 |
|
if (invxf(f->b, na-i, arg+i) != na-i) |
117 |
|
objerror(m, USER, "bad transform"); |
118 |
|
if (f->b->sca < 0.0) |
119 |
|
f->b->sca = -f->b->sca; |
120 |
|
if (dofwd) { /* do both transforms */ |
121 |
|
if ((f->f = (XF *)malloc(sizeof(XF))) == NULL) |
122 |
< |
goto memerr;; |
122 |
> |
goto memerr; |
123 |
|
xf(f->f, na-i, arg+i); |
124 |
|
if (f->f->sca < 0.0) |
125 |
|
f->f->sca = -f->f->sca; |
128 |
|
m->os = (char *)f; |
129 |
|
return(f); |
130 |
|
toofew: |
131 |
< |
objerror(m, USER, "too few arguments"); |
131 |
> |
objerror(m, USER, "too few string arguments"); |
132 |
|
memerr: |
133 |
|
error(SYSTEM, "out of memory in getfunc"); |
134 |
|
} |
166 |
|
OBJREC *m; |
167 |
|
register RAY *r; |
168 |
|
{ |
169 |
< |
static long lastrno = -1; |
169 |
> |
static unsigned long lastrno = ~0; |
170 |
|
register MFUNC *f; |
171 |
|
/* get function */ |
172 |
|
if ((f = (MFUNC *)m->os) == NULL) |
212 |
|
extern double argument(); |
213 |
|
register int n; |
214 |
|
|
215 |
+ |
if (fobj == NULL) |
216 |
+ |
syntax("arg(n) used in constant expression"); |
217 |
+ |
|
218 |
|
n = argument(1) + .5; /* round to integer */ |
219 |
|
|
220 |
|
if (n < 1) |
253 |
|
double sum; |
254 |
|
register RAY *r; |
255 |
|
|
256 |
+ |
if (fray == NULL) |
257 |
+ |
syntax("ray parameter used in constant expression"); |
258 |
+ |
|
259 |
|
if (--n < 0) |
260 |
|
goto badchan; |
261 |
|
|
280 |
|
fray->rop[2]*funcxf.xfm[2][n-6] + |
281 |
|
funcxf.xfm[3][n-6] ); |
282 |
|
|
283 |
< |
if (n == 9) { /* distance */ |
277 |
< |
|
283 |
> |
if (n == 9) { /* total distance */ |
284 |
|
sum = fray->rot; |
285 |
|
for (r = fray->parent; r != NULL; r = r->parent) |
286 |
|
sum += r->rot; |
287 |
|
return(sum * funcxf.sca); |
288 |
|
|
289 |
|
} |
290 |
+ |
|
291 |
|
if (n == 10) /* dot product (range [-1,1]) */ |
292 |
|
return( fray->rod <= -1.0 ? -1.0 : |
293 |
|
fray->rod >= 1.0 ? 1.0 : |
307 |
|
|
308 |
|
if (n < 24) /* k unit vector */ |
309 |
|
return(funcxf.xfm[2][n-21] / funcxf.sca); |
310 |
+ |
|
311 |
+ |
if (n == 24) { /* single ray (shadow) distance */ |
312 |
+ |
sum = fray->rot; |
313 |
+ |
for (r = fray->parent; r != NULL && r->crtype&SHADOW; |
314 |
+ |
r = r->parent) |
315 |
+ |
sum += r->rot; |
316 |
+ |
return(sum * funcxf.sca); |
317 |
+ |
} |
318 |
|
badchan: |
319 |
|
error(USER, "illegal channel number"); |
320 |
|
} |