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

Comparing ray/src/rt/m_direct.c (file contents):
Revision 2.1 by greg, Tue Nov 12 17:10:36 1991 UTC vs.
Revision 2.6 by greg, Thu Sep 7 12:35:21 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1994 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  
16   #include  "source.h"
17  
18 + #include  "func.h"
19 +
20   /*
21   * The arguments for MAT_DIRECT1 are:
22   *
# Line 30 | Line 32 | static char SCCSid[] = "$SunId$ LBL";
32   */
33  
34  
33 extern double  varvalue();
34
35   int  dir_proj();
36   VSMATERIAL  direct1_vs = {dir_proj, 1};
37   VSMATERIAL  direct2_vs = {dir_proj, 2};
38  
39 < #define fndx(m)         ((m)->otype == MAT_DIRECT1 ? 4 : 8)
39 > #define getdfunc(m)     ( (m)->otype == MAT_DIRECT1 ? \
40 >                                getfunc(m, 4, 0xf, 1) : \
41 >                                getfunc(m, 8, 0xff, 1) )
42  
43  
42 static
43 dir_check(m)                    /* check arguments and load function file */
44 register OBJREC  *m;
45 {
46        register FULLXF  *mxf;
47        register int  ff;
48
49        ff = fndx(m)+1;
50        if (ff > m->oargs.nsargs)
51                objerror(m, USER, "too few arguments");
52        if (m->os == NULL) {
53                mxf = (FULLXF *)malloc(sizeof(FULLXF));
54                if (mxf == NULL)
55                        error(SYSTEM, "out of memory in dir_check");
56                if (fullxf(mxf, m->oargs.nsargs-ff, m->oargs.sarg+ff) !=
57                                m->oargs.nsargs-ff)
58                        objerror(m, USER, "bad transform");
59                if (mxf->f.sca < 0.0)
60                        mxf->f.sca = -mxf->f.sca;
61                if (mxf->b.sca < 0.0)
62                        mxf->b.sca = -mxf->b.sca;
63                m->os = (char *)mxf;
64        }
65 }
66
67
44   m_direct(m, r)                  /* shade redirected ray */
45   register OBJREC  *m;
46   register RAY  *r;
47   {
48                                          /* check if source ray */
49          if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
50 <                return;                         /* got the wrong guy */
75 <        dir_check(m);
50 >                return(1);                      /* got the wrong guy */
51                                          /* compute first projection */
52          if (m->otype == MAT_DIRECT1 ||
53                          (r->rsrc < 0 || source[r->rsrc].sa.sv.pn == 0))
# Line 81 | Line 56 | register RAY  *r;
56          if (m->otype == MAT_DIRECT2 &&
57                          (r->rsrc < 0 || source[r->rsrc].sa.sv.pn == 1))
58                  redirect(m, r, 1);
59 +        return(1);
60   }
61  
62  
# Line 89 | Line 65 | OBJREC  *m;
65   RAY  *r;
66   int  n;
67   {
68 <        register char  **sa;
68 >        MFUNC  *mf;
69 >        register EPNODE  **va;
70 >        FVECT  nsdir;
71          RAY  nr;
72          double  coef;
73          register int  j;
74                                          /* set up function */
75 <        setmap(m, r, &((FULLXF *)m->os)->b);
76 <        funcfile(m->oargs.sarg[fndx(m)]);
77 <        sa = m->oargs.sarg + 4*n;
75 >        mf = getdfunc(m);
76 >        setfunc(m, r);
77 >                                        /* assign direction variable */
78 >        if (r->rsrc >= 0) {
79 >                register SRCREC  *sp = source + source[r->rsrc].sa.sv.sn;
80 >
81 >                if (sp->sflags & SDISTANT)
82 >                        VCOPY(nsdir, sp->sloc);
83 >                else {
84 >                        for (j = 0; j < 3; j++)
85 >                                nsdir[j] = sp->sloc[j] - r->rop[j];
86 >                        normalize(nsdir);
87 >                }
88 >                multv3(nsdir, nsdir, funcxf.xfm);
89 >                varset("DxA", '=', nsdir[0]/funcxf.sca);
90 >                varset("DyA", '=', nsdir[1]/funcxf.sca);
91 >                varset("DzA", '=', nsdir[2]/funcxf.sca);
92 >        } else {
93 >                varset("DxA", '=', 0.0);
94 >                varset("DyA", '=', 0.0);
95 >                varset("DzA", '=', 0.0);
96 >        }
97                                          /* compute coefficient */
98          errno = 0;
99 <        coef = varvalue(sa[0]);
99 >        va = mf->ep + 4*n;
100 >        coef = evalue(va[0]);
101          if (errno)
102                  goto computerr;
103          if (coef <= FTINY || rayorigin(&nr, r, TRANS, coef) < 0)
104                  return(0);
105 <                                        /* compute direction */
106 <        errno = 0;
107 <        for (j = 0; j < 3; j++)
108 <                nr.rdir[j] = varvalue(sa[j+1]);
109 <        if (errno)
110 <                goto computerr;
111 <        multv3(nr.rdir, nr.rdir, ((FULLXF *)m->os)->f.xfm);
105 >        va++;                           /* compute direction */
106 >        for (j = 0; j < 3; j++) {
107 >                nr.rdir[j] = evalue(va[j]);
108 >                if (errno)
109 >                        goto computerr;
110 >        }
111 >        if (mf->f != &unitxf)
112 >                multv3(nr.rdir, nr.rdir, mf->f->xfm);
113          if (r->rox != NULL)
114                  multv3(nr.rdir, nr.rdir, r->rox->f.xfm);
115          if (normalize(nr.rdir) == 0.0)
# Line 135 | Line 134 | SRCREC  *s;
134   int  n;
135   {
136          RAY  tr;
137 <        register OBJREC  *m;
138 <        char  **sa;
137 >        OBJREC  *m;
138 >        MFUNC  *mf;
139 >        EPNODE  **va;
140          FVECT  cent, newdir, nv, h;
141 <        double  olddot, newdot, od;
141 >        double  coef, olddot, newdot, od;
142          register int  i, j;
143                                /* get material arguments */
144        m = vsmaterial(o);
145        dir_check(m);
146        sa = m->oargs.sarg + 4*n;
143                                  /* initialize test ray */
144          getmaxdisk(cent, o);
145          if (s->sflags & SDISTANT)
# Line 163 | Line 159 | int  n;
159          olddot = DOT(tr.rdir, nv);
160          if (olddot <= FTINY && olddot >= -FTINY)
161                  return(0);              /* old dir parallels plane */
162 +        tr.rmax = 0.0;
163          rayorigin(&tr, NULL, PRIMARY, 1.0);
164          if (!(*ofun[o->otype].funp)(o, &tr))
165                  return(0);              /* no intersection! */
166                                  /* compute redirection */
167 <        setmap(m, &tr, &((FULLXF *)m->os)->b);
168 <        funcfile(m->oargs.sarg[fndx(m)]);
167 >        m = vsmaterial(o);
168 >        mf = getdfunc(m);
169 >        setfunc(m, &tr);
170 >        varset("DxA", '=', 0.0);
171 >        varset("DyA", '=', 0.0);
172 >        varset("DzA", '=', 0.0);
173          errno = 0;
174 <        if (varvalue(sa[0]) <= FTINY)
175 <                return(0);              /* insignificant */
174 >        va = mf->ep + 4*n;
175 >        coef = evalue(va[0]);
176          if (errno)
177                  goto computerr;
178 <        for (i = 0; i < 3; i++)
179 <                newdir[i] = varvalue(sa[i+1]);
180 <        if (errno)
181 <                goto computerr;
182 <        multv3(newdir, newdir, ((FULLXF *)m->os)->f.xfm);
178 >        if (coef <= FTINY)
179 >                return(0);              /* insignificant */
180 >        va++;
181 >        for (i = 0; i < 3; i++) {
182 >                newdir[i] = evalue(va[i]);
183 >                if (errno)
184 >                        goto computerr;
185 >        }
186 >        if (mf->f != &unitxf)
187 >                multv3(newdir, newdir, mf->f->xfm);
188                                          /* normalization unnecessary */
189          newdot = DOT(newdir, nv);
190          if (newdot <= FTINY && newdot >= -FTINY)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines