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.3 by greg, Wed Jan 12 16:46:54 1994 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 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include  "ray.h"
14  
15 + #include  "func.h"
16 +
17   /*
18   *      A procedural texture perturbs the surface normal
19   *  at the point of intersection with an object.  It has
# Line 28 | Line 30 | static char SCCSid[] = "$SunId$ LBL";
30   *  from the original coordinates to the current coordinates.
31   */
32  
31 typedef struct {
32        struct {
33                double  sca;            /* scale factor */
34                double  xfm[4][4];      /* transformation matrix */
35        }  fore, back;
36 }  XFORM;
33  
38
34   t_func(m, r)                    /* compute texture for ray */
35   register OBJREC  *m;
36   register RAY  *r;
37   {
43 #define  mxf    ((XFORM *)m->os)
44        extern double  varvalue();
45        extern int  errno;
38          FVECT  disp;
39 +        double  d;
40 +        register MFUNC  *mf;
41          register int  i;
48        register char  **sa;
42  
43          if (m->oargs.nsargs < 4)
44                  objerror(m, USER, "bad # arguments");
45 <        sa = m->oargs.sarg;
46 <
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]);
45 >        mf = getfunc(m, 3, 0x7, 1);
46 >        setfunc(m, r);
47          errno = 0;
48 <        for (i = 0; i < 3; i++)
49 <                disp[i] = varvalue(sa[i]);
50 <        if (errno) {
51 <                objerror(m, WARNING, "compute error");
52 <                return;
48 >        for (i = 0; i < 3; i++) {
49 >                disp[i] = evalue(mf->ep[i]);
50 >                if (errno) {
51 >                        objerror(m, WARNING, "compute error");
52 >                        return(0);
53 >                }
54          }
55 <        if (mxf->fore.xfm == NULL)
56 <                for (i = 0; i < 3; i++)
57 <                        r->pert[i] += disp[i];
58 <        else
59 <                for (i = 0; i < 3; i++)
60 <                        r->pert[i] += ( disp[0]*mxf->fore.xfm[0][i] +
61 <                                        disp[1]*mxf->fore.xfm[1][i] +
62 <                                        disp[2]*mxf->fore.xfm[2][i] )
63 <                                                / mxf->fore.sca;
64 <        return;
94 < memerr:
95 <        error(SYSTEM, "out of memory in t_func");
96 < #undef  mxf
55 >        if (mf->f != &unitxf)
56 >                multv3(disp, disp, mf->f->xfm);
57 >        if (r->rox != NULL) {
58 >                multv3(disp, disp, r->rox->f.xfm);
59 >                d = 1.0 / (mf->f->sca * r->rox->f.sca);
60 >        } else
61 >                d = 1.0 / mf->f->sca;
62 >        for (i = 0; i < 3; i++)
63 >                r->pert[i] += disp[i] * d;
64 >        return(0);
65   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines