Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4617 in orxonox.OLD


Ignore:
Timestamp:
Jun 13, 2005, 9:32:26 AM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: now the depth obb tree calculation works

Location:
orxonox/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc

    r4616 r4617  
    99   any later version.
    1010
    11    ### File Specific:
     11### File Specific:
    1212   main-programmer: Patrick Boenzli
    1313   co-programmer: ...
     
    4444/**
    4545   \brief standard constructor
    46 */
     46 */
    4747OBBTreeNode::OBBTreeNode ()
    4848{
    49    this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode");
     49  this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode");
    5050
    5151}
     
    5454/**
    5555   \brief standard deconstructor
    56 
    57 */
     56 */
    5857OBBTreeNode::~OBBTreeNode ()
    5958{
     
    6766   \param depth: how much more depth-steps to go: if == 1 don't go any deeper!
    6867   \param verticesList: the list of vertices of the object - each vertices triple is interpreted as a triangle
    69 */
     68 */
    7069void OBBTreeNode::spawnBVTree(const int depth, sVec3D *verticesList, const int length)
    7170{
    7271  this->depth = depth;
    7372
     73  this->bvElement = this->createBox();
     74  this->calculateBoxAttributes(this->bvElement, verticesList, length);
     75
    7476  if( likely( this->depth > 0))
    7577  {
    76     this->bvElement = this->createBox();
    77     this->calculateBoxAttributes(this->bvElement, verticesList, length);
    7878    this->forkBox(this->bvElement);
    7979  }
     
    105105  /* fist compute all the convex hull face/facelets and centroids */
    106106  for(int i = 0; i < length; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
    107     {
    108       p = verticesList[i];
    109       q = verticesList[i +1];
    110       r = verticesList[i + 2];
    111 
    112       t1 = p - q; t2 = p - r;
    113 
    114       /* finding the facelet surface via cross-product */
    115       facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
    116       /* update the entire convex hull surface */
    117       face += facelet[i];
    118 
    119       /* calculate the cetroid of the hull triangles */
    120       centroid[i] = (p + q + r) * 1/3;
    121       /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
    122       center += centroid[i] * facelet[i];
    123     }
     107  {
     108    p = verticesList[i];
     109    q = verticesList[i +1];
     110    r = verticesList[i + 2];
     111
     112    t1 = p - q; t2 = p - r;
     113
     114    /* finding the facelet surface via cross-product */
     115    facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
     116    /* update the entire convex hull surface */
     117    face += facelet[i];
     118
     119    /* calculate the cetroid of the hull triangles */
     120    centroid[i] = (p + q + r) * 1/3;
     121    /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
     122    center += centroid[i] * facelet[i];
     123  }
    124124  /* take the average of the centroid sum */
    125125  center /= face;
     
    129129  /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */
    130130  for(int j = 0; j < 3; ++j)
     131  {
     132    for(int k = 0; k < 3; ++k)
    131133    {
    132       for(int k = 0; k < 3; ++k)
    133         {
    134           for(int i = 0; i < length; i+=3)
    135             {
    136               p = verticesList[i];
    137               q = verticesList[i +1];
    138               r = verticesList[i + 2];
    139 
    140               covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] +
    141                                                                 q[j] * q[k] + r[j]*r[k]) - center[j] * center[k];
    142             }
    143         }
     134      for(int i = 0; i < length; i+=3)
     135      {
     136        p = verticesList[i];
     137        q = verticesList[i +1];
     138        r = verticesList[i + 2];
     139
     140        covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] +
     141            q[j] * q[k] + r[j]*r[k]) - center[j] * center[k];
     142      }
    144143    }
    145 
    146     printf("\nVertex Data:\n");
    147     for(int i = 0; i < length; i++)
    148     {
    149       printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
    150     }
     144  }
     145
     146  printf("\nVertex Data:\n");
     147  for(int i = 0; i < length; i++)
     148  {
     149    printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
     150  }
    151151
    152152  printf("\nCovariance Matrix:\n");
    153153  for(int j = 0; j < 3; ++j)
     154  {
     155    printf(" |");
     156    for(int k = 0; k < 3; ++k)
    154157    {
    155       printf(" |");
    156       for(int k = 0; k < 3; ++k)
    157         {
    158           printf(" \b%f ", covariance[j][k]);
    159         }
    160       printf(" |\n");
     158      printf(" \b%f ", covariance[j][k]);
    161159    }
     160    printf(" |\n");
     161  }
    162162  printf("center: %f, %f, %f\n\n", center.x, center.y, center.z);
    163163
    164164
    165165  for(int i = 0; i < 3; ++i)
    166     {
    167 
    168       box->covarianceMatrix[i][0] = covariance[i][0];
    169       box->covarianceMatrix[i][1] = covariance[i][1];
    170       box->covarianceMatrix[i][3] = covariance[i][2];
    171     }
     166  {
     167
     168    box->covarianceMatrix[i][0] = covariance[i][0];
     169    box->covarianceMatrix[i][1] = covariance[i][1];
     170    box->covarianceMatrix[i][3] = covariance[i][2];
     171  }
    172172  *box->center = center;
    173173
    174174
    175175  /* now getting spanning vectors of the sub-space:
    176      the eigenvectors of a symmertric matrix, such as the
    177      covarience matrix are mutually orthogonal.
    178      after normalizing them, they can be used as a the basis
    179      vectors
     176  the eigenvectors of a symmertric matrix, such as the
     177  covarience matrix are mutually orthogonal.
     178  after normalizing them, they can be used as a the basis
     179  vectors
    180180  */
    181181  Matrix                V(3,3);                               //!< for eigenvectors
     
    304304
    305305  /* now definin the separation plane through this specified nearest point and partition
    306     the points depending on which side they are located
     306  the points depending on which side they are located
    307307  */
    308308  Plane              separationPlane(*box->axis[axisIndex], box->vertices[vertexIndex]);  //!< separation plane
     
    379379  this->nodeRight = node2;
    380380
    381   this->nodeLeft->spawnBVTree(this->depth - 1, vertList1, partition1.getSize());
    382   this->nodeRight->spawnBVTree(this->depth - 1, vertList2, partition2.getSize());
     381  this->nodeLeft->spawnBVTree(depth - 1, vertList1, partition1.getSize());
     382  this->nodeRight->spawnBVTree(depth - 1, vertList2, partition2.getSize());
    383383}
    384384
     
    398398//     }
    399399//   glEnd();
     400  //this->drawBVPolygon(currentDepth, depth);
    400401}
    401402
     
    509510/*
    510511  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
    511              cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
    512              cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
     512  cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
     513  cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
    513514  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
    514              cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
    515              cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);*/
     515  cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
     516  cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);*/
    516517
    517518
     
    531532  /*
    532533  for(int i = 0; i < length; i++)
    533     {
    534       printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
    535     }
     534  {
     535  printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
     536}
    536537  */
    537538}
  • orxonox/trunk/src/subprojects/collision_detection/collision_detection.cc

    r4615 r4617  
    3131{
    3232  CDEngine::getInstance();
    33   //CDEngine::getInstance()->debug();
     33  CDEngine::getInstance()->debug();
    3434
    35   model = new MD2Model("models/tris.md2", "models/tris.pcx");
    36   model->tick(0.1f);
    37   CDEngine::getInstance()->debugSpawnTree(1, model->data->pVertices, model->data->numVertices);
     35  //model = new MD2Model("models/tris.md2", "models/tris.pcx");
     36  //model->tick(0.1f);
     37  //CDEngine::getInstance()->debugSpawnTree(2, model->data->pVertices, model->data->numVertices);
    3838
    3939  LightManager* lightMan = LightManager::getInstance();
     
    7070  LightManager::getInstance()->draw();
    7171
    72   model->draw();
     72  //model->draw();
    7373}
    7474
     
    8484void Framework::moduleInitGui(int argc, char** argv)
    8585{
    86   Window* guiMainWindow = NULL;
    87 
    88   initGUI(0, NULL);
    89 
    90   guiMainWindow = new Window("Collision_detection");
    91   {
    92     // all the Widgets you need
    93   }
    94   Window::mainWindow->showall();
    95   Window::mainWindow->setSize(300, 500);
     86//   Window* guiMainWindow = NULL;
     87//
     88//   initGUI(0, NULL);
     89//
     90//   guiMainWindow = new Window("Collision_detection");
     91//   {
     92//     // all the Widgets you need
     93//   }
     94//   Window::mainWindow->showall();
     95//   Window::mainWindow->setSize(300, 500);
    9696}
Note: See TracChangeset for help on using the changeset viewer.