| 1 |
– |
/* Copyright (c) 1992 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 - compute ray intersection with spheres. |
| 9 |
– |
* |
| 10 |
– |
* 8/19/85 |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
< |
#include "ray.h" |
| 8 |
> |
#include "copyright.h" |
| 9 |
|
|
| 10 |
+ |
#include "ray.h" |
| 11 |
|
#include "otypes.h" |
| 12 |
+ |
#include "rtotypes.h" |
| 13 |
|
|
| 14 |
|
|
| 15 |
< |
o_sphere(so, r) /* compute intersection with sphere */ |
| 16 |
< |
OBJREC *so; |
| 17 |
< |
register RAY *r; |
| 15 |
> |
int |
| 16 |
> |
o_sphere( /* compute intersection with sphere */ |
| 17 |
> |
OBJREC *so, |
| 18 |
> |
RAY *r |
| 19 |
> |
) |
| 20 |
|
{ |
| 21 |
|
double a, b, c; /* coefficients for quadratic equation */ |
| 22 |
|
double root[2]; /* quadratic roots */ |
| 23 |
|
int nroots; |
| 24 |
|
double t; |
| 25 |
< |
register FLOAT *ap; |
| 26 |
< |
register int i; |
| 25 |
> |
RREAL *ap; |
| 26 |
> |
int i; |
| 27 |
|
|
| 28 |
|
if (so->oargs.nfargs != 4) |
| 29 |
|
objerror(so, USER, "bad # arguments"); |
| 63 |
|
break; |
| 64 |
|
if (i >= nroots) |
| 65 |
|
return(0); /* no positive root */ |
| 66 |
+ |
if (rayreject(so, r, t)) |
| 67 |
+ |
return(0); /* previous hit better */ |
| 68 |
|
|
| 68 |
– |
if (t >= r->rot) |
| 69 |
– |
return(0); /* other is closer */ |
| 70 |
– |
|
| 69 |
|
r->ro = so; |
| 70 |
|
r->rot = t; |
| 71 |
|
/* compute normal */ |
| 78 |
|
} |
| 79 |
|
r->rod = -DOT(r->rdir, r->ron); |
| 80 |
|
r->rox = NULL; |
| 81 |
+ |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
| 82 |
+ |
r->uv[0] = r->uv[1] = 0.0; |
| 83 |
|
|
| 84 |
|
return(1); /* hit */ |
| 85 |
|
} |