Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4796 in orxonox.OLD for orxonox/trunk/src/lib


Ignore:
Timestamp:
Jul 6, 2005, 1:48:00 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: now counting the number of triangles to allocate the correct space

Location:
orxonox/trunk/src/lib/graphics/importer
Files:
2 edited

Legend:

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

    r4795 r4796  
    826826  this->normals->finalizeArray();
    827827
    828   if( unlikely((this->triangles = new sTriangleExt[this->vertices->getCount()]) == 0));
    829   {
    830     PRINTF(2)("Could not allocate memory for triangle list\n");
    831     return false;
    832   }
    833 
    834   int i = 0;                       //!< the counter for the triangle array
     828
     829  int index = 0;                   //!< the counter for the triangle array
    835830  ModelFaceElement* tmpElem;       //!< the temporary faceelement reference
    836831  ModelFace* tmpFace;              //!< the temporary face referece
    837832
     833  /* count the number of triangles */
    838834  /* now iterate through all groups and build up the triangle list */
    839835  this->currentGroup = this->firstGroup;
     
    849845      if( tmpFace->vertexCount == 3)
    850846      {
    851         for( int j = 0; j < 3; ++j)
    852         {
    853           this->triangles[i].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber;
    854           this->triangles[i].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber;
    855           tmpElem = tmpElem->next;
    856         }
    857         ++i;
     847        ++this->triangleCount;
    858848      } /* if the polygon is a quad */
    859849      else if( tmpFace->vertexCount == 4)
    860850      {
    861 
    862         this->triangles[i].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber;
    863         this->triangles[i].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber;
     851        this->triangleCount += 2;
     852      }
     853    }
     854    this->currentGroup = this->currentGroup->next;
     855  }
     856
     857  /* allocate memory for the new triangle structures */
     858  if( unlikely((this->triangles = new sTriangleExt[this->vertices->getCount()]) == 0));
     859  {
     860    PRINTF(2)("Could not allocate memory for triangle list\n");
     861    return false;
     862  }
     863
     864
     865  /* now iterate through all groups and build up the triangle list */
     866  this->currentGroup = this->firstGroup;
     867  while( this->currentGroup != NULL)
     868  {
     869      // Putting Faces to GL
     870    tmpFace = this->currentGroup->firstFace;
     871    while( tmpFace != NULL)
     872    {
     873      tmpElem = tmpFace->firstElem;
     874
     875      /* if its a triangle just add it to the list */
     876      if( tmpFace->vertexCount == 3)
     877      {
     878        for( int j = 0; j < 3; ++j)
     879        {
     880          this->triangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber;
     881          this->triangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber;
     882          tmpElem = tmpElem->next;
     883        }
     884        ++index;
     885      } /* if the polygon is a quad */
     886      else if( tmpFace->vertexCount == 4)
     887      {
     888
     889        this->triangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber;
     890        this->triangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber;
    864891        tmpElem = tmpElem->next;
    865892
    866         this->triangles[i].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber;
    867         this->triangles[i].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber;
     893        this->triangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber;
     894        this->triangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber;
    868895        tmpElem = tmpElem->next;
    869896
    870         this->triangles[i].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber;
    871         this->triangles[i].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber;
    872         ++i;
    873 
    874         this->triangles[i].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber;
    875         this->triangles[i].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber;
     897        this->triangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber;
     898        this->triangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber;
     899        ++index;
     900
     901        this->triangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber;
     902        this->triangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber;
    876903        tmpElem = tmpElem->next;
    877904
    878         this->triangles[i].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber;
    879         this->triangles[i].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber;
     905        this->triangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber;
     906        this->triangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber;
    880907        tmpElem = tmpElem->next;
    881908
    882         this->triangles[i].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber;
    883         this->triangles[i].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber;
    884         ++i;
     909        this->triangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber;
     910        this->triangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber;
     911        ++index;
    885912      }
    886913    }
  • orxonox/trunk/src/lib/graphics/importer/model.h

    r4794 r4796  
    175175  unsigned int     texCoordCount;   //!< A modelwide Counter for the texCoord.
    176176  unsigned int     faceCount;       //!< A modelwide Counter for the faces
     177  unsigned int     triangleCount;   //!< Number of triangles <= faceCount
    177178  Array<GLfloat>*  vertices;        //!< The Array that handles the Vertices.
    178179  Array<GLfloat>*  normals;         //!< The Array that handles the Normals.
Note: See TracChangeset for help on using the changeset viewer.