ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/o_instance.c
Revision: 1.10
Committed: Mon Jun 17 08:26:20 1991 UTC (32 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.9: +2 -2 lines
Log Message:
added raynum counter and reinstated repeat call test in setfunc()

File Contents

# User Rev Content
1 greg 1.8 /* Copyright (c) 1990 Regents of the University of California */
2 greg 1.1
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 greg 1.10 extern long raynum;
23 greg 1.1 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 greg 1.10 rcont.rno = raynum++;
32 greg 1.1 rcont.ro = NULL;
33     rcont.rot = FHUGE;
34 greg 1.8 multp3(rcont.rorg, r->rorg, in->x.b.xfm);
35     multv3(rcont.rdir, r->rdir, in->x.b.xfm);
36 greg 1.1 for (i = 0; i < 3; i++)
37 greg 1.8 rcont.rdir[i] /= in->x.b.sca;
38 greg 1.1 /* trace it */
39     if (!localhit(&rcont, &in->obj->scube))
40     return(0); /* missed */
41 greg 1.8 if (rcont.rot * in->x.f.sca >= r->rot)
42 greg 1.1 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.8 r->rox = NULL;
47 greg 1.4 } else { /* else use theirs */
48 greg 1.1 r->ro = rcont.ro;
49 greg 1.8 if (rcont.rox != NULL) {
50 greg 1.9 newrayxf(r); /* allocate transformation */
51     /* NOTE: r->rox may equal rcont.rox! */
52 greg 1.8 multmat4(r->rox->f.xfm, rcont.rox->f.xfm, in->x.f.xfm);
53     r->rox->f.sca = rcont.rox->f.sca * in->x.f.sca;
54     multmat4(r->rox->b.xfm, in->x.b.xfm, rcont.rox->b.xfm);
55     r->rox->b.sca = in->x.b.sca * rcont.rox->b.sca;
56     } else
57 greg 1.9 r->rox = &in->x;
58 greg 1.1 }
59     /* transform it back */
60 greg 1.8 r->rot = rcont.rot * in->x.f.sca;
61     multp3(r->rop, rcont.rop, in->x.f.xfm);
62     multv3(r->ron, rcont.ron, in->x.f.xfm);
63 greg 1.1 for (i = 0; i < 3; i++)
64 greg 1.8 r->ron[i] /= in->x.f.sca;
65 greg 1.1 r->rod = rcont.rod;
66     /* return hit */
67     return(1);
68     }