ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/bbox.c
Revision: 2.4
Committed: Tue Mar 11 17:08:55 2003 UTC (21 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.3: +17 -2 lines
Log Message:
First working version of new "mesh" primitive, obj2mesh converter

File Contents

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