Shadowrun: Awakened 29 September 2011 - Build 871
Defines | Functions | Variables
sphere.cpp File Reference
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
#include "sphere.h"
Include dependency graph for sphere.cpp:

Go to the source code of this file.

Defines

#define SPHERE_PRIVATE

Functions

objectnewsphere (void *tex, vector ctr, flt rad)
static int sphere_bbox (void *obj, vector *min, vector *max)
static void sphere_intersect (sphere *spr, ray *ry)
static void sphere_normal (sphere *spr, vector *pnt, ray *incident, vector *N)

Variables

static object_methods sphere_methods

Define Documentation

#define SPHERE_PRIVATE

Definition at line 71 of file sphere.cpp.


Function Documentation

object* newsphere ( void *  tex,
vector  ctr,
flt  rad 
)

Definition at line 81 of file sphere.cpp.

References rt_getmem(), test::s, and sphere_methods.

Referenced by rt_sphere().

                                                    {
  sphere * s;
  
  s=(sphere *) rt_getmem(sizeof(sphere));
  memset(s, 0, sizeof(sphere));
  s->methods = &sphere_methods;

  s->tex=(texture *)tex;
  s->ctr=ctr;
  s->rad=rad;

  return (object *) s;
}
static int sphere_bbox ( void *  obj,
vector min,
vector max 
) [static]

Definition at line 95 of file sphere.cpp.

References test::s, vector::x, vector::y, and vector::z.

                                                               {
  sphere * s = (sphere *) obj;

  min->x = s->ctr.x - s->rad;
  min->y = s->ctr.y - s->rad;
  min->z = s->ctr.z - s->rad;
  max->x = s->ctr.x + s->rad;
  max->y = s->ctr.y + s->rad;
  max->z = s->ctr.z + s->rad;

  return 1;
}
static void sphere_intersect ( sphere *  spr,
ray ry 
) [static]

Definition at line 108 of file sphere.cpp.

References add_intersection(), ray::d, ray::o, SPEPSILON, V, VDOT, and VSUB.

                                                     {
  flt b, disc, t1, t2, temp;
  vector V;

  VSUB(spr->ctr, ry->o, V);
  VDOT(b, V, ry->d); 
  VDOT(temp, V, V);  

  disc=b*b + spr->rad*spr->rad - temp;

  if (disc<=0.0) return;
  disc=sqrt(disc);

  t2=b+disc;
  if (t2 <= SPEPSILON) 
    return;
  add_intersection(t2, (object *) spr, ry);  

  t1=b-disc;
  if (t1 > SPEPSILON) 
    add_intersection(t1, (object *) spr, ry);  
}
static void sphere_normal ( sphere *  spr,
vector pnt,
ray incident,
vector N 
) [static]

Definition at line 131 of file sphere.cpp.

References ray::d, VDot(), VNorm(), VSub(), vector::x, vector::y, and vector::z.

                                                                                  {
  VSub((vector *) pnt, &(spr->ctr), N);

  VNorm(N);

  if (VDot(N, &(incident->d)) > 0.0)  {
    N->x=-N->x;
    N->y=-N->y;
    N->z=-N->z;
  } 
}

Variable Documentation

Initial value:
 {
  (void (*)(void *, void *))(sphere_intersect),
  (void (*)(void *, void *, void *, void *))(sphere_normal),
  sphere_bbox, 
  free 
}

Definition at line 74 of file sphere.cpp.

Referenced by newsphere().


Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net