Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5869 in orxonox.OLD for branches/collision_detection/src


Ignore:
Timestamp:
Dec 2, 2005, 12:17:35 PM (19 years ago)
Author:
patrick
Message:

collision_detection: adjusted the box splitting algorithm

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/collision_detection/src/lib/collision_detection/obb_tree_node.cc

    r5868 r5869  
    1818#include "obb_tree_node.h"
    1919#include "list.h"
     20#include <list>
    2021#include "obb.h"
    2122#include "obb_tree.h"
     
    373374
    374375  /*
    375   this step is split up in two: first there will be made a bounding box which is
    376   very badly centered. In the secon step there will be calculated a new center
     376  this step is split up in three: first there will be made a bounding box which is
     377  very badly centered. In the section step there will be calculated a new center
    377378  and a better bounding box.
    378379  */
     
    494495
    495496/**
    496   \brief this separates an ob-box in the middle
    497 * @param box: the box to separate
    498 
    499   this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis
     497 * this separates an ob-box in the middle
     498 * @param box: the box to separate
     499 *
     500 * this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis
    500501 */
    501502void OBBTreeNode::forkBox(OBB& box)
    502503{
     504
    503505  /* get the longest axis of the box */
    504506  float               aLength = -1.0f;                     //!< the length of the longest axis
     
    540542  the points depending on which side they are located
    541543  */
    542   tList<const sVec3D>      partition1;                           //!< the vertex partition 1
    543   tList<const sVec3D>      partition2;                           //!< the vertex partition 2
     544  std::list<const sVec3D*> partition1;                           //!< the vertex partition 1
     545  std::list<const sVec3D*> partition2;                           //!< the vertex partition 2
     546
     547
     548  //nameList.push_back("Pumba");
     549  //nameList.push_back("Mogli");
     550  //nameList.push_back("Timon");
     551
     552//   std::list<char*>::iterator element;
     553//   for (element = nameList.begin(); element != nameList.end(); element++)
     554//   {
     555//     PRINTF(3)("found name: %s in list\n", (*name));
     556//   }
     557
    544558
    545559
     
    555569    tmpDist = this->separationPlane.distancePoint(box.vertices[i]);
    556570    if( tmpDist > 0.0)
    557       partition1.add(&box.vertices[i]); /* positive numbers plus zero */
     571      partition1.push_back(&box.vertices[i]); /* positive numbers plus zero */
    558572    else
    559       partition2.add(&box.vertices[i]); /* negatice numbers */
    560   }
    561   partition1.add(&box.vertices[vertexIndex]);
    562   partition2.add(&box.vertices[vertexIndex]);
    563 
    564   PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize());
     573      partition2.push_back(&box.vertices[i]); /* negatice numbers */
     574  }
     575  partition1.push_back(&box.vertices[vertexIndex]);
     576  partition2.push_back(&box.vertices[vertexIndex]);
     577
     578  PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.size(), partition2.size());
    565579
    566580
    567581  /* now comes the separation into two different sVec3D arrays */
    568582  tIterator<const sVec3D>* iterator;                       //!< the iterator to go through the lists
    569   const sVec3D*      element;                              //!< the elements
    570583  int                index;                                //!< index storage place
    571584  sVec3D*            vertList1;                            //!< the vertex list 1
    572585  sVec3D*            vertList2;                            //!< the vertex list 2
    573 
    574   vertList1 = new sVec3D[partition1.getSize()];
    575   vertList2 = new sVec3D[partition2.getSize()];
    576 
    577   iterator = partition1.getIterator();
    578   element = iterator->firstElement();
    579   index = 0;
    580   while( element != NULL)
    581   {
    582     vertList1[index][0] = element[0][0];
    583     vertList1[index][1] = element[0][1];
    584     vertList1[index][2] = element[0][2];
     586  std::list<const sVec3D*>::iterator element;              //!< the list iterator
     587
     588  vertList1 = new sVec3D[partition1.size()];
     589  vertList2 = new sVec3D[partition2.size()];
     590
     591
     592  for(element = partition1.begin(), index = 0; element != partition1.end(); element++, index++)
     593  {
     594    vertList1[index][0] = (*element)[0][0];
     595    vertList1[index][1] = (*element)[0][1];
     596    vertList1[index][2] = (*element)[0][2];
    585597    ++index;
    586     element = iterator->nextElement();
    587   }
    588   delete iterator;
     598  }
     599
    589600  //   PRINTF(0)("\npartition 1:\n");
    590601  //   for(int i = 0; i < partition1.getSize(); ++i)
     
    593604  //   }
    594605
    595   iterator = partition2.getIterator();
    596   element = iterator->firstElement();
    597   index = 0;
    598   while( element != NULL)
    599   {
    600     vertList2[index][0] = element[0][0];
    601     vertList2[index][1] = element[0][1];
    602     vertList2[index][2] = element[0][2];
    603     ++index;
    604     element = iterator->nextElement();
     606
     607  //for (element = nameList.begin(); element != nameList.end(); element++)
     608//   iterator = partition2.getIterator();
     609//   element = iterator->firstElement();
     610
     611  for(element = partition2.begin(), index = 0; element != partition2.end(); element++, index++)
     612  {
     613    vertList2[index][0] = (*element)[0][0];
     614    vertList2[index][1] = (*element)[0][1];
     615    vertList2[index][2] = (*element)[0][2];
    605616  }
    606617
     
    611622    delete[] this->tmpVert2;
    612623  this->tmpVert2 = vertList2;
    613   this->tmpLen1 = partition1.getSize();
    614   this->tmpLen2 = partition2.getSize();
    615 
    616   delete iterator;
     624  this->tmpLen1 = partition1.size();
     625  this->tmpLen2 = partition2.size();
     626
    617627
    618628  //   PRINTF(0)("\npartition 2:\n");
Note: See TracChangeset for help on using the changeset viewer.