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 |
greg |
1.6 |
in = getinstance(o, IO_ALL); |
28 |
greg |
1.1 |
/* copy old ray */ |
29 |
greg |
1.7 |
copystruct(&rcont, r); |
30 |
greg |
1.1 |
/* transform it */ |
31 |
|
|
rcont.rno = nrays; |
32 |
|
|
rcont.ro = NULL; |
33 |
|
|
rcont.rot = FHUGE; |
34 |
|
|
multp3(rcont.rorg, r->rorg, in->b.xfm); |
35 |
|
|
multv3(rcont.rdir, r->rdir, in->b.xfm); |
36 |
|
|
for (i = 0; i < 3; i++) |
37 |
|
|
rcont.rdir[i] /= in->b.sca; |
38 |
|
|
/* trace it */ |
39 |
|
|
if (!localhit(&rcont, &in->obj->scube)) |
40 |
|
|
return(0); /* missed */ |
41 |
|
|
if (rcont.rot * in->f.sca >= r->rot) |
42 |
|
|
return(0); /* not close enough */ |
43 |
greg |
1.4 |
|
44 |
|
|
if (o->omod != OVOID) { /* if we have modifier, use it */ |
45 |
greg |
1.1 |
r->ro = o; |
46 |
greg |
1.4 |
r->rofs = 1.0; setident4(r->rofx); |
47 |
|
|
r->robs = 1.0; setident4(r->robx); |
48 |
|
|
} else { /* else use theirs */ |
49 |
greg |
1.1 |
r->ro = rcont.ro; |
50 |
greg |
1.3 |
multmat4(r->rofx, rcont.rofx, in->f.xfm); |
51 |
|
|
r->rofs = rcont.rofs * in->f.sca; |
52 |
greg |
1.2 |
multmat4(r->robx, in->b.xfm, rcont.robx); |
53 |
|
|
r->robs = in->b.sca * rcont.robs; |
54 |
greg |
1.1 |
} |
55 |
|
|
/* transform it back */ |
56 |
|
|
r->rot = rcont.rot * in->f.sca; |
57 |
|
|
multp3(r->rop, rcont.rop, in->f.xfm); |
58 |
|
|
multv3(r->ron, rcont.ron, in->f.xfm); |
59 |
|
|
for (i = 0; i < 3; i++) |
60 |
|
|
r->ron[i] /= in->f.sca; |
61 |
|
|
r->rod = rcont.rod; |
62 |
|
|
/* return hit */ |
63 |
|
|
return(1); |
64 |
|
|
} |