| 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_cone.c - routines for intersecting cubes with cones. |
| 6 |
|
* |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
|
#include "standard.h" |
| 14 |
– |
|
| 11 |
|
#include "octree.h" |
| 16 |
– |
|
| 12 |
|
#include "object.h" |
| 18 |
– |
|
| 13 |
|
#include "cone.h" |
| 14 |
|
|
| 15 |
|
#define ROOT3 1.732050808 |
| 29 |
|
|
| 30 |
|
extern double mincusize; /* minimum cube size */ |
| 31 |
|
|
| 32 |
+ |
static double findcseg(FVECT ep0, FVECT ep1, CONE *co, FVECT p); |
| 33 |
|
|
| 34 |
< |
o_cone(o, cu) /* determine if cone intersects cube */ |
| 35 |
< |
OBJREC *o; |
| 36 |
< |
register CUBE *cu; |
| 34 |
> |
|
| 35 |
> |
|
| 36 |
> |
extern int |
| 37 |
> |
o_cone( /* determine if cone intersects cube */ |
| 38 |
> |
OBJREC *o, |
| 39 |
> |
register CUBE *cu |
| 40 |
> |
) |
| 41 |
|
{ |
| 43 |
– |
double dist2lseg(), findcseg(); |
| 42 |
|
CONE *co; |
| 43 |
|
FVECT ep0, ep1; |
| 44 |
+ |
#ifdef STRICT |
| 45 |
|
FVECT cumin, cumax; |
| 46 |
|
CUBE cukid; |
| 47 |
+ |
register int j; |
| 48 |
+ |
#endif |
| 49 |
|
double r; |
| 50 |
|
FVECT p; |
| 51 |
< |
register int i, j; |
| 51 |
> |
register int i; |
| 52 |
|
/* get cone arguments */ |
| 53 |
|
co = getcone(o, 0); |
| 54 |
|
/* get cube center */ |
| 60 |
|
if (findcseg(ep0, ep1, co, p) > 0.0) { |
| 61 |
|
/* check min. distance to cone */ |
| 62 |
|
if (dist2lseg(p, ep0, ep1) > (r+FTINY)*(r+FTINY)) |
| 63 |
< |
return(0); |
| 63 |
> |
return(O_MISS); |
| 64 |
|
#ifdef STRICT |
| 65 |
|
/* get cube boundaries */ |
| 66 |
|
for (i = 0; i < 3; i++) |
| 67 |
|
cumax[i] = (cumin[i] = cu->cuorg[i]) + cu->cusize; |
| 68 |
|
/* closest segment intersects? */ |
| 69 |
|
if (clip(ep0, ep1, cumin, cumax)) |
| 70 |
< |
return(1); |
| 70 |
> |
return(O_HIT); |
| 71 |
|
} |
| 72 |
|
/* check sub-cubes */ |
| 73 |
|
cukid.cusize = cu->cusize * 0.5; |
| 74 |
|
if (cukid.cusize < mincusize) |
| 75 |
< |
return(1); /* cube too small */ |
| 75 |
> |
return(O_HIT); /* cube too small */ |
| 76 |
|
cukid.cutree = EMPTY; |
| 77 |
|
|
| 78 |
|
for (j = 0; j < 8; j++) { |
| 82 |
|
cukid.cuorg[i] += cukid.cusize; |
| 83 |
|
} |
| 84 |
|
if (o_cone(o, &cukid)) |
| 85 |
< |
return(1); /* sub-cube intersects */ |
| 85 |
> |
return(O_HIT); /* sub-cube intersects */ |
| 86 |
|
} |
| 87 |
< |
return(0); /* no intersection */ |
| 87 |
> |
return(O_MISS); /* no intersection */ |
| 88 |
|
#else |
| 89 |
|
} |
| 90 |
< |
return(1); /* assume intersection */ |
| 90 |
> |
return(O_HIT); /* assume intersection */ |
| 91 |
|
#endif |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
|
| 95 |
< |
double |
| 96 |
< |
findcseg(ep0, ep1, co, p) /* find line segment from cone closest to p */ |
| 97 |
< |
FVECT ep0, ep1; |
| 98 |
< |
register CONE *co; |
| 99 |
< |
FVECT p; |
| 95 |
> |
static double |
| 96 |
> |
findcseg( /* find line segment from cone closest to p */ |
| 97 |
> |
FVECT ep0, |
| 98 |
> |
FVECT ep1, |
| 99 |
> |
register CONE *co, |
| 100 |
> |
FVECT p |
| 101 |
> |
) |
| 102 |
|
{ |
| 103 |
|
double d; |
| 104 |
|
FVECT v; |