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 1.1 by greg, Tue Jul 16 15:44:30 1991 UTC vs.
Revision 2.1 by greg, Tue Nov 12 17:10:36 1991 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18   /*
19   * The arguments for MAT_DIRECT1 are:
20   *
21 < *      4+ coef1 dx1 dy1 dz1 transform..
21 > *      5+ coef1 dx1 dy1 dz1 funcfile transform..
22   *      0
23   *      n A1 A2 .. An
24   *
25   * The arguments for MAT_DIRECT2 are:
26   *
27 < *      8+ coef1 dx1 dy1 dz1 coef2 dx2 dy2 dz2 transform..
27 > *      9+ coef1 dx1 dy1 dz1 coef2 dx2 dy2 dz2 funcfile transform..
28   *      0
29   *      n A1 A2 .. An
30   */
# Line 36 | Line 36 | 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)
40  
41 +
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 +
68   m_direct(m, r)                  /* shade redirected ray */
69   register OBJREC  *m;
70   register RAY  *r;
# Line 44 | Line 72 | register RAY  *r;
72                                          /* check if source ray */
73          if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
74                  return;                         /* got the wrong guy */
75 +        dir_check(m);
76                                          /* compute first projection */
77          if (m->otype == MAT_DIRECT1 ||
78                          (r->rsrc < 0 || source[r->rsrc].sa.sv.pn == 0))
# Line 65 | Line 94 | int  n;
94          double  coef;
95          register int  j;
96                                          /* set up function */
97 <        setfunc(m, r);
98 <        if (m->oargs.nsargs < 4+4*n)
70 <                objerror(m, USER, "too few arguments");
97 >        setmap(m, r, &((FULLXF *)m->os)->b);
98 >        funcfile(m->oargs.sarg[fndx(m)]);
99          sa = m->oargs.sarg + 4*n;
100                                          /* compute coefficient */
101          errno = 0;
# Line 80 | Line 108 | int  n;
108          errno = 0;
109          for (j = 0; j < 3; j++)
110                  nr.rdir[j] = varvalue(sa[j+1]);
111 <        if (errno || normalize(nr.rdir) == 0.0)
111 >        if (errno)
112                  goto computerr;
113 +        multv3(nr.rdir, nr.rdir, ((FULLXF *)m->os)->f.xfm);
114 +        if (r->rox != NULL)
115 +                multv3(nr.rdir, nr.rdir, r->rox->f.xfm);
116 +        if (normalize(nr.rdir) == 0.0)
117 +                goto computerr;
118                                          /* compute value */
119          if (r->rsrc >= 0)
120                  nr.rsrc = source[r->rsrc].sa.sv.sn;
# Line 108 | Line 141 | int  n;
141          double  olddot, newdot, od;
142          register int  i, j;
143                                  /* get material arguments */
144 <        m = objptr(o->omod);
145 <        if (m->oargs.nsargs < 4+4*n)
113 <                objerror(m, USER, "too few arguments");
144 >        m = vsmaterial(o);
145 >        dir_check(m);
146          sa = m->oargs.sarg + 4*n;
147                                  /* initialize test ray */
148          getmaxdisk(cent, o);
# Line 122 | Line 154 | int  n;
154          else {
155                  for (i = 0; i < 3; i++) {
156                          tr.rdir[i] = cent[i] - s->sloc[i];
157 <                        tr.rorg[i] = cent[i] - .05*tr.rdir[i];
157 >                        tr.rorg[i] = s->sloc[i];
158                  }
159                  if (normalize(tr.rdir) == 0.0)
160                          return(0);              /* at source! */
# Line 135 | Line 167 | int  n;
167          if (!(*ofun[o->otype].funp)(o, &tr))
168                  return(0);              /* no intersection! */
169                                  /* compute redirection */
170 <        setfunc(m, &tr);
170 >        setmap(m, &tr, &((FULLXF *)m->os)->b);
171 >        funcfile(m->oargs.sarg[fndx(m)]);
172          errno = 0;
173          if (varvalue(sa[0]) <= FTINY)
174                  return(0);              /* insignificant */
# Line 145 | Line 178 | int  n;
178                  newdir[i] = varvalue(sa[i+1]);
179          if (errno)
180                  goto computerr;
181 +        multv3(newdir, newdir, ((FULLXF *)m->os)->f.xfm);
182 +                                        /* normalization unnecessary */
183          newdot = DOT(newdir, nv);
184          if (newdot <= FTINY && newdot >= -FTINY)
185                  return(0);              /* new dir parallels plane */
186                                  /* everything OK -- compute shear */
187          for (i = 0; i < 3; i++)
188 <                h[i] = tr.rdir[i]/olddot + newdir[i]/newdot;
188 >                h[i] = newdir[i]/newdot - tr.rdir[i]/olddot;
189          setident4(pm);
190          for (j = 0; j < 3; j++) {
191                  for (i = 0; i < 3; i++)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines