Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 16, 2005, 1:42:14 AM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: changed the way the data is displayed, now supports colors and stuff. noticed some data drawing problems. the tree separation seems so work perfectly but the graphical data representation is buggy

File:
1 edited

Legend:

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

    r4636 r4638  
    3030#define WANT_FSTREAM
    3131
     32#include "stdincl.h"
    3233
    3334#include "include.h"
     
    7778  if( rotCount == NULL)
    7879    rotCount = new int;
     80
     81  this->sphereObj = gluNewQuadric();
    7982}
    8083
     
    97100void OBBTreeNode::spawnBVTree(const int depth, sVec3D *verticesList, const int length)
    98101{
    99   printf("OBB Depth: %i, numVertices: %i\n", depth, length);
     102  PRINT(0)("\n");
     103  this->treeIndex = this->obbTree->getID();
     104  PRINTF(0)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length);
    100105  this->depth = depth;
    101106
     107
    102108  this->bvElement = new OBB();
    103   PRINTF(0)("Created OBBox\n");
     109  this->bvElement->vertices = verticesList;
     110  this->bvElement->numOfVertices = length;
     111  PRINTF(3)("Created OBBox\n");
    104112  this->calculateBoxCovariance(this->bvElement, verticesList, length);
    105   PRINTF(0)("Calculated attributes1\n");
     113  PRINTF(3)("Calculated attributes1\n");
    106114  this->calculateBoxEigenvectors(this->bvElement, verticesList, length);
    107   PRINTF(0)("Calculated attributes2\n");
     115  PRINTF(3)("Calculated attributes2\n");
    108116  this->calculateBoxAxis(this->bvElement, verticesList, length);
    109   PRINTF(0)("Calculated attributes3\n");
     117  PRINTF(3)("Calculated attributes3\n");
    110118
    111119
     
    114122    this->forkBox(this->bvElement);
    115123
    116     OBBTreeNode*       node1 = new OBBTreeNode();
    117     OBBTreeNode*       node2 = new OBBTreeNode();
    118 
    119     this->nodeLeft = node1;
    120     this->nodeRight = node2;
    121 
    122     this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);
    123     this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);
     124
     125    if(this->tmpLen1 > 2)
     126    {
     127      OBBTreeNode* node1 = new OBBTreeNode();
     128      this->nodeLeft = node1;
     129      this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);
     130    }
     131    else
     132    {
     133      PRINTF(0)("Aboarding tree walk: less than 3 vertices left\n");
     134    }
     135
     136    if( this->tmpLen2 > 2)
     137    {
     138      OBBTreeNode* node2 = new OBBTreeNode();
     139      this->nodeRight = node2;
     140      this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);
     141    }
     142    else
     143    {
     144      PRINTF(0)("Aboarding tree walk: less than 3 vertices left\n");
     145    }
    124146
    125147  }
     
    140162  this->numOfVertices = length;
    141163  this->vertices = verticesList;
    142   box->vertices = verticesList;
    143   box->numOfVertices = length;
     164
     165
    144166
    145167
     
    165187  /* take the average of the centroid sum */
    166188  center /= face;
    167   PRINTF(0)("-- Calculated Center\n");
     189  PRINTF(3)("-- Calculated Center\n");
    168190
    169191
     
    184206    }
    185207  }
    186   PRINTF(0)("-- Calculated Covariance\n");
    187 
    188 
    189 //   printf("\nVertex Data:\n");
    190 //   for(int i = 0; i < length; i++)
    191 //   {
    192 //     printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
    193 //   }
    194 
    195 //   printf("\nCovariance Matrix:\n");
     208  PRINTF(3)("-- Calculated Covariance\n");
     209
     210
     211  PRINTF(0)("\nVertex Data:\n");
     212  for(int i = 0; i < length; i++)
     213  {
     214    //PRINTF(0)("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
     215    PRINTF(0)("vertex %i: %f, %f, %f\n", i, box->vertices[i][0], box->vertices[i][1], box->vertices[i][2]);
     216  }
     217
     218//   PRINTF(3)("\nCovariance Matrix:\n");
    196219//   for(int j = 0; j < 3; ++j)
    197220//   {
    198 //     printf(" |");
     221//     PRINTF(3)(" |");
    199222//     for(int k = 0; k < 3; ++k)
    200223//     {
    201 //       printf(" \b%f ", covariance[j][k]);
     224//       PRINTF(3)(" \b%f ", covariance[j][k]);
    202225//     }
    203 //     printf(" |\n");
     226//     PRINTF(3)(" |\n");
    204227//   }
    205   PRINTF(0)("center: %f, %f, %f\n", center.x, center.y, center.z);
     228  PRINTF(3)("center: %f, %f, %f\n", center.x, center.y, center.z);
    206229
    207230
     
    213236//   }
    214237  *box->center = center;
    215   PRINTF(0)("-- Written Result to obb\n");
     238  PRINTF(3)("-- Written Result to obb\n");
    216239}
    217240
     
    235258  /* new jacobi tests */
    236259  JacobI(coMat, 3, eigvlMat, eigvMat, rotCount);
    237   PRINTF(0)("-- Done Jacobi Decomposition\n");
    238 
    239 
    240 //   printf("Jacobi\n");
     260  PRINTF(3)("-- Done Jacobi Decomposition\n");
     261
     262
     263//   PRINTF(3)("Jacobi\n");
    241264//   for(int j = 1; j < 4; ++j)
    242265//   {
    243 //     printf(" |");
     266//     PRINTF(3)(" |");
    244267//     for(int k = 1; k < 4; ++k)
    245268//     {
    246 //       printf(" \b%f ", eigvMat[j][k]);
     269//       PRINTF(3)(" \b%f ", eigvMat[j][k]);
    247270//     }
    248 //     printf(" |\n");
     271//     PRINTF(3)(" |\n");
    249272//   }
    250273
     
    253276  axis[2] = new Vector(eigvMat[1][3], eigvMat[2][3], eigvMat[3][3]);
    254277  box->axis = axis;
    255   PRINTF(0)("-- Got Axis\n");
    256 
    257 //   printf("\neigenvector: %f, %f, %f\n", box->axis[0]->x, box->axis[0]->y, box->axis[0]->z);
    258 //   printf("eigenvector: %f, %f, %f\n", box->axis[1]->x, box->axis[1]->y, box->axis[1]->z);
    259 //   printf("eigenvector: %f, %f, %f\n", box->axis[2]->x, box->axis[2]->y, box->axis[2]->z);
     278  PRINTF(3)("-- Got Axis\n");
     279
     280  PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[0]->x, box->axis[0]->y, box->axis[0]->z);
     281  PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[1]->x, box->axis[1]->y, box->axis[1]->z);
     282  PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[2]->x, box->axis[2]->y, box->axis[2]->z);
    260283}
    261284
     
    297320
    298321  box->halfLength = halfLength;
    299   PRINTF(0)("-- Written Axis to obb\n");
    300   PRINTF(0)("-- Finished Calculating Attributes\n");
    301 
    302 //   printf("\nwe got length: \n");
    303 //   for(int i = 0; i < 3; ++i)
    304 //     printf("length[%i] = %f\n", i, box->halfLength[i]);
     322  PRINTF(3)("-- Written Axis to obb\n");
     323  PRINTF(3)("-- Finished Calculating Attributes\n");
     324
     325
     326
     327//   PRINTF(3)("\nwe got length: \n");
     328  for(int i = 0; i < 3; ++i)
     329  {
     330    //if( box->halfLength[i] == 0.0)
     331      PRINTF(0)("length[%i] = %f\n", i, box->halfLength[i]);
     332  }
    305333}
    306334
     
    328356  }
    329357
    330 //   printf("\nlongest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength);
     358   PRINTF(0)("longest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength);
    331359
    332360
     
    347375  }
    348376
    349 //   printf("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist);
     377//   PRINTF(3)("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist);
    350378
    351379
     
    370398  partition1.add(&box->vertices[vertexIndex]);
    371399
    372 //   printf("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize());
     400//   PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize());
    373401
    374402
     
    395423  }
    396424
    397 //   printf("\npartition 1:\n");
     425//   PRINTF(0)("\npartition 1:\n");
    398426//   for(int i = 0; i < partition1.getSize(); ++i)
    399427//   {
    400 //     printf("v[%i][0] = %f\n", i, vertList1[i][0]);
    401 //     printf("v[%i][1] = %f\n", i, vertList1[i][1]);
    402 //     printf("v[%i][2] = %f\n", i, vertList1[i][2]);
     428//     PRINTF(0)("v[%i][0] = %f,\tv[%i][1] = %f,\tv[%i][1] = %f\n", i, vertList1[i][0], i, vertList1[i][1], i, vertList1[i][2]);
    403429//   }
    404430
     
    420446  this->tmpLen2 = partition2.getSize();
    421447
    422   //delete iterator;
    423 //   printf("\npartition 2:\n");
     448  delete iterator;
     449
     450//   PRINTF(0)("\npartition 2:\n");
    424451//   for(int i = 0; i < partition2.getSize(); ++i)
    425452//   {
    426 //     printf("v[%i][0] = %f\n", i, vertList2[i][0]);
    427 //     printf("v[%i][1] = %f\n", i, vertList2[i][1]);
    428 //     printf("v[%i][2] = %f\n", i, vertList2[i][2]);
     453//     PRINTF(0)("v[%i][0] = %f,\tv[%i][1] = %f,\tv[%i][1] = %f\n", i, vertList2[i][0], i,  vertList2[i][1], i, vertList2[i][2]);
    429454//   }
    430455}
     
    441466void OBBTreeNode::drawBV(int depth, int drawMode) const
    442467{
    443   //OBBTree::material->select();
    444 
    445   this->obbTree->getMaterial(depth)->select();
     468  this->obbTree->getMaterial(treeIndex)->select();
    446469
    447470  /* draw the model itself, there is some problem concerning this: the vertices are drawn multiple times */
    448471  if( drawMode & DRAW_MODEL || drawMode & DRAW_ALL)
    449472  {
    450     glBegin(GL_TRIANGLES);
    451     glColor3f(1.0, 1.0, 1.0);
    452     for(int i = 0; i < this->bvElement->numOfVertices; ++i)
    453     {
    454       glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
    455       //printf("v(%f, %f, %f)\n", this->vertices[i][0], this->vertices[i][1], this->vertices[i][2]);
    456     }
    457     glEnd();
     473    if( !(drawMode & DRAW_SINGLE && depth != 0))
     474    {
     475      glBegin(GL_LINE_STRIP);
     476      for(int i = 0; i < this->bvElement->numOfVertices; ++i)
     477      {
     478        glPushMatrix();
     479        glMatrixMode(GL_MODELVIEW);
     480      //glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
     481        glTranslatef(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
     482        gluSphere(this->sphereObj, 1, 10, 10);
     483        //PRINTF(0)("v(%f, %f, %f)\n", this->vertices[i][0], this->vertices[i][1], this->vertices[i][2]);
     484        glPopMatrix();
     485      }
     486      glEnd();
     487    }
    458488  }
    459489
     
    509539    /* draw bounding box */
    510540    glBegin(GL_LINE_LOOP);
    511     glColor3f(0.3, 0.4, 0.7);
    512541    glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
    513542               cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
     
    606635  for(int i = 0; i < length; i++)
    607636  {
    608   printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
     637  PRINTF(3)("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
    609638}
    610639  */
Note: See TracChangeset for help on using the changeset viewer.