ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/func.c
(Generate patch)

Comparing ray/src/rt/func.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:41:23 1989 UTC vs.
Revision 1.15 by greg, Fri May 24 13:52:10 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 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";
# Line 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #include  "otypes.h"
16  
17  
18 < typedef struct {
19 <        double  sca;                    /* scalefactor */
20 <        double  xfm[4][4];              /* transform matrix */
21 < }  XF;
18 > XF  unitxf = {                  /* identity transform */
19 >        1.0, 0.0, 0.0, 0.0,
20 >        0.0, 1.0, 0.0, 0.0,
21 >        0.0, 0.0, 1.0, 0.0,
22 >        0.0, 0.0, 0.0, 1.0,
23 >        1.0
24 > };
25  
26 < static OBJREC  *fobj;           /* current function object */
27 < static RAY  *fray;              /* current function ray */
28 < static XF  fxf;                 /* current transformation */
26 > XF  funcxf;                     /* current transformation */
27 > static OBJREC  *fobj = NULL;    /* current function object */
28 > static RAY  *fray = NULL;       /* current function ray */
29  
30  
31 < setmap(m, r, sca, xfm)          /* set channels for function call */
31 > setmap(m, r, bx)                /* set channels for function call */
32   OBJREC  *m;
33   register RAY  *r;
34 < double  sca;
32 < double  xfm[4][4];
34 > XF  *bx;
35   {
36 <        extern double  l_noise3(), l_noise3a(), l_noise3b(), l_noise3c();
35 <        extern double  l_hermite(), l_fnoise3(), l_arg();
36 >        extern double  l_arg();
37          extern long  eclock;
38          static char  *initfile = "rayinit.cal";
39 <
39 >                                        /* initialize if first call */
40          if (initfile != NULL) {
41                  loadfunc(initfile);
42 <                scompile(NULL, "Dx=$1;Dy=$2;Dz=$3;");
43 <                scompile(NULL, "Nx=$4;Ny=$5;Nz=$6;");
44 <                scompile(NULL, "Px=$7;Py=$8;Pz=$9;");
45 <                scompile(NULL, "T=$10;Rdot=$11;");
46 <                funset("arg", 1, l_arg);
47 <                funset("noise3", 3, l_noise3);
48 <                funset("noise3a", 3, l_noise3a);
49 <                funset("noise3b", 3, l_noise3b);
50 <                funset("noise3c", 3, l_noise3c);
51 <                funset("hermite", 5, l_hermite);
51 <                funset("fnoise3", 3, l_fnoise3);
42 >                scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0);
43 >                scompile("Nx=$4;Ny=$5;Nz=$6;", NULL, 0);
44 >                scompile("Px=$7;Py=$8;Pz=$9;", NULL, 0);
45 >                scompile("T=$10;Rdot=$11;", NULL, 0);
46 >                scompile("S=$12;Tx=$13;Ty=$14;Tz=$15;", NULL, 0);
47 >                scompile("Ix=$16;Iy=$17;Iz=$18;", NULL, 0);
48 >                scompile("Jx=$19;Jy=$20;Jz=$21;", NULL, 0);
49 >                scompile("Kx=$22;Ky=$23;Kz=$24;", NULL, 0);
50 >                funset("arg", 1, '=', l_arg);
51 >                setnoisefuncs();
52                  initfile = NULL;
53          }
54          fobj = m;
55          fray = r;
56 <        fxf.sca = r->ros * sca;
57 <        multmat4(fxf.xfm, r->rox, xfm);
56 >        if (r->rox != NULL)
57 >                if (bx != &unitxf) {
58 >                        funcxf.sca = r->rox->b.sca * bx->sca;
59 >                        multmat4(funcxf.xfm, r->rox->b.xfm, bx->xfm);
60 >                } else
61 >                        copystruct(&funcxf, &r->rox->b);
62 >        else
63 >                copystruct(&funcxf, bx);
64          eclock++;               /* notify expression evaluator */
65   }
66  
# Line 63 | Line 69 | setfunc(m, r)                          /* simplified interface to setmap */
69   register OBJREC  *m;
70   RAY  *r;
71   {
72 < #define  mxf    ((XF *)m->os)
72 >        register XF  *mxf;
73  
74 <        if (mxf == NULL) {
75 <                register int  n = m->oargs.nsargs;
76 <                register char  **sa = m->oargs.sarg;
74 >        if ((mxf = (XF *)m->os) == NULL) {
75 >                register int  n;
76 >                register char  **sa;
77  
78 <                while (n > 0 && **sa != '-') {
79 <                        n--;
80 <                        sa++;
78 >                for (n = m->oargs.nsargs, sa = m->oargs.sarg;
79 >                                n > 0 && **sa != '-'; n--, sa++)
80 >                        ;
81 >                if (n == 0)
82 >                        mxf = &unitxf;
83 >                else {
84 >                        mxf = (XF *)malloc(sizeof(XF));
85 >                        if (mxf == NULL)
86 >                                goto memerr;
87 >                        if (invxf(mxf, n, sa) != n)
88 >                                objerror(m, USER, "bad transform");
89 >                        if (mxf->sca < 0.0)
90 >                                mxf->sca = -mxf->sca;
91                  }
92 <                mxf = (XF *)malloc(sizeof(XF));
77 <                if (mxf == NULL)
78 <                        goto memerr;
79 <                mxf->sca = 1.0;
80 <                setident4(mxf->xfm);
81 <                if (invxf(mxf->xfm, &mxf->sca, n, sa) != n)
82 <                        objerror(m, USER, "bad transform");
83 <                if (mxf->sca < 0.0)
84 <                        mxf->sca = -mxf->sca;
92 >                m->os = (char *)mxf;
93          }
94 <        setmap(m, r, mxf->sca, mxf->xfm);
94 >        setmap(m, r, mxf);
95          return;
96   memerr:
97          error(SYSTEM, "out of memory in setfunc");
90 #undef  mxf
98   }
99  
100  
# Line 97 | Line 104 | char  *fname;
104          extern char  *libpath;          /* library search path */
105          char  *ffname;
106  
107 <        if ((ffname = getpath(fname, libpath)) == NULL) {
107 >        if ((ffname = getpath(fname, libpath, R_OK)) == NULL) {
108                  sprintf(errmsg, "cannot find function file \"%s\"", fname);
109                  error(USER, errmsg);
110          }
# Line 128 | Line 135 | double
135   chanvalue(n)                    /* return channel n to calcomp */
136   register int  n;
137   {
138 <        double  res;
138 >        double  sum;
139          register RAY  *r;
140  
141 <        n--;                                    /* for convenience */
141 >        if (--n < 0)
142 >                goto badchan;
143  
144 <        if (n < 0 || n > 10)
137 <                error(USER, "illegal channel number");
144 >        if (n < 3)                      /* ray direction */
145  
146 <        if (n == 9) {                           /* distance */
146 >                return( (       fray->rdir[0]*funcxf.xfm[0][n] +
147 >                                fray->rdir[1]*funcxf.xfm[1][n] +
148 >                                fray->rdir[2]*funcxf.xfm[2][n]  )
149 >                         / funcxf.sca );
150  
151 <                res = fray->rot;
142 <                for (r = fray->parent; r != NULL; r = r->parent)
143 <                        res += r->rot;
144 <                res *= fxf.sca;
151 >        if (n < 6)                      /* surface normal */
152  
153 <        } else if (n == 10) {                   /* dot product */
153 >                return( (       fray->ron[0]*funcxf.xfm[0][n-3] +
154 >                                fray->ron[1]*funcxf.xfm[1][n-3] +
155 >                                fray->ron[2]*funcxf.xfm[2][n-3] )
156 >                         / funcxf.sca );
157  
158 <                res = fray->rod;
158 >        if (n < 9)                      /* intersection */
159  
160 <        } else if (n < 3) {                     /* ray direction */
161 <                        res = ( fray->rdir[0]*fxf.xfm[0][n] +
162 <                                        fray->rdir[1]*fxf.xfm[1][n] +
163 <                                        fray->rdir[2]*fxf.xfm[2][n]     )
164 <                                 / fxf.sca ;
165 <        } else if (n < 6) {                     /* surface normal */
166 <                        res = ( fray->ron[0]*fxf.xfm[0][n-3] +
167 <                                        fray->ron[1]*fxf.xfm[1][n-3] +
168 <                                        fray->ron[2]*fxf.xfm[2][n-3]    )
169 <                                 / fxf.sca ;
170 <        } else {                                /* intersection */
171 <                        res =   fray->rop[0]*fxf.xfm[0][n-6] +
162 <                                        fray->rop[1]*fxf.xfm[1][n-6] +
163 <                                        fray->rop[2]*fxf.xfm[2][n-6] +
164 <                                                     fxf.xfm[3][n-6] ;
160 >                return( fray->rop[0]*funcxf.xfm[0][n-6] +
161 >                                fray->rop[1]*funcxf.xfm[1][n-6] +
162 >                                fray->rop[2]*funcxf.xfm[2][n-6] +
163 >                                             funcxf.xfm[3][n-6] );
164 >
165 >        if (n == 9) {                   /* distance */
166 >
167 >                sum = fray->rot;
168 >                for (r = fray->parent; r != NULL; r = r->parent)
169 >                        sum += r->rot;
170 >                return(sum * funcxf.sca);
171 >
172          }
173 +        if (n == 10)                    /* dot product */
174 +                return(fray->rod);
175  
176 <        return(res);
176 >        if (n == 11)                    /* scale */
177 >                return(funcxf.sca);
178 >
179 >        if (n < 15)                     /* origin */
180 >                return(funcxf.xfm[3][n-12]);
181 >
182 >        if (n < 18)                     /* i unit vector */
183 >                return(funcxf.xfm[0][n-15] / funcxf.sca);
184 >
185 >        if (n < 21)                     /* j unit vector */
186 >                return(funcxf.xfm[1][n-15] / funcxf.sca);
187 >
188 >        if (n < 24)                     /* k unit vector */
189 >                return(funcxf.xfm[2][n-21] / funcxf.sca);
190 > badchan:
191 >        error(USER, "illegal channel number");
192   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines