Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5712 in orxonox.OLD


Ignore:
Timestamp:
Nov 22, 2005, 5:49:30 PM (18 years ago)
Author:
patrick
Message:

collision_detection: exchanged box pointer against ref

Location:
branches/collision_detection/src/lib/collision_detection
Files:
2 edited

Legend:

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

    r5711 r5712  
    125125
    126126  /* create the boxes in three steps */
    127   this->calculateBoxCovariance(this->bvElement, modelInf, triangleIndexes, length);
    128   this->calculateBoxEigenvectors(this->bvElement, modelInf, triangleIndexes, length);
    129   this->calculateBoxAxis(this->bvElement, modelInf, triangleIndexes, length);
     127  this->calculateBoxCovariance(*this->bvElement, modelInf, triangleIndexes, length);
     128  this->calculateBoxEigenvectors(*this->bvElement, modelInf, triangleIndexes, length);
     129  this->calculateBoxAxis(*this->bvElement, modelInf, triangleIndexes, length);
    130130
    131131  /* do we need to descent further in the obb tree?*/
    132132  if( likely( this->depth > 0))
    133133  {
    134     this->forkBox(this->bvElement);
     134    this->forkBox(*this->bvElement);
    135135
    136136
     
    218218
    219219
    220 void OBBTreeNode::calculateBoxCovariance(OBB* box, const modelInfo& modelInf,
     220void OBBTreeNode::calculateBoxCovariance(OBB& box, const modelInfo& modelInf,
    221221                                         const int* triangleIndexes, unsigned int length)
    222222{
     
    284284  PRINTF(3)("\nVertex Data:\n");
    285285  for(int i = 0; i < length; i++)
    286     PRINTF(3)(" Vertex[%i]: %f, %f, %f\n", i, box->vertices[i][0], box->vertices[i][1], box->vertices[i][2]);
     286    PRINTF(3)(" Vertex[%i]: %f, %f, %f\n", i, box.vertices[i][0], box.vertices[i][1], box.vertices[i][2]);
    287287  PRINTF(3)("\nOBB Covariance Matrix:\n");
    288288  for(int j = 0; j < 3; ++j) { PRINT(3)(" |"); for(int k = 0; k < 3; ++k) { PRINT(3)(" \b%f ", covariance[j][k]); } PRINT(3)(" |\n"); }
     
    292292  for(int i = 0; i < 3; ++i)
    293293  {
    294     box->covarianceMatrix[i][0] = covariance[i][0];
    295     box->covarianceMatrix[i][1] = covariance[i][1];
    296     box->covarianceMatrix[i][2] = covariance[i][2];
    297   }
    298   box->center = center;
     294    box.covarianceMatrix[i][0] = covariance[i][0];
     295    box.covarianceMatrix[i][1] = covariance[i][1];
     296    box.covarianceMatrix[i][2] = covariance[i][2];
     297  }
     298  box.center = center;
    299299
    300300  PRINTF(3)("-- Written Result to OBB\n");
     
    302302
    303303
    304 void OBBTreeNode::calculateBoxEigenvectors(OBB* box, const modelInfo& modInfo,
     304void OBBTreeNode::calculateBoxEigenvectors(OBB& box, const modelInfo& modInfo,
    305305                                           const int* triangleIndexes, unsigned int length)
    306306{}
    307307
    308 void OBBTreeNode::calculateBoxEigenvectors(OBB* box, const sVec3D* verticesList, unsigned int length)
     308void OBBTreeNode::calculateBoxEigenvectors(OBB& box, const sVec3D* verticesList, unsigned int length)
    309309{
    310310  PRINTF(3)("Calculated attributes1\n");
     
    317317  Vector axis[3];                //!< the references to the obb axis
    318318
    319   Matrix covMat(  box->covarianceMatrix  );
     319  Matrix covMat(  box.covarianceMatrix  );
    320320  covMat.getEigenVectors(axis[0], axis[1], axis[2] );
    321321
     
    343343  axis[1].normalize();
    344344  axis[2].normalize();*/
    345   box->axis[0] = axis[0];
    346   box->axis[1] = axis[1];
    347   box->axis[2] = axis[2];
     345  box.axis[0] = axis[0];
     346  box.axis[1] = axis[1];
     347  box.axis[2] = axis[2];
    348348
    349349//   PRINTF(0)("-- Got Axis\n");
    350350//
    351 //   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[0].x, box->axis[0].y, box->axis[0].z);
    352 //   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[1].x, box->axis[1].y, box->axis[1].z);
    353 //   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[2].x, box->axis[2].y, box->axis[2].z);
    354 }
    355 
    356 
    357 void OBBTreeNode::calculateBoxAxis(OBB* box, const modelInfo& modInfo, const int* triangleIndexes, unsigned int length)
     351//   PRINTF(0)("eigenvector: %f, %f, %f\n", box.axis[0].x, box.axis[0].y, box.axis[0].z);
     352//   PRINTF(0)("eigenvector: %f, %f, %f\n", box.axis[1].x, box.axis[1].y, box.axis[1].z);
     353//   PRINTF(0)("eigenvector: %f, %f, %f\n", box.axis[2].x, box.axis[2].y, box.axis[2].z);
     354}
     355
     356
     357void OBBTreeNode::calculateBoxAxis(OBB& box, const modelInfo& modInfo, const int* triangleIndexes, unsigned int length)
    358358{
    359359  this->calculateBoxAxis(box, (const sVec3D*)modInfo.pVertices, modInfo.numVertices);
     
    362362
    363363
    364 void OBBTreeNode::calculateBoxAxis(OBB* box, const sVec3D* verticesList, unsigned int length)
     364void OBBTreeNode::calculateBoxAxis(OBB& box, const sVec3D* verticesList, unsigned int length)
    365365{
    366366  PRINTF(3)("Calculated attributes3\n");
     
    369369  float               halfLength[3];                         //!< half length of the axis
    370370  float               tmpLength;                             //!< tmp save point for the length
    371   Plane               p0(box->axis[0], box->center);        //!< the axis planes
    372   Plane               p1(box->axis[1], box->center);
    373   Plane               p2(box->axis[2], box->center);
     371  Plane               p0(box.axis[0], box.center);        //!< the axis planes
     372  Plane               p1(box.axis[1], box.center);
     373  Plane               p2(box.axis[2], box.center);
    374374  float               maxLength[3];
    375375  float               minLength[3];
     
    446446       centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f;       // min length is negatie
    447447       newHalfLength[i] = (maxLength[i] - minLength[i]) / 2.0f;      // min length is negative
    448        box->center +=  (box->axis[i] * centerOffset[i]);            // update the new center vector
     448       box.center +=  (box.axis[i] * centerOffset[i]);            // update the new center vector
    449449       halfLength[i] = newHalfLength[i];
    450450     }
     
    452452
    453453
    454   box->halfLength[0] = halfLength[0];
    455   box->halfLength[1] = halfLength[1];
    456   box->halfLength[2] = halfLength[2];
     454  box.halfLength[0] = halfLength[0];
     455  box.halfLength[1] = halfLength[1];
     456  box.halfLength[2] = halfLength[2];
    457457  PRINTF(3)("-- Written Axis to obb\n");
    458458  PRINTF(3)("-- Finished Calculating Attributes\n");
     
    467467  this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis
    468468 */
    469 void OBBTreeNode::forkBox(OBB* box)
     469void OBBTreeNode::forkBox(OBB& box)
    470470{
    471471  /* get the longest axis of the box */
     
    475475  for(int i = 0; i < 3; ++i)
    476476  {
    477     if( aLength < box->halfLength[i])
    478     {
    479       aLength = box->halfLength[i];
     477    if( aLength < box.halfLength[i])
     478    {
     479      aLength = box.halfLength[i];
    480480      axisIndex = i;
    481481    }
     
    489489  float               tmpDist;                             //!< temporary distance
    490490  int                 vertexIndex;
    491   Plane               middlePlane(box->axis[axisIndex], box->center); //!< the middle plane
     491  Plane               middlePlane(box.axis[axisIndex], box.center); //!< the middle plane
    492492
    493493  vertexIndex = 0;
    494   for(int i = 0; i < box->numOfVertices; ++i)
    495   {
    496     tmpDist = fabs(middlePlane.distancePoint(box->vertices[i]));
     494  for(int i = 0; i < box.numOfVertices; ++i)
     495  {
     496    tmpDist = fabs(middlePlane.distancePoint(box.vertices[i]));
    497497    if( tmpDist < dist)
    498498    {
     
    512512
    513513
    514   PRINTF(3)("vertex index: %i, of %i\n", vertexIndex, box->numOfVertices);
    515   this->separationPlane = Plane(box->axis[axisIndex], box->vertices[vertexIndex]);  //!< separation plane
    516   this->sepPlaneCenter = &box->vertices[vertexIndex];
     514  PRINTF(3)("vertex index: %i, of %i\n", vertexIndex, box.numOfVertices);
     515  this->separationPlane = Plane(box.axis[axisIndex], box.vertices[vertexIndex]);  //!< separation plane
     516  this->sepPlaneCenter = &box.vertices[vertexIndex];
    517517  this->longestAxisIndex = axisIndex;
    518518
    519   for(int i = 0; i < box->numOfVertices; ++i)
     519  for(int i = 0; i < box.numOfVertices; ++i)
    520520  {
    521521    if( i == vertexIndex) continue;
    522     tmpDist = this->separationPlane.distancePoint(box->vertices[i]);
     522    tmpDist = this->separationPlane.distancePoint(box.vertices[i]);
    523523    if( tmpDist > 0.0)
    524       partition1.add(&box->vertices[i]); /* positive numbers plus zero */
     524      partition1.add(&box.vertices[i]); /* positive numbers plus zero */
    525525    else
    526       partition2.add(&box->vertices[i]); /* negatice numbers */
    527   }
    528   partition1.add(&box->vertices[vertexIndex]);
    529   partition2.add(&box->vertices[vertexIndex]);
     526      partition2.add(&box.vertices[i]); /* negatice numbers */
     527  }
     528  partition1.add(&box.vertices[vertexIndex]);
     529  partition2.add(&box.vertices[vertexIndex]);
    530530
    531531  PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize());
  • branches/collision_detection/src/lib/collision_detection/obb_tree_node.h

    r5705 r5712  
    3131    /*  this function returns the bounding volume of this tree node @return: returns the BV */
    3232    virtual inline const BoundingVolume* getBV() const { return (BoundingVolume*)this->bvElement; }
    33    
    34    
     33
     34
    3535    virtual void spawnBVTree(const int depth, const sVec3D *verticesList, unsigned int length);
    36     virtual void spawnBVTree(const int depth, const modelInfo& modelInf, 
     36    virtual void spawnBVTree(const int depth, const modelInfo& modelInf,
    3737                             const int* triangleIndexes, unsigned int length);
    3838
     
    4141    void debug() const;
    4242
    43    
     43
    4444  private:
    45     void calculateBoxEigenvectors(OBB* box, const sVec3D* verticesList, unsigned int length);
    46     void calculateBoxAxis(OBB* box, const sVec3D* verticesList, unsigned int length);
     45    void calculateBoxEigenvectors(OBB& box, const sVec3D* verticesList, unsigned int length);
     46    void calculateBoxAxis(OBB& box, const sVec3D* verticesList, unsigned int length);
    4747
    48     void calculateBoxCovariance(OBB* box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length);
    49     void calculateBoxEigenvectors(OBB* box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length);
    50     void calculateBoxAxis(OBB* box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length);
     48    void calculateBoxCovariance(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length);
     49    void calculateBoxEigenvectors(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length);
     50    void calculateBoxAxis(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length);
    5151
    52     void forkBox(OBB* box);
     52    void forkBox(OBB& box);
    5353
    5454    bool overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB);
    5555
    56    
     56
    5757  protected:
    5858    OBB*                bvElement;                  //!< the obb element
     
    6565    int                 depth;                      //!< the depth of the node in the tree
    6666    const OBBTree*      obbTree;                    //!< reference to the obb tree
    67    
     67
    6868    const sVec3D*       vertices;                   //!< pointer to the vertices data
    6969    int                 numOfVertices;              //!< number of vertices in vertices data
     
    8282    static float*       eigvlMat;
    8383    static int*         rotCount;
    84    
     84
    8585};
    8686
Note: See TracChangeset for help on using the changeset viewer.