Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4557 in orxonox.OLD


Ignore:
Timestamp:
Jun 8, 2005, 4:07:28 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: some structural updates

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

Legend:

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

    r4511 r4557  
    2727{
    2828   this->setClassID(CL_BOUNDING_VOLUME, "BoundingVolume");
     29   this->center = new Vector();
    2930
    3031}
     
    3839{
    3940  // delete what has to be deleted here
     41  delete this->center;
    4042}
  • orxonox/trunk/src/lib/collision_detection/bounding_volume.h

    r4542 r4557  
    3535  Vector*             center;                     //!< Center point of box
    3636
    37   tList<sVect3D>*     verticesBuffer;             //!< if CD_STORE_VERTICES enabled, this is the place, where the vert. will be sotred
     37  sVect3D*            vertices;                   //!< if CD_STORE_VERTICES enabled, this is the place, where the vert. will be sotred
     38  int                 numOfVertices;              //!< number of vertices in the vertices buffer
    3839};
    3940
  • orxonox/trunk/src/lib/collision_detection/obb.cc

    r4542 r4557  
    1818#include "obb.h"
    1919#include "list.h"
     20#include "vector.h"
    2021
    2122using namespace std;
     
    2829{
    2930   this->setClassID(CL_OBB, "OBB");
     31   this->axis = new Vector[3];
     32   this->halfLength = new float[3];
    3033}
    3134
     
    3841{
    3942  // delete what has to be deleted here
     43  delete [] this->axis;
     44  delete [] this->halfLength;
    4045}
    4146
  • orxonox/trunk/src/lib/collision_detection/obb.h

    r4542 r4557  
    3232
    3333
    34  private:
     34 public:
    3535  Vector*          axis;                       //!< Axes of oriented box [x,y,z]
    36   sVect3D*         halfLength;                 //!< Half lengths of the box
     36  float*           halfLength;                 //!< Half lengths of the box along the axis
     37  float            covarianceMatrix[3][3];     //!< the covariance matrix
    3738
    38   OBB*             leftNode;                   //!< left node of the tree
    39   OBB*             rightNode;                  //!< right node of the tree
    4039};
    4140
  • orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc

    r4553 r4557  
    5555void OBBTreeNode::spawnBVTree(const int depth, sVec3D *verticesList, const int length)
    5656{
     57  this->bvElement = this->createBox();
     58  this->calculateBoxAttributes(box);
     59  this->forkBox(box);
     60}
     61
     62
     63OBB* OBBTreeNode::createBox()
     64{
     65  return new OBB();
     66}
     67
     68
     69void OBBTreeNode::calculateBoxAttributes(OBB* box)
     70{
    5771  float     facelet[length];                         //!< surface area of the i'th triangle of the convex hull
    5872  float     face;                                    //!< surface area of the entire convex hull
    5973  Vector    centroid[length];                        //!< centroid of the i'th convex hull 
    60   Vector    centre;                                  //!< the centre of the entire hull
    61   OBB*      obb = new OBB();                         //!< the new obb to add
     74  Vector    center;                                  //!< the center of the entire hull
    6275  Vector    p, q, r;                                 //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d
    6376  Vector    t1, t2;                                  //!< temporary values
     
    8598      centroid[i] = (p + q + r) * 1/3;
    8699      /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
    87       centre += centroid[i] * facelet[i];
     100      center += centroid[i] * facelet[i];
    88101    }
    89102  /* take the average of the centroid sum */
    90   centre /= face;
     103  center /= face;
    91104 
    92105  /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */
     
    102115
    103116              covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] +
    104                                                                 q[j] * q[k] + r[j]*r[k]) - centre[j] * centre[k];
     117                                                                q[j] * q[k] + r[j]*r[k]) - center[j] * center[k];
    105118            }
    106119        }
    107120    }
    108 
     121 
    109122  printf("Covariance Matrix:\n");
    110123  for(int j = 0; j < 3; ++j)
     
    123136      printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
    124137    }
     138
     139
     140   
     141  box->covarianceMatrix = covariance;
     142  box->center = center;
     143
     144
     145  /* now getting spanning vectors of the sub-space:
     146     the eigenvectors of a symmertric matrix, such as the
     147     covarience matrix are mutually orthogonal.
     148     after normalizing them, they can be used as a the basis
     149     vectors
     150  */
     151 
     152
     153}
     154
     155
     156void OBBTreeNode::forkBox(OBB* box)
     157{
     158  /* get the longest axis of the box */
     159  float aLength = -1.0f;
     160  int axisNr = 0;
     161  for(int i = 0; i < 3; ++i)
     162    {
     163      if( aLength < box->axis[i])
     164        {
     165          aLength = box->axis[i];
     166          axisNr = i;
     167        }
     168    }
     169 
     170  /* get the closest vertex near the center */
    125171 
    126172}
     
    145191
    146192void OBBTreeNode::drawBVPolygon(int currentDepth, const int depth) const
    147 {}
     193{
     194  this->bvElement->axis;
     195 
     196  glBegin(GL_TRIANGLE);
     197  glVertex3f(this->bvElement->center );
     198  glEnd();
     199}
    148200
    149201
  • orxonox/trunk/src/lib/collision_detection/obb_tree_node.h

    r4553 r4557  
    1414// FORWARD DEFINITION
    1515class BoundingVolume;
     16class OBB;
    1617//struct sVec3D;
    1718
     
    3536  virtual void drawBVBlended(int currentDepth, const int depth) const;
    3637
     38 private:
     39  OBB* createBox();
     40  void calculateBoxAttributes(OBB* box);
     41  void forkBox(OBB* box);
     42 
     43
    3744
    3845 protected:
Note: See TracChangeset for help on using the changeset viewer.