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.11 by greg, Wed Dec 12 21:57:50 1990 UTC vs.
Revision 1.14 by greg, Tue Apr 23 15:46:22 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  xfm[4][4];              /* transform matrix */
20 <        double  sca;                    /* scalefactor */
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, xfm, sca)          /* set channels for function call */
31 > setmap(m, r, bx)                /* set channels for function call */
32   OBJREC  *m;
33   register RAY  *r;
34 < double  xfm[4][4];
32 < double  sca;
34 > XF  *bx;
35   {
36          extern double  l_noise3(), l_noise3a(), l_noise3b(), l_noise3c();
37          extern double  l_hermite(), l_fnoise3(), l_arg();
38          extern long  eclock;
39          static char  *initfile = "rayinit.cal";
40 <
40 >                                        /* initialize if first call */
41          if (initfile != NULL) {
42                  loadfunc(initfile);
43                  scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0);
# Line 46 | Line 48 | double  sca;
48                  scompile("Ix=$16;Iy=$17;Iz=$18;", NULL, 0);
49                  scompile("Jx=$19;Jy=$20;Jz=$21;", NULL, 0);
50                  scompile("Kx=$22;Ky=$23;Kz=$24;", NULL, 0);
51 <                funset("arg", 1, l_arg);
52 <                funset("noise3", 3, l_noise3);
53 <                funset("noise3a", 3, l_noise3a);
54 <                funset("noise3b", 3, l_noise3b);
55 <                funset("noise3c", 3, l_noise3c);
56 <                funset("hermite", 5, l_hermite);
57 <                funset("fnoise3", 3, l_fnoise3);
51 >                funset("arg", 1, '=', l_arg);
52 >                funset("noise3", 3, ':', l_noise3);
53 >                funset("noise3a", 3, ':', l_noise3a);
54 >                funset("noise3b", 3, ':', l_noise3b);
55 >                funset("noise3c", 3, ':', l_noise3c);
56 >                funset("hermite", 5, ':', l_hermite);
57 >                funset("fnoise3", 3, ':', l_fnoise3);
58                  initfile = NULL;
59          }
60          fobj = m;
61          fray = r;
62 <        fxf.sca = r->robs * sca;
63 <        multmat4(fxf.xfm, r->robx, xfm);
62 >        if (r->rox != NULL)
63 >                if (bx != &unitxf) {
64 >                        funcxf.sca = r->rox->b.sca * bx->sca;
65 >                        multmat4(funcxf.xfm, r->rox->b.xfm, bx->xfm);
66 >                } else
67 >                        copystruct(&funcxf, &r->rox->b);
68 >        else
69 >                copystruct(&funcxf, bx);
70          eclock++;               /* notify expression evaluator */
71   }
72  
# Line 76 | Line 84 | RAY  *r;
84                  for (n = m->oargs.nsargs, sa = m->oargs.sarg;
85                                  n > 0 && **sa != '-'; n--, sa++)
86                          ;
87 <                mxf = (XF *)malloc(sizeof(XF));
88 <                if (mxf == NULL)
89 <                        goto memerr;
90 <                if (invxf(mxf->xfm, &mxf->sca, n, sa) != n)
91 <                        objerror(m, USER, "bad transform");
92 <                if (mxf->sca < 0.0)
93 <                        mxf->sca = -mxf->sca;
87 >                if (n == 0)
88 >                        mxf = &unitxf;
89 >                else {
90 >                        mxf = (XF *)malloc(sizeof(XF));
91 >                        if (mxf == NULL)
92 >                                goto memerr;
93 >                        if (invxf(mxf, n, sa) != n)
94 >                                objerror(m, USER, "bad transform");
95 >                        if (mxf->sca < 0.0)
96 >                                mxf->sca = -mxf->sca;
97 >                }
98                  m->os = (char *)mxf;
99          }
100 <        setmap(m, r, mxf->xfm, mxf->sca);
100 >        setmap(m, r, mxf);
101          return;
102   memerr:
103          error(SYSTEM, "out of memory in setfunc");
# Line 137 | Line 149 | register int  n;
149  
150          if (n < 3)                      /* ray direction */
151  
152 <                return( (       fray->rdir[0]*fxf.xfm[0][n] +
153 <                                fray->rdir[1]*fxf.xfm[1][n] +
154 <                                fray->rdir[2]*fxf.xfm[2][n]     )
155 <                         / fxf.sca );
152 >                return( (       fray->rdir[0]*funcxf.xfm[0][n] +
153 >                                fray->rdir[1]*funcxf.xfm[1][n] +
154 >                                fray->rdir[2]*funcxf.xfm[2][n]  )
155 >                         / funcxf.sca );
156  
157          if (n < 6)                      /* surface normal */
158  
159 <                return( (       fray->ron[0]*fxf.xfm[0][n-3] +
160 <                                fray->ron[1]*fxf.xfm[1][n-3] +
161 <                                fray->ron[2]*fxf.xfm[2][n-3]    )
162 <                         / fxf.sca );
159 >                return( (       fray->ron[0]*funcxf.xfm[0][n-3] +
160 >                                fray->ron[1]*funcxf.xfm[1][n-3] +
161 >                                fray->ron[2]*funcxf.xfm[2][n-3] )
162 >                         / funcxf.sca );
163  
164          if (n < 9)                      /* intersection */
165  
166 <                return( fray->rop[0]*fxf.xfm[0][n-6] +
167 <                                fray->rop[1]*fxf.xfm[1][n-6] +
168 <                                fray->rop[2]*fxf.xfm[2][n-6] +
169 <                                             fxf.xfm[3][n-6] );
166 >                return( fray->rop[0]*funcxf.xfm[0][n-6] +
167 >                                fray->rop[1]*funcxf.xfm[1][n-6] +
168 >                                fray->rop[2]*funcxf.xfm[2][n-6] +
169 >                                             funcxf.xfm[3][n-6] );
170  
171          if (n == 9) {                   /* distance */
172  
173                  sum = fray->rot;
174                  for (r = fray->parent; r != NULL; r = r->parent)
175                          sum += r->rot;
176 <                return(sum * fxf.sca);
176 >                return(sum * funcxf.sca);
177  
178          }
179          if (n == 10)                    /* dot product */
180                  return(fray->rod);
181  
182          if (n == 11)                    /* scale */
183 <                return(fxf.sca);
183 >                return(funcxf.sca);
184  
185          if (n < 15)                     /* origin */
186 <                return(fxf.xfm[3][n-12]);
186 >                return(funcxf.xfm[3][n-12]);
187  
188          if (n < 18)                     /* i unit vector */
189 <                return(fxf.xfm[0][n-15] / fxf.sca);
189 >                return(funcxf.xfm[0][n-15] / funcxf.sca);
190  
191          if (n < 21)                     /* j unit vector */
192 <                return(fxf.xfm[1][n-15] / fxf.sca);
192 >                return(funcxf.xfm[1][n-15] / funcxf.sca);
193  
194          if (n < 24)                     /* k unit vector */
195 <                return(fxf.xfm[2][n-21] / fxf.sca);
195 >                return(funcxf.xfm[2][n-21] / funcxf.sca);
196   badchan:
197          error(USER, "illegal channel number");
198   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines