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

Comparing ray/src/rt/t_func.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:41:46 1989 UTC vs.
Revision 2.7 by schorsch, Tue Mar 30 16:13:01 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  t_func.c - routine for procedural textures.
9 *
10 *     4/8/86
6   */
7  
8 + #include "copyright.h"
9 +
10   #include  "ray.h"
11 + #include  "func.h"
12 + #include  "rtotypes.h"
13  
14   /*
15   *      A procedural texture perturbs the surface normal
# Line 28 | Line 27 | static char SCCSid[] = "$SunId$ LBL";
27   *  from the original coordinates to the current coordinates.
28   */
29  
31 typedef struct {
32        struct {
33                double  sca;            /* scale factor */
34                double  xfm[4][4];      /* transformation matrix */
35        }  fore, back;
36 }  XFORM;
30  
31 <
32 < t_func(m, r)                    /* compute texture for ray */
33 < register OBJREC  *m;
34 < register RAY  *r;
31 > extern int
32 > t_func(                 /* compute texture for ray */
33 >        register OBJREC  *m,
34 >        register RAY  *r
35 > )
36   {
43 #define  mxf    ((XFORM *)m->os)
44        extern double  varvalue();
45        extern int  errno;
37          FVECT  disp;
38 +        double  d;
39 +        register MFUNC  *mf;
40          register int  i;
48        register char  **sa;
41  
42          if (m->oargs.nsargs < 4)
43                  objerror(m, USER, "bad # arguments");
44 <        sa = m->oargs.sarg;
45 <
54 <        if (mxf == NULL) {
55 <                mxf = (XFORM *)malloc(sizeof(XFORM));
56 <                if (mxf == NULL)
57 <                        goto memerr;
58 <                mxf->fore.sca = 1.0;
59 <                setident4(mxf->fore.xfm);
60 <                if (xf(mxf->fore.xfm, &mxf->fore.sca,
61 <                        m->oargs.nsargs-4, sa+4) != m->oargs.nsargs-4)
62 <                        objerror(m, USER, "bad transform");
63 <                if (mxf->fore.sca < 0.0)
64 <                        mxf->fore.sca = -mxf->fore.sca;
65 <                mxf->back.sca = 1.0;
66 <                setident4(mxf->back.xfm);
67 <                invxf(mxf->back.xfm, &mxf->back.sca,
68 <                                m->oargs.nsargs-4, sa+4);
69 <                if (mxf->back.sca < 0.0)
70 <                        mxf->back.sca = -mxf->back.sca;
71 <        }
72 <
73 <        setmap(m, r, mxf->back.sca, mxf->back.xfm);
74 <
75 <        if (!vardefined(sa[0]))
76 <                loadfunc(sa[3]);
44 >        mf = getfunc(m, 3, 0x7, 1);
45 >        setfunc(m, r);
46          errno = 0;
47 <        for (i = 0; i < 3; i++)
48 <                disp[i] = varvalue(sa[i]);
49 <        if (errno) {
50 <                objerror(m, WARNING, "compute error");
51 <                return;
47 >        for (i = 0; i < 3; i++) {
48 >                disp[i] = evalue(mf->ep[i]);
49 >                if (errno == EDOM || errno == ERANGE) {
50 >                        objerror(m, WARNING, "compute error");
51 >                        return(0);
52 >                }
53          }
54 <        if (mxf->fore.xfm == NULL)
55 <                for (i = 0; i < 3; i++)
56 <                        r->pert[i] += disp[i];
57 <        else
58 <                for (i = 0; i < 3; i++)
59 <                        r->pert[i] += ( disp[0]*mxf->fore.xfm[0][i] +
60 <                                        disp[1]*mxf->fore.xfm[1][i] +
61 <                                        disp[2]*mxf->fore.xfm[2][i] )
62 <                                                / mxf->fore.sca;
63 <        return;
94 < memerr:
95 <        error(SYSTEM, "out of memory in t_func");
96 < #undef  mxf
54 >        if (mf->f != &unitxf)
55 >                multv3(disp, disp, mf->f->xfm);
56 >        if (r->rox != NULL) {
57 >                multv3(disp, disp, r->rox->f.xfm);
58 >                d = 1.0 / (mf->f->sca * r->rox->f.sca);
59 >        } else
60 >                d = 1.0 / mf->f->sca;
61 >        for (i = 0; i < 3; i++)
62 >                r->pert[i] += disp[i] * d;
63 >        return(0);
64   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines