Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5922 in orxonox.OLD for branches/collision_detection/src/lib


Ignore:
Timestamp:
Dec 4, 2005, 11:28:35 PM (19 years ago)
Author:
patrick
Message:

collision_detection: working on centeroid obb structures

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

Legend:

Unmodified
Added
Removed
  • branches/collision_detection/src/lib/collision_detection/bounding_volume.h

    r5870 r5922  
    3232
    3333  public:
    34     Vector              center;                     //!< Center point of box
     34    Vector              center;                     //!< Weighter average center point of box
     35    Vector              arithCenter;                //!< Arithmetical center of the box
    3536
    3637    const modelInfo*    modelInf;                   //!< Reference to the model's ModelInfo
  • branches/collision_detection/src/lib/collision_detection/obb_tree_node.cc

    r5920 r5922  
    2828
    2929#include <list>
     30#include <vector>
    3031#include "debug.h"
    3132
     
    171172    /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
    172173    center += centroid[i] * facelet[i];
     174    /* the arithmetical center */
    173175  }
    174176  /* take the average of the centroid sum */
     
    197199  }
    198200
     201
     202  std::vector<int>           vertIndexVector;                           //!< vertex indexes list
     203  int                        vertIndex;                                 //!< index to vertex
     204  bool                       vertexFound;                               //!< vertex found flag
     205  Vector                     arithCenter;                               //!< aritmetical center
     206
     207
     208  /* calculate the arithmetical center of the box */
     209
     210  /* go thourgh all vertices, add only the used vertices indexes */
     211  for( int i = 0; i < length; ++i)
     212  {
     213    for(int j = 0; j < 3; ++j)
     214    {
     215      vertIndex = modelInf.pTriangles[triangleIndexes[i]].indexToVertices[j];
     216
     217      vertexFound = false;
     218      for( int i = 0; i < vertIndexVector.size(); i++)
     219      {
     220        if( vertIndexVector[i] == vertIndex)
     221          vertexFound = true;
     222      }
     223      if( !vertexFound)
     224        vertIndexVector.push_back(vertIndex);
     225    }
     226  }
     227  /* now realy calculate the center */
     228  for( int i = 0; i < vertIndexVector.size(); ++i)
     229  {
     230    tmpVec = (sVec3D*)(&modelInf.pVertices[vertIndexVector[i]]);
     231    arithCenter += *tmpVec;
     232  }
     233  arithCenter.debug();
     234  box.arithCenter = arithCenter / vertIndexVector.size();
     235
     236
     237
     238
    199239  PRINTF(3)("\nOBB Covariance Matrix:\n");
    200240  for(int j = 0; j < 3; ++j)
     
    207247    PRINT(3)("\n");
    208248  }
    209   PRINTF(3)("\nOBB Center:\n\t\t%11.2f\t %11.2f\t %11.2f\n", center.x, center.y, center.z);
     249  PRINTF(3)("\nWeighteed OBB Center:\n\t\t%11.2f\t %11.2f\t %11.2f\n", center.x, center.y, center.z);
     250  PRINTF(3)("\nArithmetical OBB Center:\n\t\t%11.2f\t %11.2f\t %11.2f\n", arithCenter.x, arithCenter.y, arithCenter.z);
    210251
    211252  /* write back the covariance matrix data to the object oriented bouning box */
     
    267308void OBBTreeNode::calculateBoxAxis(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length)
    268309{
    269 
    270   sVec3D* verticesList;
    271 
    272310
    273311  PRINTF(3)("Calculate Box Axis\n");
     
    385423  float               newHalfLength[3];
    386424
    387   for(int i = 0; i < 3; ++i)
     425  for( int i = 0; i < 3; ++i)
    388426  {
    389427    centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f;       // min length is negatie
     
    453491
    454492
    455   ./* find the center of the box */
     493  /* find the center of the box */
    456494
    457495  this->separationPlane = Plane(box.axis[longestAxisIndex], box.center);
Note: See TracChangeset for help on using the changeset viewer.