--- ray/src/rt/m_mirror.c 1991/06/20 13:44:35 1.1 +++ ray/src/rt/m_mirror.c 1991/11/12 17:10:20 2.1 @@ -40,14 +40,16 @@ register RAY *r; /* check arguments */ if (m->oargs.nfargs != 3 || m->oargs.nsargs > 1) objerror(m, USER, "bad number of arguments"); - /* check if source ray */ - if (r->rsrc >= 0) { /* aiming for somebody */ - if (source[r->rsrc].so != r->ro) - return; /* but not us */ - } else if (m->oargs.nsargs > 0) { /* else call substitute? */ + /* check for substitute material */ + if (m->oargs.nsargs > 0 && + (r->rsrc < 0 || source[r->rsrc].so != r->ro)) { rayshade(r, modifier(m->oargs.sarg[0])); return; } + /* check for bad source ray */ + if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) + return; + if (r->rod < 0.) /* back is black */ return; /* get modifiers */ @@ -64,7 +66,7 @@ register RAY *r; for (i = 0; i < 3; i++) nr.rdir[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; /* source we're aiming for next */ - nr.rsrc = source[r->rsrc].sa.svnext; + nr.rsrc = source[r->rsrc].sa.sv.sn; } else { /* ordinary reflection */ FVECT pnorm; double pdot; @@ -84,15 +86,13 @@ register RAY *r; mir_proj(pm, o, s, n) /* compute a mirror's projection */ MAT4 pm; register OBJREC *o; -register SRCREC *s; +SRCREC *s; int n; { FVECT nv; double od; /* get surface normal and offset */ - if (sfun[o->otype].of->getpleq == NULL) - return(0); /* reject non-planar case */ - od = (*sfun[o->otype].of->getpleq)(nv, o); + od = getplaneq(nv, o); /* check for behind */ if (DOT(s->sloc, nv) <= (s->sflags & SDISTANT ? FTINY : od+FTINY)) return(0); @@ -110,9 +110,9 @@ double offs; register int i, j; /* assign matrix */ setident4(m); - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) + for (j = 0; j < 3; j++) { + for (i = 0; i < 3; i++) m[i][j] -= 2.*nv[i]*nv[j]; - for (j = 0; j < 3; j++) m[3][j] = 2.*offs*nv[j]; + } }