| 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 |
|
* sphere.c - routines for creating octrees for spheres. |
| 6 |
|
* |
| 50 |
|
*/ |
| 51 |
|
|
| 52 |
|
|
| 53 |
< |
o_sphere(o, cu) /* determine if sphere intersects cube */ |
| 54 |
< |
OBJREC *o; |
| 55 |
< |
register CUBE *cu; |
| 53 |
> |
int |
| 54 |
> |
o_sphere( /* determine if sphere intersects cube */ |
| 55 |
> |
OBJREC *o, |
| 56 |
> |
CUBE *cu |
| 57 |
> |
) |
| 58 |
|
{ |
| 59 |
|
FVECT v1; |
| 60 |
|
double d1, d2; |
| 61 |
< |
register double *fa; |
| 62 |
< |
register int i; |
| 61 |
> |
RREAL *fa; |
| 62 |
> |
int i; |
| 63 |
|
#define cent fa |
| 64 |
|
#define rad fa[3] |
| 65 |
|
/* get arguments */ |
| 66 |
+ |
if (o->oargs.nfargs != 4) |
| 67 |
+ |
objerror(o, USER, "bad # arguments"); |
| 68 |
|
fa = o->oargs.farg; |
| 69 |
< |
if (o->oargs.nfargs != 4 || rad <= FTINY) |
| 70 |
< |
objerror(o, USER, "bad arguments"); |
| 69 |
> |
if (rad < -FTINY) { |
| 70 |
> |
objerror(o, WARNING, "negative radius"); |
| 71 |
> |
o->otype = o->otype == OBJ_SPHERE ? |
| 72 |
> |
OBJ_BUBBLE : OBJ_SPHERE; |
| 73 |
> |
rad = -rad; |
| 74 |
> |
} else if (rad <= FTINY) { |
| 75 |
> |
objerror(o, WARNING, "zero radius"); |
| 76 |
> |
return(O_MISS); |
| 77 |
> |
} |
| 78 |
|
|
| 79 |
|
d1 = ROOT3/2.0 * cu->cusize; /* bounding radius for cube */ |
| 80 |
|
|
| 84 |
|
d2 = DOT(v1,v1); |
| 85 |
|
|
| 86 |
|
if (d2 > (rad+d1+FTINY)*(rad+d1+FTINY)) /* quick test */ |
| 87 |
< |
return(0); /* cube outside */ |
| 87 |
> |
return(O_MISS); /* cube outside */ |
| 88 |
|
|
| 89 |
|
/* check sphere interior */ |
| 90 |
|
if (d1 < rad) { |
| 91 |
|
if (d2 < (rad-d1-FTINY)*(rad-d1-FTINY)) |
| 92 |
< |
return(0); /* cube inside sphere */ |
| 92 |
> |
return(O_MISS); /* cube inside sphere */ |
| 93 |
|
if (d2 < (rad+FTINY)*(rad+FTINY)) |
| 94 |
< |
return(1); /* cube center inside */ |
| 94 |
> |
return(O_HIT); /* cube center inside */ |
| 95 |
|
} |
| 96 |
|
/* find closest distance */ |
| 97 |
|
for (i = 0; i < 3; i++) |
| 103 |
|
v1[i] = 0; |
| 104 |
|
/* final intersection check */ |
| 105 |
|
if (DOT(v1,v1) <= (rad+FTINY)*(rad+FTINY)) |
| 106 |
< |
return(1); |
| 106 |
> |
return(O_HIT); |
| 107 |
|
else |
| 108 |
< |
return(0); |
| 108 |
> |
return(O_MISS); |
| 109 |
|
} |