extern OBJREC * /* find an object's actual material */ findmaterial(register OBJREC *o) { while (!ismaterial(o->otype)) { if (o->otype == MOD_ALIAS && o->oargs.nsargs) { OBJECT aobj; OBJREC *ao; aobj = lastmod(objndx(o), o->oargs.sarg[0]); if (aobj < 0) objerror(o, USER, "bad reference"); ao = objptr(aobj); if (ismaterial(ao->otype)) return(ao); if (ao->otype == MOD_ALIAS) { o = ao; continue; } } if (o->omod == OVOID) return(NULL); o = objptr(o->omod); } return(o); /* mixtures will return NULL */ }
OBJREC * findmaterial(OBJREC *o) /* find an object's actual material */ { while (!ismaterial(o->otype)) { if (o->otype == MOD_ALIAS && o->oargs.nsargs) { OBJECT aobj; OBJREC *ao; aobj = lastmod(objndx(o), o->oargs.sarg[0]); if (aobj < 0) objerror(o, USER, "bad reference"); /* recursive check on alias branch */ if ((ao = findmaterial(objptr(aobj))) != NULL) return(ao); } if (o->omod == OVOID) { /* void mixture de facto material? */ if (ismixture(o->otype)) break; return(NULL); /* else no material found */ } o = objptr(o->omod); } return(o); }
extern int sourcehit( /* check to see if ray hit distant source */ register RAY *r ) { int glowsrc = -1; int transrc = -1; int first, last; register int i; if (r->rsrc >= 0) { /* check only one if aimed */ first = last = r->rsrc; } else { /* otherwise check all */ first = 0; last = nsources-1; } for (i = first; i <= last; i++) { if ((source[i].sflags & (SDISTANT|SVIRTUAL)) != SDISTANT) continue; /* * Check to see if ray is within * solid angle of source. */ if (2.*PI*(1. - DOT(source[i].sloc,r->rdir)) > source[i].ss2) continue; /* is it the only possibility? */ if (first == last) { r->ro = source[i].so; break; } /* * If it's a glow or transparent illum, just remember it. */ if (source[i].sflags & SSKIP) { if (glowsrc < 0) glowsrc = i; continue; } if (transillum(source[i].so->omod)) { if (transrc < 0) transrc = i; continue; } r->ro = source[i].so; /* otherwise, use first hit */ break; } /* * Do we need fallback? */ if (r->ro == NULL) { if (transrc >= 0 && r->crtype & (AMBIENT|SPECULAR)) return(0); /* avoid overcounting */ if (glowsrc >= 0) r->ro = source[glowsrc].so; else return(0); /* nothing usable */ } /* * Make assignments. */ r->robj = objndx(r->ro); for (i = 0; i < 3; i++) r->ron[i] = -r->rdir[i]; r->rod = 1.0; r->pert[0] = r->pert[1] = r->pert[2] = 0.0; r->uv[0] = r->uv[1] = 0.0; r->rox = NULL; return(1); }