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

File Contents

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