| 1 |
– |
/* Copyright (c) 1986 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_face.c - routines for creating octrees for polygonal faces. |
| 6 |
|
* |
| 51 |
|
/* get face arguments */ |
| 52 |
|
f = getface(o); |
| 53 |
|
if (f->area == 0.0) /* empty face */ |
| 54 |
< |
return(0); |
| 54 |
> |
return(O_MISS); |
| 55 |
|
/* compute cube boundaries */ |
| 56 |
|
for (j = 0; j < 3; j++) |
| 57 |
< |
cumax[j] = (cumin[j] = cu->cuorg[j]) + cu->cusize; |
| 57 |
> |
cumax[j] = (cumin[j] = cu->cuorg[j]-FTINY) |
| 58 |
> |
+ cu->cusize + 2.0*FTINY; |
| 59 |
|
|
| 60 |
|
vloc = ABOVE | BELOW; /* check vertices */ |
| 61 |
|
for (i = 0; i < f->nv; i++) |
| 62 |
|
if (j = plocate(VERTEX(f,i), cumin, cumax)) |
| 63 |
|
vloc &= j; |
| 64 |
|
else |
| 65 |
< |
return(1); /* vertex inside */ |
| 65 |
> |
return(O_HIT); /* vertex inside */ |
| 66 |
|
|
| 67 |
|
if (vloc) /* all to one side */ |
| 68 |
< |
return(0); |
| 68 |
> |
return(O_MISS); |
| 69 |
|
|
| 70 |
|
for (i = 0; i < f->nv; i++) { /* check edges */ |
| 71 |
|
if ((j = i + 1) >= f->nv) |
| 73 |
|
VCOPY(v1, VERTEX(f,i)); /* clip modifies */ |
| 74 |
|
VCOPY(v2, VERTEX(f,j)); /* the vertices! */ |
| 75 |
|
if (clip(v1, v2, cumin, cumax)) |
| 76 |
< |
return(1); /* edge inside */ |
| 76 |
> |
return(O_HIT); /* edge inside */ |
| 77 |
|
} |
| 78 |
|
/* see if cube cuts plane */ |
| 79 |
|
for (j = 0; j < 3; j++) |
| 84 |
|
v1[j] = cumax[j]; |
| 85 |
|
v2[j] = cumin[j]; |
| 86 |
|
} |
| 87 |
< |
if ((d1 = DOT(v1, f->norm) - f->const) > FTINY) |
| 88 |
< |
return(0); |
| 89 |
< |
if ((d2 = DOT(v2, f->norm) - f->const) < -FTINY) |
| 90 |
< |
return(0); |
| 87 |
> |
if ((d1 = DOT(v1, f->norm) - f->offset) > FTINY) |
| 88 |
> |
return(O_MISS); |
| 89 |
> |
if ((d2 = DOT(v2, f->norm) - f->offset) < -FTINY) |
| 90 |
> |
return(O_MISS); |
| 91 |
|
/* intersect face */ |
| 92 |
|
for (j = 0; j < 3; j++) |
| 93 |
|
v1[j] = (v1[j]*d2 - v2[j]*d1)/(d2 - d1); |
| 94 |
|
if (inface(v1, f)) |
| 95 |
< |
return(1); |
| 95 |
> |
return(O_HIT); |
| 96 |
|
|
| 97 |
< |
return(0); /* no intersection */ |
| 97 |
> |
return(O_MISS); /* no intersection */ |
| 98 |
|
} |