| 1 |
– |
/* Copyright (c) 1988 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 |
< |
* o_instance.c - routines for creating octrees for other octrees. |
| 9 |
< |
* |
| 10 |
< |
* 11/11/88 |
| 5 |
> |
* o_instance.c - routines for creating octrees for other octrees |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
|
#include "standard.h" |
| 9 |
|
|
| 10 |
|
#include "object.h" |
| 11 |
|
|
| 12 |
+ |
#include "octree.h" |
| 13 |
+ |
|
| 14 |
|
#include "instance.h" |
| 15 |
|
|
| 16 |
+ |
#include "mesh.h" |
| 17 |
+ |
|
| 18 |
|
#include "plocate.h" |
| 19 |
|
|
| 20 |
|
/* |
| 40 |
|
*/ |
| 41 |
|
|
| 42 |
|
|
| 43 |
< |
o_instance(o, cu) /* determine if cubes intersect */ |
| 44 |
< |
OBJREC *o; |
| 43 |
> |
static int |
| 44 |
> |
o_cube(cu1, fxf, cu) /* determine if cubes intersect */ |
| 45 |
> |
CUBE *cu1; |
| 46 |
> |
FULLXF *fxf; |
| 47 |
|
CUBE *cu; |
| 48 |
|
{ |
| 49 |
< |
static char vstart[4] = {0, 3, 5, 6}; |
| 49 |
> |
static int vstart[4] = {0, 3, 5, 6}; |
| 50 |
|
FVECT cumin, cumax; |
| 51 |
|
FVECT vert[8]; |
| 52 |
|
FVECT v1, v2; |
| 52 |
– |
register INSTANCE *in; |
| 53 |
|
int vloc, vout; |
| 54 |
|
register int i, j; |
| 55 |
– |
/* get octree arguments */ |
| 56 |
– |
in = getinstance(o, GET_BOUNDS); |
| 55 |
|
/* check if cube vertex in octree */ |
| 56 |
|
for (j = 0; j < 3; j++) |
| 57 |
< |
cumax[j] = (cumin[j] = in->obj->scube.cuorg[j]) + |
| 60 |
< |
in->obj->scube.cusize; |
| 57 |
> |
cumax[j] = (cumin[j] = cu1->cuorg[j]) + cu1->cusize; |
| 58 |
|
vloc = ABOVE | BELOW; |
| 59 |
|
vout = 0; |
| 60 |
|
for (i = 0; i < 8; i++) { |
| 63 |
|
if (i & 1<<j) |
| 64 |
|
v1[j] += cu->cusize; |
| 65 |
|
} |
| 66 |
< |
multp3(v2, v1, in->b.xfm); |
| 67 |
< |
if (j = plocate(v2, cumin, cumax)) |
| 66 |
> |
multp3(v2, v1, fxf->b.xfm); |
| 67 |
> |
if ( (j = plocate(v2, cumin, cumax)) ) |
| 68 |
|
vout++; |
| 69 |
|
vloc &= j; |
| 70 |
|
} |
| 71 |
|
if (vout == 0) /* all inside */ |
| 72 |
< |
return(2); |
| 72 |
> |
return(O_IN); |
| 73 |
|
if (vout < 8) /* some inside */ |
| 74 |
< |
return(1); |
| 74 |
> |
return(O_HIT); |
| 75 |
|
if (vloc) /* all to one side */ |
| 76 |
< |
return(0); |
| 76 |
> |
return(O_MISS); |
| 77 |
|
/* octree vertices in cube? */ |
| 78 |
|
for (j = 0; j < 3; j++) |
| 79 |
|
cumax[j] = (cumin[j] = cu->cuorg[j]) + cu->cusize; |
| 80 |
|
vloc = ABOVE | BELOW; |
| 81 |
|
for (i = 0; i < 8; i++) { |
| 82 |
|
for (j = 0; j < 3; j++) { |
| 83 |
< |
v1[j] = in->obj->scube.cuorg[j]; |
| 83 |
> |
v1[j] = cu1->cuorg[j]; |
| 84 |
|
if (i & 1<<j) |
| 85 |
< |
v1[j] += in->obj->scube.cusize; |
| 85 |
> |
v1[j] += cu1->cusize; |
| 86 |
|
} |
| 87 |
< |
multp3(vert[i], v1, in->f.xfm); |
| 88 |
< |
if (j = plocate(vert[i], cumin, cumax)) |
| 87 |
> |
multp3(vert[i], v1, fxf->f.xfm); |
| 88 |
> |
if ( (j = plocate(vert[i], cumin, cumax)) ) |
| 89 |
|
vloc &= j; |
| 90 |
|
else |
| 91 |
< |
return(1); /* vertex inside */ |
| 91 |
> |
return(O_HIT); /* vertex inside */ |
| 92 |
|
} |
| 93 |
|
if (vloc) /* all to one side */ |
| 94 |
< |
return(0); |
| 94 |
> |
return(O_MISS); |
| 95 |
|
/* check edges */ |
| 96 |
|
for (i = 0; i < 4; i++) |
| 97 |
|
for (j = 0; j < 3; j++) { |
| 99 |
|
VCOPY(v1, vert[vstart[i]]); |
| 100 |
|
VCOPY(v2, vert[vstart[i] ^ 1<<j]); |
| 101 |
|
if (clip(v1, v2, cumin, cumax)) |
| 102 |
< |
return(1); /* edge inside */ |
| 102 |
> |
return(O_HIT); /* edge inside */ |
| 103 |
|
} |
| 104 |
|
|
| 105 |
< |
return(0); /* no intersection */ |
| 105 |
> |
return(O_MISS); /* no intersection */ |
| 106 |
> |
} |
| 107 |
> |
|
| 108 |
> |
|
| 109 |
> |
int |
| 110 |
> |
o_instance(o, cu) /* determine if instance intersects */ |
| 111 |
> |
OBJREC *o; |
| 112 |
> |
CUBE *cu; |
| 113 |
> |
{ |
| 114 |
> |
INSTANCE *ins; |
| 115 |
> |
/* get octree bounds */ |
| 116 |
> |
ins = getinstance(o, IO_BOUNDS); |
| 117 |
> |
/* call o_cube to do the work */ |
| 118 |
> |
return(o_cube(&ins->obj->scube, &ins->x, cu)); |
| 119 |
> |
} |
| 120 |
> |
|
| 121 |
> |
|
| 122 |
> |
int |
| 123 |
> |
o_mesh(o, cu) /* determine if mesh intersects */ |
| 124 |
> |
OBJREC *o; |
| 125 |
> |
CUBE *cu; |
| 126 |
> |
{ |
| 127 |
> |
MESHINST *mip; |
| 128 |
> |
/* get mesh bounds */ |
| 129 |
> |
mip = getmeshinst(o, IO_BOUNDS); |
| 130 |
> |
/* call o_cube to do the work */ |
| 131 |
> |
return(o_cube(&mip->msh->mcube, &mip->x, cu)); |
| 132 |
|
} |