ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/func.c
Revision: 1.7
Committed: Thu Oct 5 07:23:22 1989 UTC (34 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.6: +0 -2 lines
Log Message:
Eliminated need to initialize matrix for call to xf() and invxf()

File Contents

# Content
1 /* Copyright (c) 1986 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * func.c - interface to calcomp functions.
9 *
10 * 4/7/86
11 */
12
13 #include "ray.h"
14
15 #include "otypes.h"
16
17
18 typedef struct {
19 double xfm[4][4]; /* transform matrix */
20 double sca; /* scalefactor */
21 } XF;
22
23 static OBJREC *fobj; /* current function object */
24 static RAY *fray; /* current function ray */
25 static XF fxf; /* current transformation */
26
27
28 setmap(m, r, xfm, sca) /* set channels for function call */
29 OBJREC *m;
30 register RAY *r;
31 double xfm[4][4];
32 double sca;
33 {
34 extern double l_noise3(), l_noise3a(), l_noise3b(), l_noise3c();
35 extern double l_hermite(), l_fnoise3(), l_arg();
36 extern long eclock;
37 static char *initfile = "rayinit.cal";
38
39 if (initfile != NULL) {
40 loadfunc(initfile);
41 scompile(NULL, "Dx=$1;Dy=$2;Dz=$3;");
42 scompile(NULL, "Nx=$4;Ny=$5;Nz=$6;");
43 scompile(NULL, "Px=$7;Py=$8;Pz=$9;");
44 scompile(NULL, "T=$10;Rdot=$11;");
45 funset("arg", 1, l_arg);
46 funset("noise3", 3, l_noise3);
47 funset("noise3a", 3, l_noise3a);
48 funset("noise3b", 3, l_noise3b);
49 funset("noise3c", 3, l_noise3c);
50 funset("hermite", 5, l_hermite);
51 funset("fnoise3", 3, l_fnoise3);
52 initfile = NULL;
53 }
54 fobj = m;
55 fray = r;
56 fxf.sca = r->robs * sca;
57 multmat4(fxf.xfm, r->robx, xfm);
58 eclock++; /* notify expression evaluator */
59 }
60
61
62 setfunc(m, r) /* simplified interface to setmap */
63 register OBJREC *m;
64 RAY *r;
65 {
66 register XF *mxf;
67
68 if ((mxf = (XF *)m->os) == NULL) {
69 register int n;
70 register char **sa;
71
72 for (n = m->oargs.nsargs, sa = m->oargs.sarg;
73 n > 0 && **sa != '-'; n--, sa++)
74 ;
75 mxf = (XF *)malloc(sizeof(XF));
76 if (mxf == NULL)
77 goto memerr;
78 if (invxf(mxf->xfm, &mxf->sca, n, sa) != n)
79 objerror(m, USER, "bad transform");
80 if (mxf->sca < 0.0)
81 mxf->sca = -mxf->sca;
82 m->os = (char *)mxf;
83 }
84 setmap(m, r, mxf->xfm, mxf->sca);
85 return;
86 memerr:
87 error(SYSTEM, "out of memory in setfunc");
88 #undef mxf
89 }
90
91
92 loadfunc(fname) /* load definition file */
93 char *fname;
94 {
95 extern char *libpath; /* library search path */
96 char *ffname;
97
98 if ((ffname = getpath(fname, libpath, R_OK)) == NULL) {
99 sprintf(errmsg, "cannot find function file \"%s\"", fname);
100 error(USER, errmsg);
101 }
102 fcompile(ffname);
103 }
104
105
106 double
107 l_arg() /* return nth real argument */
108 {
109 extern double argument();
110 register int n;
111
112 n = argument(1) + .5; /* round to integer */
113
114 if (n < 1)
115 return(fobj->oargs.nfargs);
116
117 if (n > fobj->oargs.nfargs) {
118 sprintf(errmsg, "missing real argument %d", n);
119 objerror(fobj, USER, errmsg);
120 }
121 return(fobj->oargs.farg[n-1]);
122 }
123
124
125 double
126 chanvalue(n) /* return channel n to calcomp */
127 register int n;
128 {
129 double res;
130 register RAY *r;
131
132 n--; /* for convenience */
133
134 if (n < 0 || n > 10)
135 error(USER, "illegal channel number");
136
137 if (n == 9) { /* distance */
138
139 res = fray->rot;
140 for (r = fray->parent; r != NULL; r = r->parent)
141 res += r->rot;
142 res *= fxf.sca;
143
144 } else if (n == 10) { /* dot product */
145
146 res = fray->rod;
147
148 } else if (n < 3) { /* ray direction */
149 res = ( fray->rdir[0]*fxf.xfm[0][n] +
150 fray->rdir[1]*fxf.xfm[1][n] +
151 fray->rdir[2]*fxf.xfm[2][n] )
152 / fxf.sca ;
153 } else if (n < 6) { /* surface normal */
154 res = ( fray->ron[0]*fxf.xfm[0][n-3] +
155 fray->ron[1]*fxf.xfm[1][n-3] +
156 fray->ron[2]*fxf.xfm[2][n-3] )
157 / fxf.sca ;
158 } else { /* intersection */
159 res = fray->rop[0]*fxf.xfm[0][n-6] +
160 fray->rop[1]*fxf.xfm[1][n-6] +
161 fray->rop[2]*fxf.xfm[2][n-6] +
162 fxf.xfm[3][n-6] ;
163 }
164
165 return(res);
166 }