| 1 |
greg |
1.1 |
/* Copyright (c) 1988 Regents of the University of California */
|
| 2 |
|
|
|
| 3 |
|
|
#ifndef lint
|
| 4 |
|
|
static char SCCSid[] = "$SunId$ LBL";
|
| 5 |
|
|
#endif
|
| 6 |
|
|
|
| 7 |
|
|
/*
|
| 8 |
|
|
* o_instance.c - routines for computing ray intersections with octrees.
|
| 9 |
|
|
*
|
| 10 |
|
|
* 11/11/88
|
| 11 |
|
|
*/
|
| 12 |
|
|
|
| 13 |
|
|
#include "ray.h"
|
| 14 |
|
|
|
| 15 |
|
|
#include "instance.h"
|
| 16 |
|
|
|
| 17 |
|
|
|
| 18 |
|
|
o_instance(o, r) /* compute ray intersection with octree */
|
| 19 |
|
|
OBJREC *o;
|
| 20 |
|
|
register RAY *r;
|
| 21 |
|
|
{
|
| 22 |
|
|
extern long nrays;
|
| 23 |
|
|
RAY rcont;
|
| 24 |
|
|
register INSTANCE *in;
|
| 25 |
|
|
register int i;
|
| 26 |
|
|
/* get the octree */
|
| 27 |
|
|
in = getinstance(o, GET_ALL);
|
| 28 |
|
|
/* copy old ray */
|
| 29 |
|
|
bcopy(r, &rcont, sizeof(RAY));
|
| 30 |
|
|
/* transform it */
|
| 31 |
|
|
rcont.rno = nrays;
|
| 32 |
|
|
rcont.ro = NULL;
|
| 33 |
|
|
rcont.rot = FHUGE;
|
| 34 |
|
|
rcont.rno = nrays;
|
| 35 |
|
|
multp3(rcont.rorg, r->rorg, in->b.xfm);
|
| 36 |
|
|
multv3(rcont.rdir, r->rdir, in->b.xfm);
|
| 37 |
|
|
for (i = 0; i < 3; i++)
|
| 38 |
|
|
rcont.rdir[i] /= in->b.sca;
|
| 39 |
|
|
/* trace it */
|
| 40 |
|
|
if (!localhit(&rcont, &in->obj->scube))
|
| 41 |
|
|
return(0); /* missed */
|
| 42 |
|
|
if (rcont.rot * in->f.sca >= r->rot)
|
| 43 |
|
|
return(0); /* not close enough */
|
| 44 |
|
|
/* if we have modifier, use it */
|
| 45 |
|
|
if (o->omod != OVOID)
|
| 46 |
|
|
r->ro = o;
|
| 47 |
|
|
else { /* else use theirs */
|
| 48 |
|
|
r->ro = rcont.ro;
|
| 49 |
greg |
1.2 |
multmat4(r->rofx, in->f.xfm, rcont.rofx);
|
| 50 |
|
|
r->rofs = in->f.sca * rcont.rofs;
|
| 51 |
|
|
multmat4(r->robx, in->b.xfm, rcont.robx);
|
| 52 |
|
|
r->robs = in->b.sca * rcont.robs;
|
| 53 |
greg |
1.1 |
}
|
| 54 |
|
|
/* transform it back */
|
| 55 |
|
|
r->rot = rcont.rot * in->f.sca;
|
| 56 |
|
|
multp3(r->rop, rcont.rop, in->f.xfm);
|
| 57 |
|
|
multv3(r->ron, rcont.ron, in->f.xfm);
|
| 58 |
|
|
for (i = 0; i < 3; i++)
|
| 59 |
|
|
r->ron[i] /= in->f.sca;
|
| 60 |
|
|
r->rod = rcont.rod;
|
| 61 |
|
|
/* return hit */
|
| 62 |
|
|
return(1);
|
| 63 |
|
|
}
|