1 |
< |
/* Copyright (c) 1990 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
15 |
|
#include "otypes.h" |
16 |
|
|
17 |
|
|
18 |
+ |
#define INITFILE "rayinit.cal" |
19 |
+ |
#define DEFVNAME "FILE_LOADED`" |
20 |
+ |
|
21 |
+ |
XF unitxf = { /* identity transform */ |
22 |
+ |
1.0, 0.0, 0.0, 0.0, |
23 |
+ |
0.0, 1.0, 0.0, 0.0, |
24 |
+ |
0.0, 0.0, 1.0, 0.0, |
25 |
+ |
0.0, 0.0, 0.0, 1.0, |
26 |
+ |
1.0 |
27 |
+ |
}; |
28 |
+ |
|
29 |
|
XF funcxf; /* current transformation */ |
30 |
|
static OBJREC *fobj = NULL; /* current function object */ |
31 |
|
static RAY *fray = NULL; /* current function ray */ |
36 |
|
register RAY *r; |
37 |
|
XF *bx; |
38 |
|
{ |
28 |
– |
extern double l_noise3(), l_noise3a(), l_noise3b(), l_noise3c(); |
29 |
– |
extern double l_hermite(), l_fnoise3(), l_arg(); |
39 |
|
extern long eclock; |
31 |
– |
static char *initfile = "rayinit.cal"; |
40 |
|
static long lastrno = -1; |
41 |
|
/* check to see if already set */ |
42 |
|
if (m == fobj && r->rno == lastrno) |
43 |
< |
return; |
36 |
< |
/* initialize if first call */ |
37 |
< |
if (initfile != NULL) { |
38 |
< |
loadfunc(initfile); |
39 |
< |
scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0); |
40 |
< |
scompile("Nx=$4;Ny=$5;Nz=$6;", NULL, 0); |
41 |
< |
scompile("Px=$7;Py=$8;Pz=$9;", NULL, 0); |
42 |
< |
scompile("T=$10;Rdot=$11;", NULL, 0); |
43 |
< |
scompile("S=$12;Tx=$13;Ty=$14;Tz=$15;", NULL, 0); |
44 |
< |
scompile("Ix=$16;Iy=$17;Iz=$18;", NULL, 0); |
45 |
< |
scompile("Jx=$19;Jy=$20;Jz=$21;", NULL, 0); |
46 |
< |
scompile("Kx=$22;Ky=$23;Kz=$24;", NULL, 0); |
47 |
< |
funset("arg", 1, l_arg); |
48 |
< |
funset("noise3", 3, l_noise3); |
49 |
< |
funset("noise3a", 3, l_noise3a); |
50 |
< |
funset("noise3b", 3, l_noise3b); |
51 |
< |
funset("noise3c", 3, l_noise3c); |
52 |
< |
funset("hermite", 5, l_hermite); |
53 |
< |
funset("fnoise3", 3, l_fnoise3); |
54 |
< |
initfile = NULL; |
55 |
< |
} |
43 |
> |
return(0); |
44 |
|
fobj = m; |
45 |
|
fray = r; |
46 |
< |
lastrno = r->rno; |
47 |
< |
if (r->rox != NULL) { |
48 |
< |
funcxf.sca = r->rox->b.sca * bx->sca; |
49 |
< |
multmat4(funcxf.xfm, r->rox->b.xfm, bx->xfm); |
50 |
< |
} else |
46 |
> |
if (r->rox != NULL) |
47 |
> |
if (bx != &unitxf) { |
48 |
> |
funcxf.sca = r->rox->b.sca * bx->sca; |
49 |
> |
multmat4(funcxf.xfm, r->rox->b.xfm, bx->xfm); |
50 |
> |
} else |
51 |
> |
copystruct(&funcxf, &r->rox->b); |
52 |
> |
else |
53 |
|
copystruct(&funcxf, bx); |
54 |
+ |
lastrno = r->rno; |
55 |
|
eclock++; /* notify expression evaluator */ |
56 |
+ |
return(1); |
57 |
|
} |
58 |
|
|
59 |
|
|
70 |
|
for (n = m->oargs.nsargs, sa = m->oargs.sarg; |
71 |
|
n > 0 && **sa != '-'; n--, sa++) |
72 |
|
; |
73 |
< |
mxf = (XF *)malloc(sizeof(XF)); |
74 |
< |
if (mxf == NULL) |
75 |
< |
goto memerr; |
76 |
< |
if (invxf(mxf, n, sa) != n) |
77 |
< |
objerror(m, USER, "bad transform"); |
78 |
< |
if (mxf->sca < 0.0) |
79 |
< |
mxf->sca = -mxf->sca; |
73 |
> |
if (n == 0) |
74 |
> |
mxf = &unitxf; |
75 |
> |
else { |
76 |
> |
mxf = (XF *)malloc(sizeof(XF)); |
77 |
> |
if (mxf == NULL) |
78 |
> |
goto memerr; |
79 |
> |
if (invxf(mxf, n, sa) != n) |
80 |
> |
objerror(m, USER, "bad transform"); |
81 |
> |
if (mxf->sca < 0.0) |
82 |
> |
mxf->sca = -mxf->sca; |
83 |
> |
} |
84 |
|
m->os = (char *)mxf; |
85 |
|
} |
86 |
< |
setmap(m, r, mxf); |
91 |
< |
return; |
86 |
> |
return(setmap(m, r, mxf)); |
87 |
|
memerr: |
88 |
|
error(SYSTEM, "out of memory in setfunc"); |
89 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
double |
126 |
+ |
l_erf() /* error function */ |
127 |
+ |
{ |
128 |
+ |
extern double erf(); |
129 |
+ |
|
130 |
+ |
return(erf(argument(1))); |
131 |
+ |
} |
132 |
+ |
|
133 |
+ |
|
134 |
+ |
double |
135 |
+ |
l_erfc() /* cumulative error function */ |
136 |
+ |
{ |
137 |
+ |
extern double erfc(); |
138 |
+ |
|
139 |
+ |
return(erfc(argument(1))); |
140 |
+ |
} |
141 |
+ |
|
142 |
+ |
|
143 |
+ |
funcfile(fname) /* set context, load file if necessary */ |
144 |
+ |
char *fname; |
145 |
+ |
{ |
146 |
+ |
extern char *setcontext(); |
147 |
+ |
static char initfile[] = INITFILE; |
148 |
+ |
|
149 |
+ |
if (initfile[0]) { /* initialize on first call */ |
150 |
+ |
setcontext(""); |
151 |
+ |
scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0); |
152 |
+ |
scompile("Nx=$4;Ny=$5;Nz=$6;", NULL, 0); |
153 |
+ |
scompile("Px=$7;Py=$8;Pz=$9;", NULL, 0); |
154 |
+ |
scompile("T=$10;Rdot=$11;", NULL, 0); |
155 |
+ |
scompile("S=$12;Tx=$13;Ty=$14;Tz=$15;", NULL, 0); |
156 |
+ |
scompile("Ix=$16;Iy=$17;Iz=$18;", NULL, 0); |
157 |
+ |
scompile("Jx=$19;Jy=$20;Jz=$21;", NULL, 0); |
158 |
+ |
scompile("Kx=$22;Ky=$23;Kz=$24;", NULL, 0); |
159 |
+ |
funset("arg", 1, '=', l_arg); |
160 |
+ |
funset("erf", 1, ':', l_erf); |
161 |
+ |
funset("erfc", 1, ':', l_erfc); |
162 |
+ |
setnoisefuncs(); |
163 |
+ |
loadfunc(initfile); |
164 |
+ |
initfile[0] = '\0'; |
165 |
+ |
} |
166 |
+ |
setcontext(fname); |
167 |
+ |
if (!vardefined(DEFVNAME)) { |
168 |
+ |
loadfunc(fname); |
169 |
+ |
varset(DEFVNAME, ':', 1.0); |
170 |
+ |
} |
171 |
+ |
} |
172 |
+ |
|
173 |
+ |
|
174 |
+ |
double |
175 |
|
chanvalue(n) /* return channel n to calcomp */ |
176 |
|
register int n; |
177 |
|
{ |
210 |
|
return(sum * funcxf.sca); |
211 |
|
|
212 |
|
} |
213 |
< |
if (n == 10) /* dot product */ |
214 |
< |
return(fray->rod); |
213 |
> |
if (n == 10) /* dot product (range [-1,1]) */ |
214 |
> |
return( fray->rod <= -1.0 ? -1.0 : |
215 |
> |
fray->rod >= 1.0 ? 1.0 : |
216 |
> |
fray->rod ); |
217 |
|
|
218 |
|
if (n == 11) /* scale */ |
219 |
|
return(funcxf.sca); |