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

Go to the source code of this file.

Defines

#define OBJBOUND_PRIVATE

Functions

static int countobj (object *root)
void dividespace (int maxoctnodes, object **toplist)
static void globalbound (object **rootlist, vector *gmin, vector *gmax)
static void movenextobj (object *thisobj, object **root)
static int objinside (object *obj, vector *min, vector *max)
static void octreespace (object **rootlist, int maxoctnodes)

Define Documentation

Definition at line 70 of file objbound.cpp.


Function Documentation

static int countobj ( object root) [static]

Definition at line 117 of file objbound.cpp.

References object::nextobj.

Referenced by dividespace(), and octreespace().

                                   {
  object * cur;     /* counts the number of objects on a list */
  int numobj;

  numobj=0;
  cur=root;

  while (cur != NULL) {
    cur=(object *)cur->nextobj;
    numobj++;
  } 
  return numobj;
}
void dividespace ( int  maxoctnodes,
object **  toplist 
)

Definition at line 330 of file objbound.cpp.

References countobj(), globalbound(), newbndbox(), bndbox::nextobj, bndbox::objlist, octreespace(), and bndbox::tex.

                                                    {
  bndbox * gbox;
  vector gmin, gmax;

  if (countobj(*toplist) > maxoctnodes) {
    globalbound(toplist, &gmin, &gmax);  

    octreespace(toplist, maxoctnodes); 

    gbox = newbndbox(gmin, gmax);
    gbox->objlist = NULL;
    gbox->tex = NULL; 
    gbox->nextobj=NULL;
    gbox->objlist=*toplist;
    *toplist=(object *) gbox;  
  }
}
static void globalbound ( object **  rootlist,
vector gmin,
vector gmax 
) [static]

Definition at line 73 of file objbound.cpp.

References object_methods::bbox, FHUGE, object::methods, MYMAX, MYMIN, vector::x, vector::y, and vector::z.

Referenced by dividespace(), and octreespace().

                                                                          {
  vector min, max; 
  object * cur;

  if (*rootlist == NULL)  /* don't bound non-existant objects */
    return;

  gmin->x =  FHUGE;   gmin->y =  FHUGE;   gmin->z =  FHUGE;
  gmax->x = -FHUGE;   gmax->y = -FHUGE;   gmax->z = -FHUGE;

  cur=*rootlist;
  while (cur != NULL)  {  /* Go! */ 
    min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE;
    max.x =  FHUGE; max.y =  FHUGE; max.z =  FHUGE;

    cur->methods->bbox((void *) cur, &min, &max);

    gmin->x = MYMIN( gmin->x , min.x); 
    gmin->y = MYMIN( gmin->y , min.y); 
    gmin->z = MYMIN( gmin->z , min.z); 
  
    gmax->x = MYMAX( gmax->x , max.x); 
    gmax->y = MYMAX( gmax->y , max.y); 
    gmax->z = MYMAX( gmax->z , max.z); 

    cur=(object *)cur->nextobj;
  }
}
static void movenextobj ( object thisobj,
object **  root 
) [static]

Definition at line 131 of file objbound.cpp.

References object::nextobj.

Referenced by octreespace().

                                                          {
  object * cur, * tmp;

  /* move the object after thisobj to the front of the object list  */
  /*   headed by root */
  if (thisobj != NULL) {
    if (thisobj->nextobj != NULL) {
      cur=(object *)thisobj->nextobj;            /* the object to be moved    */
      thisobj->nextobj = cur->nextobj; /* link around the moved obj */
      tmp=*root;                       /* store the root node       */
      cur->nextobj=tmp;                /* attach root to cur        */ 
      *root=cur;                       /* make cur, the new root    */
    }
  }
}
static int objinside ( object obj,
vector min,
vector max 
) [static]

Definition at line 102 of file objbound.cpp.

References object_methods::bbox, object::methods, vector::x, vector::y, and vector::z.

Referenced by octreespace().

                                                               {
  vector omin, omax;

  if (obj == NULL)  /* non-existant object, shouldn't get here */
    return 0;

  if (obj->methods->bbox((void *) obj, &omin, &omax)) {
    if ((min->x <= omin.x) && (min->y <= omin.y) && (min->z <= omin.z) &&
        (max->x >= omax.x) && (max->y >= omax.y) && (max->z >= omax.z)) { 
      return 1;
    }
  }
  return 0;
}
static void octreespace ( object **  rootlist,
int  maxoctnodes 
) [static]

Definition at line 147 of file objbound.cpp.

References countobj(), globalbound(), bndbox::max, bndbox::min, movenextobj(), newbndbox(), bndbox::nextobj, object::nextobj, objinside(), bndbox::objlist, vector::x, vector::y, and vector::z.

Referenced by dividespace().

                                                             {
  object * cur;
  vector gmin, gmax, gctr;
  vector cmin1, cmin2, cmin3, cmin4, cmin5, cmin6, cmin7, cmin8;
  vector cmax1, cmax2, cmax3, cmax4, cmax5, cmax6, cmax7, cmax8;
  bndbox * box1, * box2, * box3, * box4;
  bndbox * box5, * box6, * box7, * box8;
  int skipobj;

  if (*rootlist == NULL)  /* don't subdivide non-existant data */
    return;

  skipobj=0;
  globalbound(rootlist, &gmin, &gmax);  /* find global min and max */

  gctr.x = ((gmax.x - gmin.x) / 2.0) + gmin.x;
  gctr.y = ((gmax.y - gmin.y) / 2.0) + gmin.y;
  gctr.z = ((gmax.z - gmin.z) / 2.0) + gmin.z;

  cmin1=gmin;
  cmax1=gctr;
  box1 = newbndbox(cmin1, cmax1); 

  cmin2=gmin;
  cmin2.x=gctr.x;
  cmax2=gmax;
  cmax2.y=gctr.y;
  cmax2.z=gctr.z;
  box2 = newbndbox(cmin2, cmax2); 

  cmin3=gmin;
  cmin3.y=gctr.y;
  cmax3=gmax;
  cmax3.x=gctr.x;
  cmax3.z=gctr.z;
  box3 = newbndbox(cmin3, cmax3); 

  cmin4=gmin;
  cmin4.x=gctr.x;
  cmin4.y=gctr.y;
  cmax4=gmax;
  cmax4.z=gctr.z;
  box4 = newbndbox(cmin4, cmax4); 

  cmin5=gmin;
  cmin5.z=gctr.z;
  cmax5=gctr;
  cmax5.z=gmax.z;
  box5 = newbndbox(cmin5, cmax5); 

  cmin6=gctr;
  cmin6.y=gmin.y;
  cmax6=gmax;
  cmax6.y=gctr.y;
  box6 = newbndbox(cmin6, cmax6); 

  cmin7=gctr;
  cmin7.x=gmin.x;
  cmax7=gctr;
  cmax7.y=gmax.y;
  cmax7.z=gmax.z;
  box7 = newbndbox(cmin7, cmax7); 

  cmin8=gctr;
  cmax8=gmax;
  box8 = newbndbox(cmin8, cmax8); 

  cur = *rootlist;
  while (cur != NULL)  {  
    if (objinside((object *)cur->nextobj, &cmin1, &cmax1)) {
      movenextobj(cur, &box1->objlist);  
    }  
    else if (objinside((object *)cur->nextobj, &cmin2, &cmax2)) {
      movenextobj(cur, &box2->objlist);  
    }  
    else if (objinside((object *)cur->nextobj, &cmin3, &cmax3)) {
      movenextobj(cur, &box3->objlist);  
    }  
    else if (objinside((object *)cur->nextobj, &cmin4, &cmax4)) {
      movenextobj(cur, &box4->objlist);  
    }  
    else if (objinside((object *)cur->nextobj, &cmin5, &cmax5)) {
      movenextobj(cur, &box5->objlist);  
    }  
    else if (objinside((object *)cur->nextobj, &cmin6, &cmax6)) {
      movenextobj(cur, &box6->objlist);  
    }  
    else if (objinside((object *)cur->nextobj, &cmin7, &cmax7)) {
      movenextobj(cur, &box7->objlist);  
    }  
    else if (objinside((object *)cur->nextobj, &cmin8, &cmax8)) {
      movenextobj(cur, &box8->objlist);  
    }  
    else {
      skipobj++; 
      cur=(object *)cur->nextobj;
    }
  }     

/* new scope, for redefinition of cur, and old */
  { bndbox * cur, * old;
  old=box1;
  cur=box2; 
  if (countobj(cur->objlist) > 0) {
     old->nextobj=cur;
     globalbound(&cur->objlist, &cur->min, &cur->max); 
     old=cur; 
  }      
  cur=box3;
  if (countobj(cur->objlist) > 0) {
     old->nextobj=cur;
     globalbound(&cur->objlist, &cur->min, &cur->max); 
     old=cur; 
  }      
  cur=box4;
  if (countobj(cur->objlist) > 0) {
     old->nextobj=cur;
     globalbound(&cur->objlist, &cur->min, &cur->max); 
     old=cur; 
  }      
  cur=box5;
  if (countobj(cur->objlist) > 0) {
     old->nextobj=cur;
     globalbound(&cur->objlist, &cur->min, &cur->max); 
     old=cur; 
  }      
  cur=box6;
  if (countobj(cur->objlist) > 0) {
     old->nextobj=cur;
     globalbound(&cur->objlist, &cur->min, &cur->max); 
     old=cur; 
  }      
  cur=box7;
  if (countobj(cur->objlist) > 0) {
     old->nextobj=cur;
     globalbound(&cur->objlist, &cur->min, &cur->max); 
     old=cur; 
  }      
  cur=box8;
  if (countobj(cur->objlist) > 0) {
     old->nextobj=cur;
     globalbound(&cur->objlist, &cur->min, &cur->max); 
     old=cur; 
  }      

  old->nextobj=*rootlist;

  if (countobj(box1->objlist) > 0) {
    globalbound(&box1->objlist, &box1->min, &box1->max); 
    *rootlist=(object *) box1;
  }
  else {
    *rootlist=(object *) box1->nextobj;
  }

  } /**** end of special cur and old scope */

  if (countobj(box1->objlist) > maxoctnodes) {
    octreespace(&box1->objlist, maxoctnodes);
  }
  if (countobj(box2->objlist) > maxoctnodes) {
    octreespace(&box2->objlist, maxoctnodes);
  }
  if (countobj(box3->objlist) > maxoctnodes) {
    octreespace(&box3->objlist, maxoctnodes);
  }
  if (countobj(box4->objlist) > maxoctnodes) {
    octreespace(&box4->objlist, maxoctnodes);
  }
  if (countobj(box5->objlist) > maxoctnodes) {
    octreespace(&box5->objlist, maxoctnodes);
  }
  if (countobj(box6->objlist) > maxoctnodes) {
    octreespace(&box6->objlist, maxoctnodes);
  }
  if (countobj(box7->objlist) > maxoctnodes) {
    octreespace(&box7->objlist, maxoctnodes);
  }
  if (countobj(box8->objlist) > maxoctnodes) {
    octreespace(&box8->objlist, maxoctnodes);
  }
}

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