1 |
– |
/* Copyright (c) 1991 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; |
45 |
< |
CUBE *cu; |
43 |
> |
static int o_cube(CUBE *cu1, FULLXF *fxf, CUBE *cu); |
44 |
> |
|
45 |
> |
|
46 |
> |
static int |
47 |
> |
o_cube( /* determine if cubes intersect */ |
48 |
> |
CUBE *cu1, |
49 |
> |
FULLXF *fxf, |
50 |
> |
CUBE *cu |
51 |
> |
) |
52 |
|
{ |
53 |
|
static int vstart[4] = {0, 3, 5, 6}; |
54 |
|
FVECT cumin, cumax; |
55 |
|
FVECT vert[8]; |
56 |
|
FVECT v1, v2; |
52 |
– |
register INSTANCE *in; |
57 |
|
int vloc, vout; |
58 |
|
register int i, j; |
55 |
– |
/* get octree arguments */ |
56 |
– |
in = getinstance(o, IO_BOUNDS); |
59 |
|
/* check if cube vertex in octree */ |
60 |
|
for (j = 0; j < 3; j++) |
61 |
< |
cumax[j] = (cumin[j] = in->obj->scube.cuorg[j]) + |
60 |
< |
in->obj->scube.cusize; |
61 |
> |
cumax[j] = (cumin[j] = cu1->cuorg[j]) + cu1->cusize; |
62 |
|
vloc = ABOVE | BELOW; |
63 |
|
vout = 0; |
64 |
|
for (i = 0; i < 8; i++) { |
67 |
|
if (i & 1<<j) |
68 |
|
v1[j] += cu->cusize; |
69 |
|
} |
70 |
< |
multp3(v2, v1, in->x.b.xfm); |
71 |
< |
if (j = plocate(v2, cumin, cumax)) |
70 |
> |
multp3(v2, v1, fxf->b.xfm); |
71 |
> |
if ( (j = plocate(v2, cumin, cumax)) ) |
72 |
|
vout++; |
73 |
|
vloc &= j; |
74 |
|
} |
84 |
|
vloc = ABOVE | BELOW; |
85 |
|
for (i = 0; i < 8; i++) { |
86 |
|
for (j = 0; j < 3; j++) { |
87 |
< |
v1[j] = in->obj->scube.cuorg[j]; |
87 |
> |
v1[j] = cu1->cuorg[j]; |
88 |
|
if (i & 1<<j) |
89 |
< |
v1[j] += in->obj->scube.cusize; |
89 |
> |
v1[j] += cu1->cusize; |
90 |
|
} |
91 |
< |
multp3(vert[i], v1, in->x.f.xfm); |
92 |
< |
if (j = plocate(vert[i], cumin, cumax)) |
91 |
> |
multp3(vert[i], v1, fxf->f.xfm); |
92 |
> |
if ( (j = plocate(vert[i], cumin, cumax)) ) |
93 |
|
vloc &= j; |
94 |
|
else |
95 |
|
return(O_HIT); /* vertex inside */ |
107 |
|
} |
108 |
|
|
109 |
|
return(O_MISS); /* no intersection */ |
110 |
+ |
} |
111 |
+ |
|
112 |
+ |
|
113 |
+ |
/* XXX o_instance() is extern, but not declared in any header file */ |
114 |
+ |
int |
115 |
+ |
o_instance( /* determine if instance intersects */ |
116 |
+ |
OBJREC *o, |
117 |
+ |
CUBE *cu |
118 |
+ |
) |
119 |
+ |
{ |
120 |
+ |
INSTANCE *ins; |
121 |
+ |
/* get octree bounds */ |
122 |
+ |
ins = getinstance(o, IO_BOUNDS); |
123 |
+ |
/* call o_cube to do the work */ |
124 |
+ |
return(o_cube(&ins->obj->scube, &ins->x, cu)); |
125 |
+ |
} |
126 |
+ |
|
127 |
+ |
|
128 |
+ |
/* XXX o_mesh() is extern, but not declared in any header file */ |
129 |
+ |
int |
130 |
+ |
o_mesh( /* determine if mesh intersects */ |
131 |
+ |
OBJREC *o, |
132 |
+ |
CUBE *cu |
133 |
+ |
) |
134 |
+ |
{ |
135 |
+ |
MESHINST *mip; |
136 |
+ |
/* get mesh bounds */ |
137 |
+ |
mip = getmeshinst(o, IO_BOUNDS); |
138 |
+ |
/* call o_cube to do the work */ |
139 |
+ |
return(o_cube(&mip->msh->mcube, &mip->x, cu)); |
140 |
|
} |