Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 20, 2005, 5:46:58 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: some segfault corrections :)

File:
1 edited

Legend:

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

    r4659 r4660  
    339339  vectors
    340340  */
    341   Vector**              axis = new Vector*[3];                //!< the references to the obb axis
     341  Vector*              axis = new Vector[3];                //!< the references to the obb axis
    342342
    343343  coMat[1][1] = box->covarianceMatrix[0][0]; coMat[1][2] = box->covarianceMatrix[0][1]; coMat[1][3] = box->covarianceMatrix[0][2];
     
    361361//   }
    362362
    363   axis[0] = new Vector(eigvMat[1][1], eigvMat[2][1], eigvMat[3][1]);
    364   axis[1] = new Vector(eigvMat[1][2], eigvMat[2][2], eigvMat[3][2]);
    365   axis[2] = new Vector(eigvMat[1][3], eigvMat[2][3], eigvMat[3][3]);
     363  axis[0].x = eigvMat[1][1]; axis[0].y = eigvMat[2][1]; axis[0].z = eigvMat[3][1];
     364  axis[1].x = eigvMat[1][2]; axis[1].y = eigvMat[2][2]; axis[1].z = eigvMat[3][2];
     365  axis[2].x = eigvMat[1][3]; axis[2].y = eigvMat[2][3]; axis[2].z = eigvMat[3][3];
    366366  box->axis = axis;
     367
    367368  PRINTF(3)("-- Got Axis\n");
    368369
    369   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[0]->x, box->axis[0]->y, box->axis[0]->z);
    370   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[1]->x, box->axis[1]->y, box->axis[1]->z);
    371   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[2]->x, box->axis[2]->y, box->axis[2]->z);
     370  PRINTF(3)("eigenvector: %f, %f, %f\n", box->axis[0].x, box->axis[0].y, box->axis[0].z);
     371  PRINTF(3)("eigenvector: %f, %f, %f\n", box->axis[1].x, box->axis[1].y, box->axis[1].z);
     372  PRINTF(3)("eigenvector: %f, %f, %f\n", box->axis[2].x, box->axis[2].y, box->axis[2].z);
    372373}
    373374
     
    380381  float*              halfLength = new float[3];             //!< half length of the axis
    381382  float               tmpLength;                             //!< tmp save point for the length
    382   Plane               p0(*box->axis[0], *box->center);       //!< the axis planes
    383   Plane               p1(*box->axis[1], *box->center);
    384   Plane               p2(*box->axis[2], *box->center);
     383  Plane               p0(box->axis[0], *box->center);       //!< the axis planes
     384  Plane               p1(box->axis[1], *box->center);
     385  Plane               p2(box->axis[2], *box->center);
    385386  float               maxLength[3];
    386387  float               minLength[3];
     
    415416
    416417  /* get the maximal dimensions of the body in all directions */
    417 //   maxLength[0] = 0.0f;
    418 //   minLength[0] = 0.0f;
    419 //   for(int j = 0; j < length; ++j)
    420 //   {
    421 //     tmpLength = p0.distancePoint(vertices[j]);
    422 //     if( tmpLength > maxLength[0])
    423 //       maxLength[0] = tmpLength;
    424 //     else if( tmpLength < minLength[0])
    425 //       minLength[0] = tmpLength;
    426 //   }
    427 //
    428 //   maxLength[1] = 0.0f;
    429 //   minLength[1] = 0.0f;
    430 //   for(int j = 0; j < length; ++j)
    431 //   {
    432 //     tmpLength = p0.distancePoint(vertices[j]);
    433 //     if( tmpLength > maxLength[1])
    434 //       maxLength[1] = tmpLength;
    435 //     else if( tmpLength < minLength[1])
    436 //       minLength[1] = tmpLength;
    437 //   }
    438 //
    439 //   maxLength[2] = 0.0f;
    440 //   minLength[2] = 0.0f;
    441 //   for(int j = 0; j < length; ++j)
    442 //   {
    443 //     tmpLength = p0.distancePoint(vertices[j]);
    444 //     if( tmpLength > maxLength[2])
    445 //       maxLength[2] = tmpLength;
    446 //     else if( tmpLength < minLength[2])
    447 //       minLength[2] = tmpLength;
    448 //   }
    449 //
    450 //
    451 //   /* calculate the real centre of the body by using the axis length */
    452 //   float center[3];
    453 //   float offset[3];
    454 //   for(int i = 0; i < 3; ++i)
    455 //     {
    456 //       center[i] = (maxLength[i] - minLength[i]) / 2.0f; // min length is negative
    457 //       offset[i] = halfLength[i] - center[i];
    458 //       box->center[i] +=  *box->axis[i] * offset[i];            // update the new center vector
    459 //       PRINTF(0)("Center Translation Operation: halfLength old: %f, new: %f\n", halfLength[i], center[i]);
    460 //       halfLength[i] = center[i];
    461 //     }
     418   maxLength[0] = 0.0f;
     419   minLength[0] = 0.0f;
     420   for(int j = 0; j < length; ++j)
     421   {
     422     tmpLength = p0.distancePoint(vertices[j]);
     423     if( tmpLength > maxLength[0])
     424       maxLength[0] = tmpLength;
     425     else if( tmpLength < minLength[0])
     426       minLength[0] = tmpLength;
     427   }
     428
     429   maxLength[1] = 0.0f;
     430   minLength[1] = 0.0f;
     431   for(int j = 0; j < length; ++j)
     432   {
     433     tmpLength = p0.distancePoint(vertices[j]);
     434     if( tmpLength > maxLength[1])
     435       maxLength[1] = tmpLength;
     436     else if( tmpLength < minLength[1])
     437       minLength[1] = tmpLength;
     438   }
     439
     440   maxLength[2] = 0.0f;
     441   minLength[2] = 0.0f;
     442   for(int j = 0; j < length; ++j)
     443   {
     444     tmpLength = p0.distancePoint(vertices[j]);
     445     if( tmpLength > maxLength[2])
     446       maxLength[2] = tmpLength;
     447     else if( tmpLength < minLength[2])
     448       minLength[2] = tmpLength;
     449   }
     450
     451
     452   /* calculate the real centre of the body by using the axis length */
     453   float center[3];
     454   float offset[3];
     455   for(int i = 0; i < 3; ++i)
     456     {
     457       center[i] = (maxLength[i] - minLength[i]) / 2.0f; // min length is negative
     458       offset[i] = halfLength[i] - center[i];
     459       //PRINTF(0)("Center Orig: %f, %f, %f ---- new: %f, %f, %f", box->center[]);
     460       *box->center +=  (box->axis[i] * offset[i]);            // update the new center vector
     461       PRINTF(0)("Center Translation Operation: halfLength old: %f, new: %f\n", halfLength[i], center[i]);
     462       halfLength[i] = center[i];
     463     }
    462464
    463465
     
    473475  {
    474476    //if( box->halfLength[i] == 0.0)
    475       PRINTF(0)("length[%i] = %f\n", i, box->halfLength[i]);
     477    PRINTF(3)("length[%i] = %f\n", i, box->halfLength[i]);
    476478  }
    477479}
     
    507509  float               tmpDist;                             //!< temporary distance
    508510  int                 vertexIndex;
    509   Plane               middlePlane(*box->axis[axisIndex], *box->center); //!< the middle plane
    510 
     511  Plane               middlePlane(box->axis[axisIndex], *box->center); //!< the middle plane
     512
     513  vertexIndex = 0;
    511514  for(int i = 0; i < box->numOfVertices; ++i)
    512515  {
     
    528531  tList<sVec3D>      partition2;                           //!< the vertex partition 2
    529532
    530 
    531   this->separationPlane = new Plane(*box->axis[axisIndex], box->vertices[vertexIndex]);  //!< separation plane
     533  printf("vertex index: %i, of %i\n", vertexIndex, box->numOfVertices);
     534  this->separationPlane = new Plane(box->axis[axisIndex], box->vertices[vertexIndex]);  //!< separation plane
    532535  this->sepPlaneCenter = &box->vertices[vertexIndex];
    533536  this->longestAxisIndex = axisIndex;
     
    655658      glColor3f(0.0, 0.4, 0.3);
    656659      glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
    657       glVertex3f(this->bvElement->center->x + this->bvElement->axis[0]->x * this->bvElement->halfLength[0],
    658                  this->bvElement->center->y + this->bvElement->axis[0]->y * this->bvElement->halfLength[0],
    659                  this->bvElement->center->z + this->bvElement->axis[0]->z * this->bvElement->halfLength[0]);
     660      glVertex3f(this->bvElement->center->x + this->bvElement->axis[0].x * this->bvElement->halfLength[0],
     661                 this->bvElement->center->y + this->bvElement->axis[0].y * this->bvElement->halfLength[0],
     662                 this->bvElement->center->z + this->bvElement->axis[0].z * this->bvElement->halfLength[0]);
    660663
    661664      glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
    662       glVertex3f(this->bvElement->center->x + this->bvElement->axis[1]->x * this->bvElement->halfLength[1],
    663                  this->bvElement->center->y + this->bvElement->axis[1]->y * this->bvElement->halfLength[1],
    664                  this->bvElement->center->z + this->bvElement->axis[1]->z * this->bvElement->halfLength[1]);
     665      glVertex3f(this->bvElement->center->x + this->bvElement->axis[1].x * this->bvElement->halfLength[1],
     666                 this->bvElement->center->y + this->bvElement->axis[1].y * this->bvElement->halfLength[1],
     667                 this->bvElement->center->z + this->bvElement->axis[1].z * this->bvElement->halfLength[1]);
    665668
    666669      glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
    667       glVertex3f(this->bvElement->center->x + this->bvElement->axis[2]->x * this->bvElement->halfLength[2],
    668                  this->bvElement->center->y + this->bvElement->axis[2]->y * this->bvElement->halfLength[2],
    669                  this->bvElement->center->z + this->bvElement->axis[2]->z * this->bvElement->halfLength[2]);
     670      glVertex3f(this->bvElement->center->x + this->bvElement->axis[2].x * this->bvElement->halfLength[2],
     671                 this->bvElement->center->y + this->bvElement->axis[2].y * this->bvElement->halfLength[2],
     672                 this->bvElement->center->z + this->bvElement->axis[2].z * this->bvElement->halfLength[2]);
    670673      glEnd();
    671674    }
     
    678681    {
    679682    Vector cen = *this->bvElement->center;
    680     Vector** axis = this->bvElement->axis;
     683    Vector* axis = this->bvElement->axis;
    681684    float* len = this->bvElement->halfLength;
    682685
    683686    /* draw bounding box */
    684687    glBegin(GL_LINE_LOOP);
    685     glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
    686                cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
    687                cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
    688     glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
    689                cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
    690                cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
    691     glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
    692                cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
    693                cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
    694     glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
    695                cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
    696                cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
     688    glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
     689               cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
     690               cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
     691    glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
     692               cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
     693               cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
     694    glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
     695               cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
     696               cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
     697    glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
     698               cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
     699               cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
    697700    glEnd();
    698701
    699702    glBegin(GL_LINE_LOOP);
    700     glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
    701                cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
    702                cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
    703     glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
    704                cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
    705                cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
    706     glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
    707                cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
    708                cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
    709     glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
    710                cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
    711                cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
     703    glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
     704               cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
     705               cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
     706    glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
     707               cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
     708               cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
     709    glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
     710               cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
     711               cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
     712    glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
     713               cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
     714               cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
    712715    glEnd();
    713716
    714717    glBegin(GL_LINE_LOOP);
    715     glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
    716                cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
    717                cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
    718     glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
    719                cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
    720                cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
    721     glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
    722                cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
    723                cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
    724     glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
    725                cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
    726                cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
     718    glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
     719               cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
     720               cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
     721    glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
     722               cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
     723               cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
     724    glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
     725               cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
     726               cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
     727    glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
     728               cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
     729               cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
    727730    glEnd();
    728731
    729732    glBegin(GL_LINE_LOOP);
    730     glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
    731                cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
    732                cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
    733     glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
    734                cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
    735                cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
    736     glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
    737                cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
    738                cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
    739     glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
    740                cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
    741                cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
     733    glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
     734               cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
     735               cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
     736    glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
     737               cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
     738               cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
     739    glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
     740               cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
     741               cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
     742    glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
     743               cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
     744               cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
    742745    glEnd();
    743746    }
     
    750753    {
    751754    /* now draw the separation plane */
    752     Vector a1 = *this->bvElement->axis[(this->longestAxisIndex + 1)%3];
    753     Vector a2 = *this->bvElement->axis[(this->longestAxisIndex + 2)%3];
     755    Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3];
     756    Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3];
    754757    Vector c = *this->bvElement->center;
    755758    float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3];
Note: See TracChangeset for help on using the changeset viewer.