ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/bbox.c
Revision: 2.5
Committed: Sat Mar 27 12:41:45 2004 UTC (20 years, 3 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6, rad3R6P1
Changes since 2.4: +26 -17 lines
Log Message:
Continued ANSIfication. Renamed local initotypes() to ot_initotypes().

File Contents

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