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 2.2 by greg, Mon Nov 25 09:51:00 1991 UTC vs.
Revision 2.12 by greg, Thu Apr 14 04:50:29 1994 UTC

# Line 1 | Line 1
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";
# Line 18 | Line 18 | 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  
# Line 54 | Line 54 | int  dofwd;
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);
# Line 68 | Line 69 | int  dofwd;
69                  funset("erf", 1, ':', l_erf);
70                  funset("erfc", 1, ':', l_erfc);
71                  setnoisefuncs();
72 +                setprismfuncs();
73                  loadfunc(initfile);
74                  initfile[0] = '\0';
75          }
# Line 80 | Line 82 | int  dofwd;
82          if (i == 1 && arg[ff][0] == '.')
83                  setcontext(f->ctx = "");        /* "." means no file */
84          else {
85 <                strcpy(sbuf,m->oargs.sarg[ff]); /* file name is context */
85 >                strcpy(sbuf,arg[ff]);   /* file name is context */
86                  if (i > LCALSUF && !strcmp(sbuf+i-LCALSUF, CALSUF))
87                          sbuf[i-LCALSUF] = '\0'; /* remove suffix */
88                  setcontext(f->ctx = savestr(sbuf));
89                  if (!vardefined(REFVNAME)) {    /* file loaded? */
90 <                        loadfunc(m->oargs.sarg[ff]);
90 >                        loadfunc(arg[ff]);
91                          varset(REFVNAME, '=', 1.0);
92                  } else                          /* reference_count++ */
93                          varset(REFVNAME, '=', varvalue(REFVNAME)+1.0);
# Line 111 | Line 113 | int  dofwd;
113                  f->f = f->b = &unitxf;
114          else {                          /* get transform */
115                  if ((f->b = (XF *)malloc(sizeof(XF))) == NULL)
116 <                        goto memerr;;
116 >                        goto memerr;
117                  if (invxf(f->b, na-i, arg+i) != na-i)
118                          objerror(m, USER, "bad transform");
119                  if (f->b->sca < 0.0)
120                          f->b->sca = -f->b->sca;
121                  if (dofwd) {                    /* do both transforms */
122                          if ((f->f = (XF *)malloc(sizeof(XF))) == NULL)
123 <                                goto memerr;;
123 >                                goto memerr;
124                          xf(f->f, na-i, arg+i);
125                          if (f->f->sca < 0.0)
126                                  f->f->sca = -f->f->sca;
# Line 127 | Line 129 | int  dofwd;
129          m->os = (char *)f;
130          return(f);
131   toofew:
132 <        objerror(m, USER, "too few arguments");
132 >        objerror(m, USER, "too few string arguments");
133   memerr:
134          error(SYSTEM, "out of memory in getfunc");
135   }
# Line 165 | Line 167 | setfunc(m, r)                  /* set channels for function call */
167   OBJREC  *m;
168   register RAY  *r;
169   {
170 <        static long  lastrno = -1;
170 >        static unsigned long  lastrno = ~0;
171          register MFUNC  *f;
172                                          /* get function */
173          if ((f = (MFUNC *)m->os) == NULL)
# Line 194 | Line 196 | register RAY  *r;
196   loadfunc(fname)                 /* load definition file */
197   char  *fname;
198   {
199 <        extern char  *libpath;          /* library search path */
199 >        extern char  *getlibpath();     /* library search path */
200          char  *ffname;
201  
202 <        if ((ffname = getpath(fname, libpath, R_OK)) == NULL) {
202 >        if ((ffname = getpath(fname, getlibpath(), R_OK)) == NULL) {
203                  sprintf(errmsg, "cannot find function file \"%s\"", fname);
204                  error(USER, errmsg);
205          }
# Line 211 | Line 213 | l_arg()                                /* return nth real argument */
213          extern double  argument();
214          register int  n;
215  
216 +        if (fobj == NULL)
217 +                syntax("arg(n) used in constant expression");
218 +
219          n = argument(1) + .5;           /* round to integer */
220  
221          if (n < 1)
# Line 249 | Line 254 | register int  n;
254          double  sum;
255          register RAY  *r;
256  
257 +        if (fray == NULL)
258 +                syntax("ray parameter used in constant expression");
259 +
260          if (--n < 0)
261                  goto badchan;
262  
# Line 273 | Line 281 | register int  n;
281                                  fray->rop[2]*funcxf.xfm[2][n-6] +
282                                               funcxf.xfm[3][n-6] );
283  
284 <        if (n == 9) {                   /* distance */
277 <
284 >        if (n == 9) {                   /* total distance */
285                  sum = fray->rot;
286                  for (r = fray->parent; r != NULL; r = r->parent)
287                          sum += r->rot;
288                  return(sum * funcxf.sca);
289  
290          }
291 +
292          if (n == 10)                    /* dot product (range [-1,1]) */
293                  return( fray->rod <= -1.0 ? -1.0 :
294                          fray->rod >= 1.0 ? 1.0 :
# Line 300 | Line 308 | register int  n;
308  
309          if (n < 24)                     /* k unit vector */
310                  return(funcxf.xfm[2][n-21] / funcxf.sca);
311 +
312 +        if (n == 24) {                  /* single ray (shadow) distance */
313 +                sum = fray->rot;
314 +                for (r = fray->parent; r != NULL && r->crtype&SHADOW;
315 +                                r = r->parent)
316 +                        sum += r->rot;
317 +                return(sum * funcxf.sca);
318 +        }
319   badchan:
320          error(USER, "illegal channel number");
321   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines