--- ray/src/rt/o_instance.c 1991/11/12 17:10:10 2.1 +++ ray/src/rt/o_instance.c 2004/03/30 16:13:01 2.8 @@ -1,42 +1,41 @@ -/* Copyright (c) 1990 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: o_instance.c,v 2.8 2004/03/30 16:13:01 schorsch Exp $"; #endif - /* * o_instance.c - routines for computing ray intersections with octrees. - * - * 11/11/88 */ -#include "ray.h" +#include "copyright.h" +#include "ray.h" #include "instance.h" +#include "rtotypes.h" -o_instance(o, r) /* compute ray intersection with octree */ -OBJREC *o; -register RAY *r; +extern int +o_instance( /* compute ray intersection with octree */ + OBJREC *o, + register RAY *r +) { - extern long raynum; RAY rcont; - register INSTANCE *in; + double d; + register INSTANCE *ins; register int i; /* get the octree */ - in = getinstance(o, IO_ALL); - /* duplicate and clear ray */ - copystruct(&rcont, r); - rayclear(&rcont); - /* transform ray to new space */ - multp3(rcont.rorg, r->rorg, in->x.b.xfm); - multv3(rcont.rdir, r->rdir, in->x.b.xfm); + ins = getinstance(o, IO_ALL); + /* copy and transform ray */ + rcont = *r; + multp3(rcont.rorg, r->rorg, ins->x.b.xfm); + multv3(rcont.rdir, r->rdir, ins->x.b.xfm); for (i = 0; i < 3; i++) - rcont.rdir[i] /= in->x.b.sca; - /* trace it */ - if (!localhit(&rcont, &in->obj->scube)) + rcont.rdir[i] /= ins->x.b.sca; + rcont.rmax *= ins->x.b.sca; + /* clear and trace it */ + rayclear(&rcont); + if (!localhit(&rcont, &ins->obj->scube)) return(0); /* missed */ - if (rcont.rot * in->x.f.sca >= r->rot) + if (rcont.rot * ins->x.f.sca >= r->rot) return(0); /* not close enough */ if (o->omod != OVOID) { /* if we have modifier, use it */ @@ -47,20 +46,26 @@ register RAY *r; if (rcont.rox != NULL) { newrayxf(r); /* allocate transformation */ /* NOTE: r->rox may equal rcont.rox! */ - multmat4(r->rox->f.xfm, rcont.rox->f.xfm, in->x.f.xfm); - r->rox->f.sca = rcont.rox->f.sca * in->x.f.sca; - multmat4(r->rox->b.xfm, in->x.b.xfm, rcont.rox->b.xfm); - r->rox->b.sca = in->x.b.sca * rcont.rox->b.sca; + multmat4(r->rox->f.xfm, rcont.rox->f.xfm, ins->x.f.xfm); + r->rox->f.sca = rcont.rox->f.sca * ins->x.f.sca; + multmat4(r->rox->b.xfm, ins->x.b.xfm, rcont.rox->b.xfm); + r->rox->b.sca = ins->x.b.sca * rcont.rox->b.sca; } else - r->rox = &in->x; + r->rox = &ins->x; } /* transform it back */ - r->rot = rcont.rot * in->x.f.sca; - multp3(r->rop, rcont.rop, in->x.f.xfm); - multv3(r->ron, rcont.ron, in->x.f.xfm); - for (i = 0; i < 3; i++) - r->ron[i] /= in->x.f.sca; + r->rot = rcont.rot * ins->x.f.sca; + multp3(r->rop, rcont.rop, ins->x.f.xfm); + multv3(r->ron, rcont.ron, ins->x.f.xfm); + multv3(r->pert, rcont.pert, ins->x.f.xfm); + d = 1./ins->x.f.sca; + for (i = 0; i < 3; i++) { + r->ron[i] *= d; + r->pert[i] *= d; + } r->rod = rcont.rod; + r->uv[0] = rcont.uv[0]; + r->uv[1] = rcont.uv[1]; /* return hit */ return(1); }