--- ray/src/rt/m_direct.c 1991/07/16 17:16:32 1.3 +++ ray/src/rt/m_direct.c 1991/11/12 17:10:36 2.1 @@ -36,7 +36,35 @@ int dir_proj(); VSMATERIAL direct1_vs = {dir_proj, 1}; VSMATERIAL direct2_vs = {dir_proj, 2}; +#define fndx(m) ((m)->otype == MAT_DIRECT1 ? 4 : 8) + +static +dir_check(m) /* check arguments and load function file */ +register OBJREC *m; +{ + register FULLXF *mxf; + register int ff; + + ff = fndx(m)+1; + if (ff > m->oargs.nsargs) + objerror(m, USER, "too few arguments"); + if (m->os == NULL) { + mxf = (FULLXF *)malloc(sizeof(FULLXF)); + if (mxf == NULL) + error(SYSTEM, "out of memory in dir_check"); + if (fullxf(mxf, m->oargs.nsargs-ff, m->oargs.sarg+ff) != + m->oargs.nsargs-ff) + objerror(m, USER, "bad transform"); + if (mxf->f.sca < 0.0) + mxf->f.sca = -mxf->f.sca; + if (mxf->b.sca < 0.0) + mxf->b.sca = -mxf->b.sca; + m->os = (char *)mxf; + } +} + + m_direct(m, r) /* shade redirected ray */ register OBJREC *m; register RAY *r; @@ -66,7 +94,8 @@ int n; double coef; register int j; /* set up function */ - setfunc(m, r); + setmap(m, r, &((FULLXF *)m->os)->b); + funcfile(m->oargs.sarg[fndx(m)]); sa = m->oargs.sarg + 4*n; /* compute coefficient */ errno = 0; @@ -79,8 +108,13 @@ int n; errno = 0; for (j = 0; j < 3; j++) nr.rdir[j] = varvalue(sa[j+1]); - if (errno || normalize(nr.rdir) == 0.0) + if (errno) goto computerr; + multv3(nr.rdir, nr.rdir, ((FULLXF *)m->os)->f.xfm); + if (r->rox != NULL) + multv3(nr.rdir, nr.rdir, r->rox->f.xfm); + if (normalize(nr.rdir) == 0.0) + goto computerr; /* compute value */ if (r->rsrc >= 0) nr.rsrc = source[r->rsrc].sa.sv.sn; @@ -107,7 +141,7 @@ int n; double olddot, newdot, od; register int i, j; /* get material arguments */ - m = objptr(o->omod); + m = vsmaterial(o); dir_check(m); sa = m->oargs.sarg + 4*n; /* initialize test ray */ @@ -133,7 +167,8 @@ int n; if (!(*ofun[o->otype].funp)(o, &tr)) return(0); /* no intersection! */ /* compute redirection */ - setfunc(m, &tr); + setmap(m, &tr, &((FULLXF *)m->os)->b); + funcfile(m->oargs.sarg[fndx(m)]); errno = 0; if (varvalue(sa[0]) <= FTINY) return(0); /* insignificant */ @@ -143,12 +178,14 @@ int n; newdir[i] = varvalue(sa[i+1]); if (errno) goto computerr; + multv3(newdir, newdir, ((FULLXF *)m->os)->f.xfm); + /* normalization unnecessary */ newdot = DOT(newdir, nv); if (newdot <= FTINY && newdot >= -FTINY) return(0); /* new dir parallels plane */ /* everything OK -- compute shear */ for (i = 0; i < 3; i++) - h[i] = tr.rdir[i]/olddot + newdir[i]/newdot; + h[i] = newdir[i]/newdot - tr.rdir[i]/olddot; setident4(pm); for (j = 0; j < 3; j++) { for (i = 0; i < 3; i++) @@ -165,18 +202,4 @@ int n; computerr: objerror(m, WARNING, "projection compute error"); return(0); -} - - -static -dir_check(m) /* check arguments and load function file */ -register OBJREC *m; -{ - register int ff; - - ff = m->otype == MAT_DIRECT1 ? 4 : 8; - if (ff >= m->oargs.nsargs) - objerror(m, USER, "too few arguments"); - if (!vardefined(m->oargs.sarg[0])) - loadfunc(m->oargs.sarg[ff]); }