Back to index

radiance  4R0+20100331
Defines | Functions | Variables
sphere.c File Reference
#include "standard.h"
#include "octree.h"
#include "object.h"
#include "otypes.h"

Go to the source code of this file.

Defines

#define ROOT3   1.732050808
#define cent   fa
#define rad   fa[3]

Functions

int o_sphere (OBJREC *o, register CUBE *cu)

Variables

static const char RCSid [] = "$Id: sphere.c,v 2.5 2004/03/30 16:13:00 schorsch Exp $"

Define Documentation

#define cent   fa
#define rad   fa[3]
#define ROOT3   1.732050808

Definition at line 18 of file sphere.c.


Function Documentation

int o_sphere ( OBJREC o,
register CUBE cu 
)

Definition at line 54 of file sphere.c.

{
       FVECT  v1;
       double  d1, d2;
       register RREAL  *fa;
       register int  i;
#define  cent        fa
#define  rad         fa[3]
                                   /* get arguments */
       if (o->oargs.nfargs != 4)
              objerror(o, USER, "bad # arguments");
       fa = o->oargs.farg;
       if (rad < -FTINY) {
              objerror(o, WARNING, "negative radius");
              o->otype = o->otype == OBJ_SPHERE ?
                            OBJ_BUBBLE : OBJ_SPHERE;
              rad = -rad;
       } else if (rad <= FTINY)
              objerror(o, USER, "zero radius");

       d1 = ROOT3/2.0 * cu->cusize;       /* bounding radius for cube */

       d2 = cu->cusize * 0.5;             /* get distance between centers */
       for (i = 0; i < 3; i++)
              v1[i] = cu->cuorg[i] + d2 - cent[i];
       d2 = DOT(v1,v1);

       if (d2 > (rad+d1+FTINY)*(rad+d1+FTINY))   /* quick test */
              return(O_MISS);                    /* cube outside */
       
                                   /* check sphere interior */
       if (d1 < rad) {
              if (d2 < (rad-d1-FTINY)*(rad-d1-FTINY))
                     return(O_MISS);             /* cube inside sphere */
              if (d2 < (rad+FTINY)*(rad+FTINY))
                     return(O_HIT);              /* cube center inside */
       }
                                   /* find closest distance */
       for (i = 0; i < 3; i++)
              if (cent[i] < cu->cuorg[i])
                     v1[i] = cu->cuorg[i] - cent[i];
              else if (cent[i] > cu->cuorg[i] + cu->cusize)
                     v1[i] = cent[i] - (cu->cuorg[i] + cu->cusize);
              else
                     v1[i] = 0;
                                   /* final intersection check */
       if (DOT(v1,v1) <= (rad+FTINY)*(rad+FTINY))
              return(O_HIT);
       else
              return(O_MISS);
}

Here is the call graph for this function:


Variable Documentation

const char RCSid[] = "$Id: sphere.c,v 2.5 2004/03/30 16:13:00 schorsch Exp $" [static]

Definition at line 2 of file sphere.c.