Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4588 in orxonox.OLD for orxonox/trunk/src/lib/collision_detection


Ignore:
Timestamp:
Jun 10, 2005, 11:23:01 AM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: now drawing o-boundingbox as a polygon, seems to be one minor accuracy problem

Location:
orxonox/trunk/src/lib/collision_detection
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/collision_detection/bounding_volume.h

    r4560 r4588  
    1 /*! 
     1/*!
    22    \file bounding_volume.h
    33    \brief Definition of a bounding volume for collision detection algorithms
     
    99
    1010#include "base_object.h"
     11#include "abstract_model.h"
    1112
    12 class sVect3D;
    1313class Vector;
    1414template<class T> class tList;
     
    2424  inline const Vector* getCenter() const { return this->center; }
    2525
    26   virtual sVect3D* getVertices() const = NULL;
     26  sVec3D* getVertices() const { return this->vertices; }
    2727  virtual void mergeWith(const BoundingVolume &bv) = NULL;
    2828
     
    3535  Vector*             center;                     //!< Center point of box
    3636
    37   sVect3D*            vertices;                   //!< if CD_STORE_VERTICES enabled, this is the place, where the vert. will be sotred
     37  sVec3D*             vertices;                   //!< if CD_STORE_VERTICES enabled, this is the place, where the vert. will be sotred
    3838  int                 numOfVertices;              //!< number of vertices in the vertices buffer
    3939};
  • orxonox/trunk/src/lib/collision_detection/obb.h

    r4576 r4588  
    2424  inline const float* getHalfLength() const { return this->halfLength; }
    2525
    26   virtual sVect3D* getVertices() const { return this->vertices; }
    2726  virtual void mergeWith(const BoundingVolume &bv);
    2827
  • orxonox/trunk/src/lib/collision_detection/obb_tree.cc

    r4587 r4588  
    9797  /* generate some test vertices */
    9898  sVec3D* vertList = new sVec3D[4];
    99   sVec3D data[]  = {{0.0, 0.0, 0.0},{10.0, -5.0, 5.0},{10.0, 5.0, 0.0}, {5.0, 4.0, 1.0}};
     99  sVec3D data[]  = {{0.0, 0.0, 0.0},{2.0, -8.0, 5.0},{10.0, 5.0, 0.0}, {5.0, 4.0, 1.0}};
    100100
    101   for(int i = 0; i < 3; ++i)
     101  for(int i = 0; i < 4; ++i)
    102102    {
    103103      vertList[i][0] = data[i][0];
  • orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc

    r4587 r4588  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    4444   \brief standard constructor
    4545*/
    46 OBBTreeNode::OBBTreeNode () 
    47 {
    48    this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode"); 
     46OBBTreeNode::OBBTreeNode ()
     47{
     48   this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode");
    4949
    5050}
     
    5555
    5656*/
    57 OBBTreeNode::~OBBTreeNode () 
     57OBBTreeNode::~OBBTreeNode ()
    5858{
    5959  // delete what has to be deleted here
     
    8585  float     facelet[length];                         //!< surface area of the i'th triangle of the convex hull
    8686  float     face;                                    //!< surface area of the entire convex hull
    87   Vector    centroid[length];                        //!< centroid of the i'th convex hull 
     87  Vector    centroid[length];                        //!< centroid of the i'th convex hull
    8888  Vector    center;                                  //!< the center of the entire hull
    8989  Vector    p, q, r;                                 //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d
    9090  Vector    t1, t2;                                  //!< temporary values
    9191  float     covariance[3][3];                        //!< the covariance matrix
    92    
     92
    9393  this->numOfVertices = length;
    9494  this->vertices = verticesList;
     95  box->vertices = verticesList;
     96  box->numOfVertices = length;
    9597
    9698
     
    101103      q = verticesList[i +1];
    102104      r = verticesList[i + 2];
    103      
     105
    104106      t1 = p - q; t2 = p - r;
    105      
     107
    106108      /* finding the facelet surface via cross-product */
    107109      facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
     
    118120
    119121
    120  
     122
    121123  /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */
    122124  for(int j = 0; j < 3; ++j)
    123125    {
    124126      for(int k = 0; k < 3; ++k)
    125         {
    126           for(int i = 0; i < length; i+=3)
    127             {
    128               p = verticesList[i];
    129               q = verticesList[i +1];
    130               r = verticesList[i + 2];
    131 
    132               covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] +
    133                                                                 q[j] * q[k] + r[j]*r[k]) - center[j] * center[k];
    134             }
    135         }
     127        {
     128          for(int i = 0; i < length; i+=3)
     129            {
     130              p = verticesList[i];
     131              q = verticesList[i +1];
     132              r = verticesList[i + 2];
     133
     134              covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] +
     135                                                                q[j] * q[k] + r[j]*r[k]) - center[j] * center[k];
     136            }
     137        }
    136138    }
    137139
     
    141143      printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
    142144    }
    143  
     145
    144146  printf("\nCovariance Matrix:\n");
    145147  for(int j = 0; j < 3; ++j)
     
    147149      printf(" |");
    148150      for(int k = 0; k < 3; ++k)
    149         {
    150           printf(" \b%f ", covariance[j][k]);
    151         }
     151        {
     152          printf(" \b%f ", covariance[j][k]);
     153        }
    152154      printf(" |\n");
    153155    }
    154156  printf("center: %f, %f, %f\n\n", center.x, center.y, center.z);
    155157
    156    
     158
    157159  for(int i = 0; i < 3; ++i)
    158160    {
    159    
     161
    160162      box->covarianceMatrix[i][0] = covariance[i][0];
    161163      box->covarianceMatrix[i][1] = covariance[i][1];
     
    168170     the eigenvectors of a symmertric matrix, such as the
    169171     covarience matrix are mutually orthogonal.
    170      after normalizing them, they can be used as a the basis 
     172     after normalizing them, they can be used as a the basis
    171173     vectors
    172174  */
    173175  Matrix                V(3,3);                               //!< for eigenvectors
    174   DiagonalMatrix        D(3);                                 //!< for eigenvalues   
     176  DiagonalMatrix        D(3);                                 //!< for eigenvalues
    175177  SymmetricMatrix       C(3);                                 //!< for the covariance symmetrical matrix
    176178  Vector**              axis = new Vector*[3];                //!< the references to the obb axis
    177  
     179
    178180  C(1,1) = covariance[0][0];
    179181  C(1,2) = covariance[0][1];
    180182  C(1,3) = covariance[0][2];
    181   C(2,1) = covariance[1][0];   
     183  C(2,1) = covariance[1][0];
    182184  C(2,2) = covariance[1][1];
    183   C(2,3) = covariance[1][2]; 
     185  C(2,3) = covariance[1][2];
    184186  C(3,1) = covariance[2][0];
    185187  C(3,2) = covariance[2][1];
     
    204206  axis[2] = new Vector(V(1, 3), V(2, 3), V(3, 3));
    205207  box->axis = axis;
    206  
     208
    207209  printf("eigenvector: %f, %f, %f\n", box->axis[0]->x, box->axis[0]->y, box->axis[0]->z);
    208210  printf("eigenvector: %f, %f, %f\n", box->axis[1]->x, box->axis[1]->y, box->axis[1]->z);
    209211  printf("eigenvector: %f, %f, %f\n", box->axis[2]->x, box->axis[2]->y, box->axis[2]->z);
    210212
    211  
     213
    212214  /* now get the axis length */
    213215  Line                ax[3];                                 //!< the axis
    214216  float*              halfLength = new float[3];             //!< half length of the axis
    215217  float               tmpLength;                             //!< tmp save point for the length
    216  
     218
    217219  ax[0].r = *box->center; ax[0].a = *box->axis[0];
    218220  ax[1].r = *box->center; ax[1].a = *box->axis[1];
     
    222224  Plane p1(*box->axis[1], *box->center);
    223225  Plane p2(*box->axis[2], *box->center);
    224  
     226
    225227
    226228
     
    252254  box->halfLength = halfLength;
    253255
    254  
    255  
     256
     257
    256258  printf("we got length: \n");
    257259  for(int i = 0; i < 3; ++i)
     
    268270    {
    269271      if( aLength < box->axis[i]->len())
    270         {
    271           aLength = box->axis[i]->len();
    272           axisNr = i;
    273         }
    274     }
    275  
     272        {
     273          aLength = box->axis[i]->len();
     274          axisNr = i;
     275        }
     276    }
     277
    276278  /* get the closest vertex near the center */
    277  
     279
    278280}
    279281
     
    287289  glBegin(GL_LINE_LOOP);
    288290  glColor3f(1.0, 1.0, 1.0);
    289   for(int i = 0; i < this->numOfVertices; ++i)
    290     {
    291       glVertex3f(this->vertices[i][0], this->vertices[i][1], this->vertices[i][2]);
     291  for(int i = 0; i < this->bvElement->numOfVertices; ++i)
     292    {
     293      glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
    292294      //printf("v(%f, %f, %f)\n", this->vertices[i][0], this->vertices[i][1], this->vertices[i][2]);
    293295    }
     
    298300void OBBTreeNode::drawBVPolygon(int currentDepth, const int depth) const
    299301{
     302
     303  /* draw the obb axes */
    300304  glBegin(GL_LINES);
    301305  glColor3f(0.0, 0.4, 0.3);
     
    304308             this->bvElement->center->y + this->bvElement->axis[0]->y * this->bvElement->halfLength[0],
    305309             this->bvElement->center->z + this->bvElement->axis[0]->z * this->bvElement->halfLength[0]);
    306  
     310
    307311  glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
    308312  glVertex3f(this->bvElement->center->x + this->bvElement->axis[1]->x * this->bvElement->halfLength[1],
     
    315319             this->bvElement->center->z + this->bvElement->axis[2]->z * this->bvElement->halfLength[2]);
    316320  glEnd();
     321
     322
     323  Vector cen = *this->bvElement->center;
     324  Vector** axis = this->bvElement->axis;
     325  float* len = this->bvElement->halfLength;
     326
     327  /* draw bounding box */
     328  glBegin(GL_LINE_LOOP);
     329  glColor3f(0.3, 0.4, 0.7);
     330  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
     331             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
     332             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
     333  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
     334             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
     335             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
     336  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
     337             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
     338             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
     339  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
     340             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
     341             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
     342  glEnd();
     343
     344  glBegin(GL_LINE_LOOP);
     345  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
     346             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
     347             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
     348  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
     349             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
     350             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
     351  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
     352             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
     353             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
     354  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
     355             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
     356             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
     357  glEnd();
     358
     359  glBegin(GL_LINE_LOOP);
     360  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
     361             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
     362             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
     363  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
     364             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
     365             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
     366  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
     367             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
     368             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
     369  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
     370             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
     371             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
     372  glEnd();
     373
     374  glBegin(GL_LINE_LOOP);
     375  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
     376             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
     377             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
     378  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
     379             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
     380             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
     381  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
     382             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
     383             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
     384  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
     385             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
     386             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
     387  glEnd();
     388
     389/*
     390  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
     391             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
     392             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
     393  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
     394             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
     395             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);*/
     396
     397
     398  glEnd();
     399
     400
    317401}
    318402
Note: See TracChangeset for help on using the changeset viewer.