Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2006, 1:30:44 PM (17 years ago)
Author:
patrick
Message:

merged the mount_point branche back to trunk to use the new std::* based obj file importer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/static_model.cc

    r9869 r10147  
    9191  this->updateBase();
    9292}
     93
     94
     95
     96/**
     97 * extract the mount points from this file: looking at each group and checking if the group realy is a mountpoint marker
     98 * if so get place and orientation
     99 */
     100void StaticModel::extractMountPoints()
     101{
     102
     103  // go through all groups and check if they are mounts
     104  std::vector<StaticModelData::Group>::const_iterator groupIt = this->data->getGroups().begin();
     105  for( ; groupIt != this->data->getGroups().end(); groupIt++)
     106  {
     107    //PRINTF(0)("Found a MountPoint: %s\n", groupName.c_str());
     108
     109    // get the name of this group and check if it's a mout point identifier
     110    std::string groupName = (*groupIt).name;
     111    std::vector<Vector> vertices;
     112
     113    if( groupName.find("MP.", 0) != std::string::npos)
     114    {
     115      PRINTF(0)("Found a MountPoint: %s\n", groupName.c_str());
     116
     117      // now check if it is a mount point identifier
     118      if( this->data->getGroups().size() != 5) {
     119        PRINTF(1)("the face count of %s is wrong, perhaps you missnamed this object or used the wrong mount point object\n", groupName.c_str());
     120      }
     121
     122      // now extract the direction from the length:
     123      std::vector<StaticModelData::Face>::const_iterator faceIt = (*groupIt)._faces.begin();
     124      for( ; faceIt < (*groupIt)._faces.end(); faceIt++)
     125      {
     126        // now go through all modelfaceelements
     127        std::vector<StaticModelData::FaceElement>::const_iterator faceElementIt = (*faceIt)._elements.begin();
     128        for( ; faceElementIt < (*faceIt)._elements.end(); faceElementIt++)
     129        {
     130          int vert = (*faceElementIt).vertexNumber;
     131          vertices.push_back(Vector(this->data->getVertices()[vert*3],
     132                             this->data->getVertices()[vert*3 + 1],
     133                             this->data->getVertices()[vert*3 + 2]));
     134        }
     135      }
     136
     137      // vertex with the max count is the up-point
     138      std::vector<Vector>::const_iterator it = vertices.begin();
     139      Vector tmpPoint;
     140      int tmpCount;
     141      Vector upPoint;
     142      int maxCount = 0;
     143      for( ; it < vertices.end(); it++)
     144      {
     145        tmpCount = 0;
     146        tmpPoint = (*it);
     147        //
     148        std::vector<Vector>::const_iterator it2 = vertices.begin();
     149        for( ; it2 < vertices.end(); it2++)
     150          if( tmpPoint == *it2)
     151            tmpCount++;
     152
     153        // if this is the vertex with the most surrounding vertices
     154        if( tmpCount > maxCount)
     155        {
     156          upPoint = tmpPoint;
     157          maxCount = tmpCount;
     158        }
     159      }
     160
     161      // now get the center of the object
     162      Vector center;
     163      it = vertices.begin();
     164      for( ; it < vertices.end(); it++)
     165        center += (*it);
     166      // scale
     167      center /= vertices.size();
     168
     169
     170    }
     171
     172  }
     173
     174
     175}
     176
     177
    93178
    94179/**
Note: See TracChangeset for help on using the changeset viewer.