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

Comparing ray/src/rt/func.c (file contents):
Revision 2.41 by greg, Mon Sep 16 17:31:14 2024 UTC vs.
Revision 2.46 by greg, Sat Dec 6 04:13:14 2025 UTC

# Line 60 | Line 60 | initfunc(void) /* initialize function evaluation */
60          setprismfuncs();
61          loadfunc(rayinitcal);
62          rayinitcal[0] = '\0';
63 +        doptimize(1);           /* optimize definitions */
64   }
65  
66  
67   /* Set parameters for current evaluation */
68   void
69 < set_eparams(char *prms)
69 > set_eparams(const char *prms)
70   {
71 <        static char     *last_params = NULL;
72 <        char            vname[RMAXWORD];
73 <        double          value;
74 <        char            *cpd;
71 >        static const char       *last_params = NULL;
72 >        char                    vname[RMAXWORD];
73 >        double                  value;
74 >        char                    *cpd;
75                                          /* check if already set */
76          if (prms == NULL || !*prms)
77                  return;
# Line 96 | Line 97 | set_eparams(char *prms)
97                  if (*prms++ != '=')
98                          goto bad_params;
99                  value = atof(prms);
100 <                if ((prms = fskip(prms)) == NULL)
100 >                if ((prms = fskip((char *)prms)) == NULL)
101                          goto bad_params;
102                  while (isspace(*prms)) prms++;
103                  prms += (*prms == ',') | (*prms == ';') | (*prms == ':');
# Line 127 | Line 128 | getfunc(       /* get function for this modifier */
128          if ((f = (MFUNC *)m->os) != NULL)
129                  return(f);
130          fobj = NULL; fray = NULL;
130        if (rayinitcal[0])              /* initialize on first call */
131                initfunc();
131          if ((na = m->oargs.nsargs) <= ff)
132                  goto toofew;
133          arg = m->oargs.sarg;
# Line 163 | Line 162 | getfunc(       /* get function for this modifier */
162                  goto toofew;
163          if (i <= ff)                    /* find transform args */
164                  i = ff+1;
165 <        while (i < na && arg[i][0] != '-')
165 >        while (i < na && !isxfopt(arg[i]))
166                  i++;
167          if (i == na) {                  /* no transform */
168                  f->fxp = f->bxp = &unitxf;
# Line 256 | Line 255 | setfunc(                       /* set channels for function call */
255  
256   int
257   worldfunc(                      /* special function context sans object */
258 <        char    *ctx,
258 >        const char      *ctx,
259          RAY     *r
260   )
261   {
262          static RNUMBER  lastrno = ~0;
264
265        if (rayinitcal[0])              /* initialize on first call */
266                initfunc();
263                                          /* set evaluator context */
264 <        calcontext(ctx);
264 >        calcontext((char *)ctx);
265                                          /* check if ray already set */
266          if ((fobj == NULL) & (r->rno == lastrno))
267                  return(0);
# Line 290 | Line 286 | loadfunc(                      /* load definition file */
286                  error(SYSTEM, errmsg);
287          }
288          fcompile(ffname);
293        doptimize(1);           /* optimize definitions */
289   }
290  
291  
# Line 341 | Line 336 | chanvalue(                     /* return channel n to calcomp */
336          if (--n < 0)
337                  goto badchan;
338  
339 <        if (n <= 2)                     /* ray direction */
339 >        if (n < 3)                      /* ray direction */
340  
341                  return( (       fray->rdir[0]*funcxf.xfm[0][n] +
342                                  fray->rdir[1]*funcxf.xfm[1][n] +
343                                  fray->rdir[2]*funcxf.xfm[2][n]  )
344                           / funcxf.sca );
345  
346 <        if (n <= 5)                     /* surface normal */
346 >        if (n < 6)                      /* surface normal */
347  
348                  return( (       fray->ron[0]*funcxf.xfm[0][n-3] +
349                                  fray->ron[1]*funcxf.xfm[1][n-3] +
350                                  fray->ron[2]*funcxf.xfm[2][n-3] )
351                           / funcxf.sca );
352  
353 <        if (n <= 8) {                   /* intersection point */
359 <                if (fray->rot >= FHUGE*.99)
360 <                        return(0.0);    /* XXX should be runtime error? */
353 >        if (n < 9)                      /* intersection point */
354  
355                  return( fray->rop[0]*funcxf.xfm[0][n-6] +
356                                  fray->rop[1]*funcxf.xfm[1][n-6] +
357                                  fray->rop[2]*funcxf.xfm[2][n-6] +
358                                               funcxf.xfm[3][n-6] );
366        }
359  
360          if (n == 9)                     /* total distance */
361                  return(raydist(fray,PRIMARY) * funcxf.sca);
# Line 376 | Line 368 | chanvalue(                     /* return channel n to calcomp */
368          if (n == 11)                    /* scale */
369                  return(funcxf.sca);
370  
371 <        if (n <= 14)                    /* origin */
371 >        if (n < 15)                     /* origin */
372                  return(funcxf.xfm[3][n-12]);
373  
374 <        if (n <= 17)                    /* i unit vector */
374 >        if (n < 18)                     /* i unit vector */
375                  return(funcxf.xfm[0][n-15] / funcxf.sca);
376  
377 <        if (n <= 20)                    /* j unit vector */
377 >        if (n < 21)                     /* j unit vector */
378                  return(funcxf.xfm[1][n-18] / funcxf.sca);
379  
380 <        if (n <= 23)                    /* k unit vector */
380 >        if (n < 24)                     /* k unit vector */
381                  return(funcxf.xfm[2][n-21] / funcxf.sca);
382  
383          if (n == 24)                    /* single ray (shadow) distance */
384                  return((fray->rot+raydist(fray->parent,SHADOW)) * funcxf.sca);
385  
386 <        if (n <= 26)                    /* local (u,v) coordinates */
386 >        if (n < 27)                     /* local (u,v) coordinates */
387                  return(fray->uv[n-25]);
388   badchan:
389          error(USER, "illegal channel number");

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)