ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/bbox.c
Revision: 1.4
Committed: Sat Dec 15 15:23:56 1990 UTC (34 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +1 -1 lines
Log Message:
added XF and FULLXF types

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1987 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * bbox.c - routines for bounding box computation.
9     *
10     * 8/4/87
11     */
12    
13     #include "standard.h"
14    
15     #include "object.h"
16    
17     #include "otypes.h"
18    
19     #include "face.h"
20    
21     #include "cone.h"
22    
23     #include "instance.h"
24    
25    
26     add2bbox(o, bbmin, bbmax) /* expand bounding box to fit object */
27     register OBJREC *o;
28     FVECT bbmin, bbmax;
29     {
30 greg 1.2 CONE *co;
31     FACE *fo;
32     INSTANCE *io;
33 greg 1.1 FVECT v;
34     register int i, j;
35    
36     switch (o->otype) {
37     case OBJ_SPHERE:
38     case OBJ_BUBBLE:
39     if (o->oargs.nfargs != 4)
40     objerror(o, USER, "bad arguments");
41     for (i = 0; i < 3; i++) {
42     VCOPY(v, o->oargs.farg);
43     v[i] -= o->oargs.farg[3];
44     point2bbox(v, bbmin, bbmax);
45     v[i] += 2.0 * o->oargs.farg[3];
46     point2bbox(v, bbmin, bbmax);
47     }
48     break;
49     case OBJ_FACE:
50     fo = getface(o);
51     j = fo->nv;
52     while (j--)
53     point2bbox(VERTEX(fo,j), bbmin, bbmax);
54     break;
55     case OBJ_CONE:
56     case OBJ_CUP:
57     case OBJ_CYLINDER:
58     case OBJ_TUBE:
59     case OBJ_RING:
60     co = getcone(o, 0);
61     if (o->otype != OBJ_RING)
62     circle2bbox(CO_P0(co), co->ad, CO_R0(co), bbmin, bbmax);
63     circle2bbox(CO_P1(co), co->ad, CO_R1(co), bbmin, bbmax);
64     break;
65     case OBJ_INSTANCE:
66 greg 1.3 io = getinstance(o, IO_BOUNDS);
67 greg 1.1 for (j = 0; j < 8; j++) {
68     for (i = 0; i < 3; i++) {
69     v[i] = io->obj->scube.cuorg[i];
70     if (j & 1<<i)
71     v[i] += io->obj->scube.cusize;
72     }
73 greg 1.4 multp3(v, v, io->x.f.xfm);
74 greg 1.1 point2bbox(v, bbmin, bbmax);
75     }
76     break;
77     }
78     }
79    
80    
81     point2bbox(p, bbmin, bbmax) /* expand bounding box to fit point */
82     register FVECT p, bbmin, bbmax;
83     {
84     register int i;
85    
86     for (i = 0; i < 3; i++) {
87     if (p[i] < bbmin[i])
88     bbmin[i] = p[i];
89     if (p[i] > bbmax[i])
90     bbmax[i] = p[i];
91     }
92     }
93    
94    
95     circle2bbox(cent, norm, rad, bbmin, bbmax) /* expand bbox to fit circle */
96     FVECT cent, norm;
97     double rad;
98     FVECT bbmin, bbmax;
99     {
100     FVECT v1, v2;
101     register int i, j;
102    
103     for (i = 0; i < 3; i++) {
104     v1[0] = v1[1] = v1[2] = 0;
105     v1[i] = 1.0;
106     fcross(v2, norm, v1);
107     if (normalize(v2) == 0.0)
108     continue;
109     for (j = 0; j < 3; j++)
110     v1[j] = cent[j] + rad*v2[j];
111     point2bbox(v1, bbmin, bbmax);
112     for (j = 0; j < 3; j++)
113     v1[j] = cent[j] - rad*v2[j];
114     point2bbox(v1, bbmin, bbmax);
115     }
116     }