Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5706 in orxonox.OLD for branches


Ignore:
Timestamp:
Nov 22, 2005, 3:19:00 PM (19 years ago)
Author:
patrick
Message:

collision_detection: removed some more variables and changed some names

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

Legend:

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

    r5704 r5706  
    1717
    1818#include "bounding_volume.h"
    19 #include "vector.h"
    2019
    2120using namespace std;
     
    2726BoundingVolume::BoundingVolume ()
    2827{
    29    this->setClassID(CL_BOUNDING_VOLUME, "BoundingVolume");
    30    this->center = new Vector();
    31    this->vertices = NULL;
     28  this->setClassID(CL_BOUNDING_VOLUME, "BoundingVolume");
     29  this->vertices = NULL;
    3230}
    3331
     
    3937BoundingVolume::~BoundingVolume ()
    4038{
    41   // delete what has to be deleted here
    42   delete this->center;
    43  
    4439  if( this->triangleIndexes)
    4540    delete[] this->triangleIndexes;
  • branches/collision_detection/src/lib/collision_detection/bounding_volume.h

    r5704 r5706  
    1111#include "abstract_model.h"
    1212
    13 class Vector;
     13
    1414template<class T> class tList;
    1515
     
    2222    virtual ~BoundingVolume();
    2323
    24     inline const Vector* getCenter() const { return this->center; }
     24    inline const Vector& getCenter() const { return this->center; }
    2525
    2626    const sVec3D* getVertices() const { return this->vertices; }
     
    3232
    3333  public:
    34     Vector*             center;                     //!< Center point of box
     34    Vector              center;                     //!< Center point of box
    3535
    3636    const sVec3D*       vertices;                   //!< if CD_STORE_VERTICES enabled, this is the place, where the vert. will be sotred
  • branches/collision_detection/src/lib/collision_detection/obb_tree_node.cc

    r5705 r5706  
    232232  Vector    t1, t2;                                  //!< temporary values
    233233  float     covariance[3][3] = {0,0,0, 0,0,0, 0,0,0};//!< the covariance matrix
    234   int       mode = 0;                                //!< mode = 0: vertex soup, no connections, mode = 1: 3 following verteces build a triangle
    235 
    236   this->numOfVertices = length;
    237   this->vertices = verticesList;
    238 
    239 
    240   if( likely(mode == 0))
    241   {
    242     /* fist compute all the convex hull face/facelets and centroids */
    243     for( int i = 0; i+3 < length ; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
    244     {
    245       p = verticesList[i];
    246       q = verticesList[i + 1];
    247       r = verticesList[i + 2];
    248 
    249       t1 = p - q; t2 = p - r;
    250 
    251       /* finding the facelet surface via cross-product */
    252       facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
    253       /* update the entire convex hull surface */
    254       face += facelet[i];
    255 
    256       /* calculate the cetroid of the hull triangles */
    257       centroid[i] = (p + q + r) * 1/3;
    258       /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
    259       center += centroid[i] * facelet[i];
    260     }
    261     /* take the average of the centroid sum */
    262     center /= face;
    263     PRINTF(3)("-- Calculated Center\n");
    264 
    265 
    266     /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */
    267     for( int j = 0; j < 3; ++j)
    268     {
    269       for( int k = 0; k < 3; ++k)
     234
     235
     236 
     237  /* fist compute all the convex hull face/facelets and centroids */
     238  for( int i = 0; i+3 < length ; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
     239  {
     240    p = verticesList[i];
     241    q = verticesList[i + 1];
     242    r = verticesList[i + 2];
     243
     244    t1 = p - q; t2 = p - r;
     245
     246    /* finding the facelet surface via cross-product */
     247    facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
     248    /* update the entire convex hull surface */
     249    face += facelet[i];
     250
     251    /* calculate the cetroid of the hull triangles */
     252    centroid[i] = (p + q + r) * 1/3;
     253    /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
     254    center += centroid[i] * facelet[i];
     255  }
     256  /* take the average of the centroid sum */
     257  center /= face;
     258  PRINTF(3)("-- Calculated Center\n");
     259
     260
     261  /* now calculate the covariance matrix - if not written in three for-loops,
     262     it would compute faster: minor */
     263  for( int j = 0; j < 3; ++j)
     264  {
     265    for( int k = 0; k < 3; ++k)
     266    {
     267      for( int i = 0; i + 3 < length; i+=3)
    270268      {
    271         for( int i = 0; i + 3 < length; i+=3)
    272         {
    273           p = verticesList[i];
    274           q = verticesList[i + 1];
    275           r = verticesList[i + 2];
    276 
    277           covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j] * p[k] +
    278               q[j] * q[k] + r[j] * r[k]) - center[j] * center[k];
    279         }
     269        p = verticesList[i];
     270        q = verticesList[i + 1];
     271        r = verticesList[i + 2];
     272
     273        covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j] * p[k] +
     274            q[j] * q[k] + r[j] * r[k]) - center[j] * center[k];
    280275      }
    281276    }
    282     PRINTF(3)("-- Calculated Covariance\n");
    283   }
    284   else if( mode == 1)
    285   {
    286     for( int i = 0; i + 3 < length; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
    287     {
    288       p = verticesList[i];
    289       q = verticesList[i + 1];
    290       r = verticesList[i + 2];
    291 
    292       centroid[i] = (p + q + r) / 3.0f;
    293       center += centroid[i];
    294     }
    295     center /= length;
    296 
    297     for( int j = 0; j < 3; ++j)
    298     {
    299       for( int k = 0; k < 3; ++k)
    300       {
    301         for( int i = 0; i + 3 < length; i+=3)
    302         {
    303           p = verticesList[i];
    304           q = verticesList[i +1];
    305           r = verticesList[i + 2];
    306 
    307           covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k];
    308         }
    309         covariance[j][k] /= (3.0f * length);
    310       }
    311     }
    312     PRINTF(3)("-- Calculated Covariance\n");
    313   }
    314   else if( mode == 2)
    315   {
    316     /* fist compute all the convex hull face/facelets and centroids */
    317     for(int i = 0; i + 3 < length; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
    318     {
    319       p = verticesList[i];
    320       q = verticesList[i + 1];
    321       r = verticesList[i + 2];
    322 
    323       t1 = p - q; t2 = p - r;
    324 
    325       /* finding the facelet surface via cross-product */
    326       facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
    327       /* update the entire convex hull surface */
    328       face += facelet[i];
    329 
    330       /* calculate the cetroid of the hull triangles */
    331       centroid[i] = (p + q + r) * 1/3;
    332       /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
    333       center += centroid[i] * facelet[i];
    334     }
    335     /* take the average of the centroid sum */
    336     center /= face;
    337     PRINTF(3)("-- Calculated Center\n");
    338 
    339     for( int j = 0; j < 3; ++j)
    340     {
    341       for( int k = 0; k < 3; ++k)
    342       {
    343         for( int i = 0; i + 3 < length; i+=3)
    344         {
    345           p = verticesList[i];
    346           q = verticesList[i +1];
    347           r = verticesList[i + 2];
    348 
    349           covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k];
    350         }
    351         covariance[j][k] /= (3.0f * length);
    352       }
    353     }
    354     PRINTF(3)("-- Calculated Covariance\n");
    355   }
    356   else
    357   {
    358     for( int i = 0; i < length; ++i)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
    359     {
    360       center += verticesList[i];
    361     }
    362     center /= length;
    363 
    364     for( int j = 0; j < 3; ++j)
    365     {
    366       for( int k = 0; k < 3; ++k)
    367       {
    368         for( int i = 0; i + 3 < length; i+=3)
    369         {
    370           p = verticesList[i];
    371           q = verticesList[i +1];
    372           r = verticesList[i + 2];
    373 
    374           covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k];
    375         }
    376         covariance[j][k] /= (3.0f * length);
    377       }
    378     }
    379     PRINTF(3)("-- Calculated Covariance\n");
    380   }
    381 
     277  }
     278  PRINTF(3)("-- Calculated Covariance\n");
     279
     280   
    382281  PRINTF(3)("\nVertex Data:\n");
    383282  for(int i = 0; i < length; i++)
    384   {
    385     PRINTF(3)("vertex %i: %f, %f, %f\n", i, box->vertices[i][0], box->vertices[i][1], box->vertices[i][2]);
    386   }
    387 
    388 
    389   PRINTF(3)("\nCovariance Matrix:\n");
    390   for(int j = 0; j < 3; ++j)
    391   {
    392     PRINT(3)(" |");
    393     for(int k = 0; k < 3; ++k)
    394     {
    395       PRINT(3)(" \b%f ", covariance[j][k]);
    396     }
    397     PRINT(3)(" |\n");
    398   }
    399 
    400   PRINTF(3)("center: %f, %f, %f\n", center.x, center.y, center.z);
     283    PRINTF(3)(" Vertex[%i]: %f, %f, %f\n", i, box->vertices[i][0], box->vertices[i][1], box->vertices[i][2]);
     284  PRINTF(3)("\nOBB Covariance Matrix:\n");
     285  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"); }
     286  PRINTF(3)("OBB Center: %f, %f, %f\n", center.x, center.y, center.z);
    401287
    402288
     
    407293    box->covarianceMatrix[i][2] = covariance[i][2];
    408294  }
    409   *box->center = center;
    410   PRINTF(3)("-- Written Result to obb\n");
     295  box->center = center;
     296 
     297  PRINTF(3)("-- Written Result to OBB\n");
    411298}
    412299
     
    479366  float               halfLength[3];                         //!< half length of the axis
    480367  float               tmpLength;                             //!< tmp save point for the length
    481   Plane               p0(box->axis[0], *box->center);        //!< the axis planes
    482   Plane               p1(box->axis[1], *box->center);
    483   Plane               p2(box->axis[2], *box->center);
     368  Plane               p0(box->axis[0], box->center);        //!< the axis planes
     369  Plane               p1(box->axis[1], box->center);
     370  Plane               p2(box->axis[2], box->center);
    484371  float               maxLength[3];
    485372  float               minLength[3];
     
    556443       centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f;       // min length is negatie
    557444       newHalfLength[i] = (maxLength[i] - minLength[i]) / 2.0f;      // min length is negative
    558        *box->center +=  (box->axis[i] * centerOffset[i]);            // update the new center vector
     445       box->center +=  (box->axis[i] * centerOffset[i]);            // update the new center vector
    559446       halfLength[i] = newHalfLength[i];
    560447     }
     
    599486  float               tmpDist;                             //!< temporary distance
    600487  int                 vertexIndex;
    601   Plane               middlePlane(box->axis[axisIndex], *box->center); //!< the middle plane
     488  Plane               middlePlane(box->axis[axisIndex], box->center); //!< the middle plane
    602489
    603490  vertexIndex = 0;
     
    738625    if( unlikely(this->nodeRight == NULL && this->nodeLeft == NULL))
    739626    {
    740       nodeA->collidesWith(nodeB, *((OBBTreeNode*)treeNode)->bvElement->center);
    741 
    742       nodeB->collidesWith(nodeA, *this->bvElement->center);
     627      nodeA->collidesWith(nodeB, ((OBBTreeNode*)treeNode)->bvElement->center);
     628
     629      nodeB->collidesWith(nodeA, this->bvElement->center);
    743630    }
    744631
     
    766653  rotAxisB[2] =  nodeB->getAbsDir().apply(boxB->axis[2]);
    767654
    768   t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(*boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(*boxB->center));
     655
     656  t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(boxB->center));
    769657
    770658//   printf("\n");
     
    928816      glBegin(GL_LINES);
    929817      glColor3f(0.0, 0.4, 0.3);
    930       glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
    931       glVertex3f(this->bvElement->center->x + this->bvElement->axis[0].x * this->bvElement->halfLength[0],
    932                  this->bvElement->center->y + this->bvElement->axis[0].y * this->bvElement->halfLength[0],
    933                  this->bvElement->center->z + this->bvElement->axis[0].z * this->bvElement->halfLength[0]);
    934 
    935       glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
    936       glVertex3f(this->bvElement->center->x + this->bvElement->axis[1].x * this->bvElement->halfLength[1],
    937                  this->bvElement->center->y + this->bvElement->axis[1].y * this->bvElement->halfLength[1],
    938                  this->bvElement->center->z + this->bvElement->axis[1].z * this->bvElement->halfLength[1]);
    939 
    940       glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
    941       glVertex3f(this->bvElement->center->x + this->bvElement->axis[2].x * this->bvElement->halfLength[2],
    942                  this->bvElement->center->y + this->bvElement->axis[2].y * this->bvElement->halfLength[2],
    943                  this->bvElement->center->z + this->bvElement->axis[2].z * this->bvElement->halfLength[2]);
     818      glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z);
     819      glVertex3f(this->bvElement->center.x + this->bvElement->axis[0].x * this->bvElement->halfLength[0],
     820                 this->bvElement->center.y + this->bvElement->axis[0].y * this->bvElement->halfLength[0],
     821                 this->bvElement->center.z + this->bvElement->axis[0].z * this->bvElement->halfLength[0]);
     822
     823      glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z);
     824      glVertex3f(this->bvElement->center.x + this->bvElement->axis[1].x * this->bvElement->halfLength[1],
     825                 this->bvElement->center.y + this->bvElement->axis[1].y * this->bvElement->halfLength[1],
     826                 this->bvElement->center.z + this->bvElement->axis[1].z * this->bvElement->halfLength[1]);
     827
     828      glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z);
     829      glVertex3f(this->bvElement->center.x + this->bvElement->axis[2].x * this->bvElement->halfLength[2],
     830                 this->bvElement->center.y + this->bvElement->axis[2].y * this->bvElement->halfLength[2],
     831                 this->bvElement->center.z + this->bvElement->axis[2].z * this->bvElement->halfLength[2]);
    944832      glEnd();
    945833    }
     
    960848    if( !(drawMode & DRAW_SINGLE && depth != 0))
    961849    {
    962     Vector cen = *this->bvElement->center;
     850    Vector cen = this->bvElement->center;
    963851    Vector* axis = this->bvElement->axis;
    964852    float* len = this->bvElement->halfLength;
     
    1098986    Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3];
    1099987    Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3];
    1100     Vector c = *this->bvElement->center;
     988    Vector c = this->bvElement->center;
    1101989    float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3];
    1102990    float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3];
Note: See TracChangeset for help on using the changeset viewer.