--- ray/src/rt/m_mirror.c 1991/06/20 13:44:35 1.1 +++ ray/src/rt/m_mirror.c 1994/01/12 16:46:41 2.3 @@ -40,16 +40,18 @@ 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; + return(1); } + /* check for bad source ray */ + if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) + return(1); + if (r->rod < 0.) /* back is black */ - return; + return(1); /* get modifiers */ raytexture(r, m->omod); /* assign material color */ @@ -64,35 +66,38 @@ 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; if (rayorigin(&nr, r, REFLECTED, bright(mcolor)) < 0) - return; + return(1); pdot = raynormal(pnorm, r); /* use textures */ for (i = 0; i < 3; i++) nr.rdir[i] = r->rdir[i] + 2.*pdot*pnorm[i]; + /* check for penetration */ + if (DOT(nr.rdir, r->ron) <= FTINY) + for (i = 0; i < 3; i++) + nr.rdir[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; } rayvalue(&nr); multcolor(nr.rcol, mcolor); addcolor(r->rcol, nr.rcol); + return(1); } 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 +115,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]; + } }