ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/o_instance.c
Revision: 2.5
Committed: Tue Feb 25 02:47:23 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.4 static const char RCSid[] = "$Id$";
3 greg 1.1 #endif
4     /*
5     * o_instance.c - routines for computing ray intersections with octrees.
6 greg 2.4 */
7    
8 greg 2.5 #include "copyright.h"
9 greg 1.1
10     #include "ray.h"
11    
12     #include "instance.h"
13    
14    
15     o_instance(o, r) /* compute ray intersection with octree */
16     OBJREC *o;
17     register RAY *r;
18     {
19     RAY rcont;
20     register INSTANCE *in;
21     register int i;
22     /* get the octree */
23 greg 1.6 in = getinstance(o, IO_ALL);
24 greg 2.3 /* copy and transform ray */
25 greg 1.7 copystruct(&rcont, r);
26 greg 1.8 multp3(rcont.rorg, r->rorg, in->x.b.xfm);
27     multv3(rcont.rdir, r->rdir, in->x.b.xfm);
28 greg 1.1 for (i = 0; i < 3; i++)
29 greg 1.8 rcont.rdir[i] /= in->x.b.sca;
30 greg 2.3 rcont.rmax *= in->x.b.sca;
31     /* clear and trace it */
32     rayclear(&rcont);
33 greg 1.1 if (!localhit(&rcont, &in->obj->scube))
34 greg 1.11 return(0); /* missed */
35 greg 1.8 if (rcont.rot * in->x.f.sca >= r->rot)
36 greg 1.11 return(0); /* not close enough */
37 greg 1.4
38     if (o->omod != OVOID) { /* if we have modifier, use it */
39 greg 1.1 r->ro = o;
40 greg 1.8 r->rox = NULL;
41 greg 1.4 } else { /* else use theirs */
42 greg 1.1 r->ro = rcont.ro;
43 greg 1.8 if (rcont.rox != NULL) {
44 greg 1.9 newrayxf(r); /* allocate transformation */
45     /* NOTE: r->rox may equal rcont.rox! */
46 greg 1.8 multmat4(r->rox->f.xfm, rcont.rox->f.xfm, in->x.f.xfm);
47     r->rox->f.sca = rcont.rox->f.sca * in->x.f.sca;
48     multmat4(r->rox->b.xfm, in->x.b.xfm, rcont.rox->b.xfm);
49     r->rox->b.sca = in->x.b.sca * rcont.rox->b.sca;
50     } else
51 greg 1.9 r->rox = &in->x;
52 greg 1.1 }
53     /* transform it back */
54 greg 1.8 r->rot = rcont.rot * in->x.f.sca;
55     multp3(r->rop, rcont.rop, in->x.f.xfm);
56     multv3(r->ron, rcont.ron, in->x.f.xfm);
57 greg 1.1 for (i = 0; i < 3; i++)
58 greg 1.8 r->ron[i] /= in->x.f.sca;
59 greg 1.1 r->rod = rcont.rod;
60     /* return hit */
61     return(1);
62     }