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

Go to the source code of this file.

Defines

#define BNDBOX_PRIVATE

Functions

static int bndbox_bbox (void *obj, vector *min, vector *max)
static void bndbox_intersect (bndbox *bx, ray *ry)
static void free_bndbox (void *v)
bndboxnewbndbox (vector min, vector max)

Variables

static object_methods bndbox_methods

Define Documentation

#define BNDBOX_PRIVATE

Definition at line 71 of file bndbox.cpp.


Function Documentation

static int bndbox_bbox ( void *  obj,
vector min,
vector max 
) [static]

Definition at line 98 of file bndbox.cpp.

References bndbox::max, and bndbox::min.

                                                               {
  bndbox * b = (bndbox *) obj;

  *min = b->min;
  *max = b->max;

  return 1;
}
static void bndbox_intersect ( bndbox bx,
ray ry 
) [static]

Definition at line 117 of file bndbox.cpp.

References ray::d, ray::e, EPSILON, FHUGE, ray::flags, object_methods::intersect, bndbox::max, object::methods, bndbox::min, object::nextobj, ray::o, mission1::obj, bndbox::objlist, RAYPNT, RT_RAY_BOUNDED, ray::s, vector::x, vector::y, and vector::z.

                                                    {
  flt a, tx1, tx2, ty1, ty2, tz1, tz2;
  flt tnear, tfar;
  object * obj;
  ray newray; 

  /* eliminate bounded rays whose bounds do not intersect  */
  /* the bounds of the box..                               */
  if (ry->flags |= RT_RAY_BOUNDED) {
    if ((ry->s.x > bx->max.x) && (ry->e.x > bx->max.x)) return;
    if ((ry->s.x < bx->min.x) && (ry->e.x < bx->min.x)) return;
  
    if ((ry->s.y > bx->max.y) && (ry->e.y > bx->max.y)) return;
    if ((ry->s.y < bx->min.y) && (ry->e.y < bx->min.y)) return;

    if ((ry->s.z > bx->max.z) && (ry->e.z > bx->max.z)) return;
    if ((ry->s.z < bx->min.z) && (ry->e.z < bx->min.z)) return;
  }

  tnear= -FHUGE;
  tfar= FHUGE;

  if (ry->d.x == 0.0) {
    if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return;
  }
  else { 
    tx1 = (bx->min.x - ry->o.x) / ry->d.x;
    tx2 = (bx->max.x - ry->o.x) / ry->d.x;
    if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; } 
    if (tx1 > tnear) tnear=tx1;   
    if (tx2 < tfar)   tfar=tx2;   
  }  
  if (tnear > tfar) return; 
  if (tfar < 0.0) return;
  
  if (ry->d.y == 0.0) { 
    if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return;
  }
  else { 
    ty1 = (bx->min.y - ry->o.y) / ry->d.y;
    ty2 = (bx->max.y - ry->o.y) / ry->d.y;
    if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; } 
    if (ty1 > tnear) tnear=ty1;   
    if (ty2 < tfar)   tfar=ty2;   
  } 
  if (tnear > tfar) return; 
  if (tfar < 0.0) return;
 
  if (ry->d.z == 0.0) { 
    if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return;
  }
  else { 
    tz1 = (bx->min.z - ry->o.z) / ry->d.z;
    tz2 = (bx->max.z - ry->o.z) / ry->d.z;
    if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; } 
    if (tz1 > tnear) tnear=tz1;   
    if (tz2 < tfar)   tfar=tz2;   
  } 
  if (tnear > tfar) return; 
  if (tfar < 0.0) return;


  /* intersect all of the enclosed objects */
  newray=*ry;
  newray.flags |= RT_RAY_BOUNDED;

  RAYPNT(newray.s , (*ry) , tnear); 
  RAYPNT(newray.e , (*ry) , (tfar + EPSILON)); 
 
  obj = bx->objlist;
  while (obj != NULL) {
    obj->methods->intersect(obj, &newray); 
    obj = (object *)obj->nextobj;
  }
}
static void free_bndbox ( void *  v) [static]

Definition at line 108 of file bndbox.cpp.

References free_objects(), and bndbox::objlist.

                                  {
  bndbox * b = (bndbox *) v; 

  free_objects(b->objlist);  
 
  free(b);
}
bndbox* newbndbox ( vector  min,
vector  max 
)

Definition at line 82 of file bndbox.cpp.

References bndbox_methods, bndbox::max, bndbox::methods, bndbox::min, bndbox::nextobj, bndbox::objlist, rt_getmem(), and bndbox::tex.

Referenced by dividespace(), and octreespace().

                                           {
  bndbox * b;
  
  b=(bndbox *) rt_getmem(sizeof(bndbox));
  memset(b, 0, sizeof(bndbox));
  b->min=min;
  b->max=max;
  b->methods = &bndbox_methods;

  b->objlist=NULL;
  b->tex=NULL;
  b->nextobj=NULL;
  return b;
}

Variable Documentation

Initial value:
 {
  (void (*)(void *, void *))(bndbox_intersect),
  (void (*)(void *, void *, void *, void *))(NULL),
  bndbox_bbox, 
  free_bndbox 
}

Definition at line 74 of file bndbox.cpp.

Referenced by newbndbox().


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