ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/bbox.c
Revision: 1.1
Committed: Thu Feb 2 10:33:00 1989 UTC (35 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

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     #define co ((CONE *)osp)
31     #define fo ((FACE *)osp)
32     #define io ((INSTANCE *)osp)
33     register char *osp;
34     FVECT v;
35     register int i, j;
36    
37     switch (o->otype) {
38     case OBJ_SPHERE:
39     case OBJ_BUBBLE:
40     if (o->oargs.nfargs != 4)
41     objerror(o, USER, "bad arguments");
42     for (i = 0; i < 3; i++) {
43     VCOPY(v, o->oargs.farg);
44     v[i] -= o->oargs.farg[3];
45     point2bbox(v, bbmin, bbmax);
46     v[i] += 2.0 * o->oargs.farg[3];
47     point2bbox(v, bbmin, bbmax);
48     }
49     break;
50     case OBJ_FACE:
51     fo = getface(o);
52     j = fo->nv;
53     while (j--)
54     point2bbox(VERTEX(fo,j), bbmin, bbmax);
55     break;
56     case OBJ_CONE:
57     case OBJ_CUP:
58     case OBJ_CYLINDER:
59     case OBJ_TUBE:
60     case OBJ_RING:
61     co = getcone(o, 0);
62     if (o->otype != OBJ_RING)
63     circle2bbox(CO_P0(co), co->ad, CO_R0(co), bbmin, bbmax);
64     circle2bbox(CO_P1(co), co->ad, CO_R1(co), bbmin, bbmax);
65     break;
66     case OBJ_INSTANCE:
67     io = getinstance(o, GET_BOUNDS);
68     for (j = 0; j < 8; j++) {
69     for (i = 0; i < 3; i++) {
70     v[i] = io->obj->scube.cuorg[i];
71     if (j & 1<<i)
72     v[i] += io->obj->scube.cusize;
73     }
74     multp3(v, v, io->f.xfm);
75     point2bbox(v, bbmin, bbmax);
76     }
77     break;
78     }
79     #undef co
80     #undef fo
81     #undef io
82     }
83    
84    
85     point2bbox(p, bbmin, bbmax) /* expand bounding box to fit point */
86     register FVECT p, bbmin, bbmax;
87     {
88     register int i;
89    
90     for (i = 0; i < 3; i++) {
91     if (p[i] < bbmin[i])
92     bbmin[i] = p[i];
93     if (p[i] > bbmax[i])
94     bbmax[i] = p[i];
95     }
96     }
97    
98    
99     circle2bbox(cent, norm, rad, bbmin, bbmax) /* expand bbox to fit circle */
100     FVECT cent, norm;
101     double rad;
102     FVECT bbmin, bbmax;
103     {
104     FVECT v1, v2;
105     register int i, j;
106    
107     for (i = 0; i < 3; i++) {
108     v1[0] = v1[1] = v1[2] = 0;
109     v1[i] = 1.0;
110     fcross(v2, norm, v1);
111     if (normalize(v2) == 0.0)
112     continue;
113     for (j = 0; j < 3; j++)
114     v1[j] = cent[j] + rad*v2[j];
115     point2bbox(v1, bbmin, bbmax);
116     for (j = 0; j < 3; j++)
117     v1[j] = cent[j] - rad*v2[j];
118     point2bbox(v1, bbmin, bbmax);
119     }
120     }