1 |
– |
/* Copyright (c) 1987 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* bbox.c - routines for bounding box computation. |
9 |
– |
* |
10 |
– |
* 8/4/87 |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include "standard.h" |
8 |
> |
#include "copyright.h" |
9 |
|
|
10 |
+ |
#include "standard.h" |
11 |
|
#include "object.h" |
12 |
< |
|
12 |
> |
#include "octree.h" |
13 |
|
#include "otypes.h" |
18 |
– |
|
14 |
|
#include "face.h" |
20 |
– |
|
15 |
|
#include "cone.h" |
22 |
– |
|
16 |
|
#include "instance.h" |
17 |
+ |
#include "mesh.h" |
18 |
+ |
#include "oconv.h" |
19 |
|
|
20 |
|
|
21 |
< |
add2bbox(o, bbmin, bbmax) /* expand bounding box to fit object */ |
22 |
< |
register OBJREC *o; |
23 |
< |
FVECT bbmin, bbmax; |
21 |
> |
static void point2bbox(FVECT p, FVECT bbmin, FVECT bbmax); |
22 |
> |
static void circle2bbox(FVECT cent, FVECT norm, double rad, FVECT bbmin, FVECT bbmax); |
23 |
> |
|
24 |
> |
|
25 |
> |
void |
26 |
> |
add2bbox( /* expand bounding box to fit object */ |
27 |
> |
register OBJREC *o, |
28 |
> |
FVECT bbmin, |
29 |
> |
FVECT bbmax |
30 |
> |
) |
31 |
|
{ |
32 |
< |
#define co ((CONE *)osp) |
33 |
< |
#define fo ((FACE *)osp) |
34 |
< |
#define io ((INSTANCE *)osp) |
35 |
< |
register char *osp; |
32 |
> |
CONE *co; |
33 |
> |
FACE *fo; |
34 |
> |
INSTANCE *io; |
35 |
> |
MESHINST *mi; |
36 |
|
FVECT v; |
37 |
|
register int i, j; |
38 |
|
|
66 |
|
circle2bbox(CO_P1(co), co->ad, CO_R1(co), bbmin, bbmax); |
67 |
|
break; |
68 |
|
case OBJ_INSTANCE: |
69 |
< |
io = getinstance(o, GET_BOUNDS); |
69 |
> |
io = getinstance(o, IO_BOUNDS); |
70 |
|
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 |
< |
multp3(v, v, io->f.xfm); |
76 |
> |
multp3(v, v, io->x.f.xfm); |
77 |
|
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 |
+ |
point2bbox(v, bbmin, bbmax); |
90 |
+ |
} |
91 |
+ |
break; |
92 |
|
} |
79 |
– |
#undef co |
80 |
– |
#undef fo |
81 |
– |
#undef io |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
< |
point2bbox(p, bbmin, bbmax) /* expand bounding box to fit point */ |
97 |
< |
register FVECT p, bbmin, bbmax; |
96 |
> |
static void |
97 |
> |
point2bbox( /* expand bounding box to fit point */ |
98 |
> |
register FVECT p, |
99 |
> |
register FVECT bbmin, |
100 |
> |
register FVECT bbmax |
101 |
> |
) |
102 |
|
{ |
103 |
|
register int i; |
104 |
|
|
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
< |
circle2bbox(cent, norm, rad, bbmin, bbmax) /* expand bbox to fit circle */ |
115 |
< |
FVECT cent, norm; |
116 |
< |
double rad; |
117 |
< |
FVECT bbmin, bbmax; |
114 |
> |
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 |
|
{ |
123 |
< |
FVECT v1, v2; |
124 |
< |
register int i, j; |
123 |
> |
double d, r; |
124 |
> |
register int i; |
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]; |
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); |
127 |
> |
r = sqrt(1. - norm[i]*norm[i]); |
128 |
> |
d = cent[i] + r*rad; |
129 |
> |
if (d > bbmax[i]) |
130 |
> |
bbmax[i] = d; |
131 |
> |
d = cent[i] - r*rad; |
132 |
> |
if (d < bbmin[i]) |
133 |
> |
bbmin[i] = d; |
134 |
|
} |
135 |
|
} |