| 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 | 
  | 
        CONE  *co; | 
| 33 | 
  | 
        FACE  *fo; | 
| 34 | 
  | 
        INSTANCE  *io; | 
| 35 | 
+ | 
        MESHINST  *mi; | 
| 36 | 
  | 
        FVECT  v; | 
| 37 | 
  | 
        register int  i, j; | 
| 38 | 
  | 
 | 
| 61 | 
  | 
        case OBJ_TUBE: | 
| 62 | 
  | 
        case OBJ_RING: | 
| 63 | 
  | 
                co = getcone(o, 0); | 
| 64 | 
+ | 
                if (co == NULL) | 
| 65 | 
+ | 
                        break; | 
| 66 | 
  | 
                if (o->otype != OBJ_RING) | 
| 67 | 
  | 
                        circle2bbox(CO_P0(co), co->ad, CO_R0(co), bbmin, bbmax); | 
| 68 | 
  | 
                circle2bbox(CO_P1(co), co->ad, CO_R1(co), bbmin, bbmax); | 
| 75 | 
  | 
                                if (j & 1<<i) | 
| 76 | 
  | 
                                        v[i] += io->obj->scube.cusize; | 
| 77 | 
  | 
                        } | 
| 78 | 
< | 
                        multp3(v, v, io->f.xfm); | 
| 78 | 
> | 
                        multp3(v, v, io->x.f.xfm); | 
| 79 | 
  | 
                        point2bbox(v, bbmin, bbmax); | 
| 80 | 
  | 
                } | 
| 81 | 
  | 
                break; | 
| 82 | 
+ | 
        case OBJ_MESH: | 
| 83 | 
+ | 
                mi = getmeshinst(o, IO_BOUNDS); | 
| 84 | 
+ | 
                for (j = 0; j < 8; j++) { | 
| 85 | 
+ | 
                        for (i = 0; i < 3; i++) { | 
| 86 | 
+ | 
                                v[i] = mi->msh->mcube.cuorg[i]; | 
| 87 | 
+ | 
                                if (j & 1<<i) | 
| 88 | 
+ | 
                                        v[i] += mi->msh->mcube.cusize; | 
| 89 | 
+ | 
                        } | 
| 90 | 
+ | 
                        multp3(v, v, mi->x.f.xfm); | 
| 91 | 
+ | 
                        point2bbox(v, bbmin, bbmax); | 
| 92 | 
+ | 
                } | 
| 93 | 
+ | 
                break; | 
| 94 | 
  | 
        } | 
| 95 | 
  | 
} | 
| 96 | 
  | 
 | 
| 97 | 
  | 
 | 
| 98 | 
< | 
point2bbox(p, bbmin, bbmax)             /* expand bounding box to fit point */ | 
| 99 | 
< | 
register FVECT  p, bbmin, bbmax; | 
| 98 | 
> | 
static void | 
| 99 | 
> | 
point2bbox(             /* expand bounding box to fit point */ | 
| 100 | 
> | 
        register FVECT  p, | 
| 101 | 
> | 
        register FVECT  bbmin, | 
| 102 | 
> | 
        register FVECT  bbmax | 
| 103 | 
> | 
) | 
| 104 | 
  | 
{ | 
| 105 | 
  | 
        register int  i; | 
| 106 | 
  | 
 | 
| 113 | 
  | 
} | 
| 114 | 
  | 
 | 
| 115 | 
  | 
 | 
| 116 | 
< | 
circle2bbox(cent, norm, rad, bbmin, bbmax)      /* expand bbox to fit circle */ | 
| 117 | 
< | 
FVECT  cent, norm; | 
| 118 | 
< | 
double  rad; | 
| 119 | 
< | 
FVECT  bbmin, bbmax; | 
| 116 | 
> | 
static void | 
| 117 | 
> | 
circle2bbox(    /* expand bbox to fit circle */ | 
| 118 | 
> | 
        FVECT  cent, | 
| 119 | 
> | 
        FVECT  norm, | 
| 120 | 
> | 
        double  rad, | 
| 121 | 
> | 
        FVECT  bbmin, | 
| 122 | 
> | 
        FVECT  bbmax | 
| 123 | 
> | 
) | 
| 124 | 
  | 
{ | 
| 125 | 
< | 
        FVECT  v1, v2; | 
| 126 | 
< | 
        register int  i, j; | 
| 125 | 
> | 
        double  d, r; | 
| 126 | 
> | 
        register int  i; | 
| 127 | 
  | 
 | 
| 128 | 
  | 
        for (i = 0; i < 3; i++) { | 
| 129 | 
< | 
                v1[0] = v1[1] = v1[2] = 0; | 
| 130 | 
< | 
                v1[i] = 1.0; | 
| 131 | 
< | 
                fcross(v2, norm, v1); | 
| 132 | 
< | 
                if (normalize(v2) == 0.0) | 
| 133 | 
< | 
                        continue; | 
| 134 | 
< | 
                for (j = 0; j < 3; j++) | 
| 135 | 
< | 
                        v1[j] = cent[j] + rad*v2[j]; | 
| 111 | 
< | 
                point2bbox(v1, bbmin, bbmax); | 
| 112 | 
< | 
                for (j = 0; j < 3; j++) | 
| 113 | 
< | 
                        v1[j] = cent[j] - rad*v2[j]; | 
| 114 | 
< | 
                point2bbox(v1, bbmin, bbmax); | 
| 129 | 
> | 
                r = sqrt(1. - norm[i]*norm[i]); | 
| 130 | 
> | 
                d = cent[i] + r*rad; | 
| 131 | 
> | 
                if (d > bbmax[i]) | 
| 132 | 
> | 
                        bbmax[i] = d; | 
| 133 | 
> | 
                d = cent[i] - r*rad; | 
| 134 | 
> | 
                if (d < bbmin[i]) | 
| 135 | 
> | 
                        bbmin[i] = d; | 
| 136 | 
  | 
        } | 
| 137 | 
  | 
} |