Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6031 in orxonox.OLD


Ignore:
Timestamp:
Dec 10, 2005, 11:18:19 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: cleanup in the StaticModel class, as my idea changed

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

Legend:

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

    r6022 r6031  
    3232////////////////////
    3333/**
    34  * creates a new ModelFaceElement
    35 */
     34 * @brief creates a new ModelFaceElement
     35 */
    3636ModelFaceElement::ModelFaceElement()
    3737{
     
    4444
    4545/**
    46  * destroys a ModelFaceElement
    47 */
     46 * @brief destroys a ModelFaceElement
     47 */
    4848ModelFaceElement::~ModelFaceElement()
    4949{
     
    5353
    5454/**
    55  * creates a new ModelFace
    56 */
     55 * @brief creates a new ModelFace
     56 */
    5757ModelFace::ModelFace()
    5858{
     
    8181
    8282/**
    83  * Creates a new ModelGroup
    84 */
     83 * @brief Creates a new ModelGroup
     84 */
    8585ModelGroup::ModelGroup()
    8686{
     
    9797
    9898/**
    99  * deletes a ModelGroup
    100 */
     99 * @brief deletes a ModelGroup
     100 */
    101101ModelGroup::~ModelGroup()
    102102{
     
    118118
    119119/**
    120  * cleans up a ModelGroup
    121 
    122    actually does the same as the delete Operator, but does not delete the predecessing group
    123 */
     120 * @brief cleans up a ModelGroup
     121 *
     122 * actually does the same as the delete Operator, but does not delete the predecessing group
     123 */
    124124void ModelGroup::cleanup()
    125125{
     
    137137/////////////
    138138/**
    139  * Creates a 3D-Model.
    140 
    141    assigns it a Name and a Type
    142 */
    143 StaticModel::StaticModel(const char* modelName, MODEL_TYPE type)
     139 * @brief Creates a 3D-Model.
     140 *
     141 * assigns it a Name and a Type
     142 */
     143StaticModel::StaticModel(const char* modelName)
    144144{
    145145  this->setClassID(CL_MODEL, "Model");
    146146  PRINTF(4)("new 3D-Model is being created\n");
    147147  this->setName(modelName);
    148   this->type = type;
    149148
    150149  this->finalized = false;
     150
    151151  // setting the start group;
    152152  this->currentGroup = this->firstGroup = new ModelGroup;
    153153  this->groupCount = 0;
    154   this->vertexCount = 0;
    155   this->normalCount = 0;
    156   this->texCoordCount = 0;
    157154  this->faceCount = 0;
    158   this->triangleCount = 0;
    159   this->triangles = NULL;
    160 
    161   this->scaleFactor = 1;
    162 
    163   this->vertices = new tArray<GLfloat>();
    164   this->vTexture = new tArray<GLfloat>();
    165   this->normals = new tArray<GLfloat>();
    166 
    167   if (this->type == MODEL_VERTEX_ARRAY)
    168     glEnableClientState(GL_VERTEX_ARRAY | GL_NORMAL_ARRAY | GL_TEXTURE_COORD_ARRAY);
    169 }
    170 
    171 /**
    172  *  deletes an Model.
    173 
    174    Looks if any from model allocated space is still in use, and if so deleted it.
    175 */
     155
     156  this->scaleFactor = 1.0f;
     157}
     158
     159/**
     160 * @brief deletes an Model.
     161 *
     162 * Looks if any from model allocated space is still in use, and if so deleted it.
     163 */
    176164StaticModel::~StaticModel()
    177165{
     
    190178  delete this->firstGroup;
    191179
    192   // deleting Arrays (if not allready done by finalize)
    193   this->deleteArrays();
    194 
    195180  // deleting the MaterialList
    196181  PRINTF(5)("Deleting Materials.\n");
     
    207192
    208193/**
    209  * Finalizes an Object. This can be done outside of the Class.
    210 */
     194 * @brief Finalizes an Object. This can be done outside of the Class.
     195 */
    211196void StaticModel::finalize()
    212197{
     
    215200  this->buildTriangleList();
    216201
    217   // deletes everything we allocated.
    218   //if (this->type == MODEL_DISPLAY_LIST)
    219     //this->deleteArrays();
    220   //  this->cleanup();
    221 
    222   /* load the ModelInfo */
    223   this->pModelInfo.numVertices = this->vertexCount;
    224   this->pModelInfo.pVertices = this->vertices->getArray();
    225   this->pModelInfo.numTriangles = this->triangleCount;
    226   this->pModelInfo.pTriangles = this->triangles;
    227   this->pModelInfo.numNormals = this->normalCount;
    228   this->pModelInfo.pNormals = this->normals->getArray();
    229   this->pModelInfo.numTexCoor = this->vTexture->getCount();
    230   this->pModelInfo.pTexCoor = this->vTexture->getArray();
     202  this->pModelInfo.pVertices = this->vertices.getArray();
     203  this->pModelInfo.pNormals = this->normals.getArray();
     204  this->pModelInfo.pTexCoor = this->vTexture.getArray();
    231205
    232206  this->finalized = true;
     
    234208
    235209/**
    236  * rebuild the Model from the Information we got.
     210 * @brief rebuild the Model from the Information we got.
    237211 */
    238212void StaticModel::rebuild()
     
    240214  PRINTF(3)("Rebuilding Model '%s'\n", this->getName());
    241215  this->finalize();
    242 
    243216}
    244217
     
    252225void StaticModel::draw () const
    253226{
    254 
    255227  PRINTF(4)("drawing the 3D-Models\n");
    256228  ModelGroup* tmpGroup = this->firstGroup;
     
    262234    }
    263235
    264 
    265 /*  const GLfloat* pVertices = NULL;
    266   const GLfloat* pNorm = NULL;
    267 
    268   glBegin(GL_TRIANGLES);
    269   for( int i = 0; i < this->triangleCount; ++i)
    270   {
     236  /*
     237    const GLfloat* pVertices = NULL;
     238    const GLfloat* pNorm = NULL;
     239   
     240    glBegin(GL_TRIANGLES);
     241    for( int i = 0; i < this->triangleCount; ++i)
     242    {
    271243    //printf("int i = %i\n", i);
    272244    pNorm = &this->normals->getArray()[this->triangles[i].indexToNormals[0]];
     
    285257    glVertex3f(pVertices[0], pVertices[1], pVertices[2]);
    286258
    287   }
    288   glEnd();*/
    289 }
    290 
    291 /**
    292  *  Draws the Model number groupNumber
     259    }
     260    glEnd();
     261  */
     262}
     263
     264
     265/**
     266 * @brief Draws the Model number groupNumber
    293267 * @param groupNumber The number of the group that will be displayed.
    294 
    295    It does this by just calling the List that must have been created earlier.
    296 */
     268 *
     269 * It does this by just calling the List that must have been created earlier.
     270 */
    297271void StaticModel::draw (int groupNumber) const
    298272{
    299   if (groupNumber >= this->groupCount)
     273  if (unlikely(groupNumber >= this->groupCount))
    300274    {
    301275      PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount);
     
    318292  PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->getName());
    319293  return;
    320 
    321 }
    322 
    323 /**
    324  * Draws the Model with a specific groupName
     294}
     295
     296
     297/**
     298 * @brief Draws the Model with a specific groupName
    325299 * @param groupName The name of the group that will be displayed.
    326 
    327    It does this by just calling the List that must have been created earlier.
    328 */
     300 *
     301 * It does this by just calling the List that must have been created earlier.
     302 */
    329303void StaticModel::draw (char* groupName) const
    330304{
     
    348322// INIT //
    349323//////////
    350 /**
    351  *  deletes all the arrays
    352 */
    353 bool StaticModel::deleteArrays()
    354 {
    355   if (this->vertices)
    356     delete this->vertices;
    357   if (this->vTexture)
    358     delete this->vTexture;
    359   if (this->normals)
    360     delete this->normals;
    361   if (this->triangles)
    362     delete[] this->triangles;
    363 
    364   this->vertices = NULL;
    365   this->vTexture = NULL;
    366   this->normals = NULL;
    367   this->triangles = NULL;
    368   this->triangleCount = 0;
    369 }
    370 
    371 /**
    372  *  finalizes an Model.
     324
     325/**
     326 * @brief finalizes an Model.
     327 *
    373328 * This funcion is needed, to delete all the Lists, and arrays that are no more
    374329 * needed because they are already imported into openGL.
     
    386341//////////
    387342/**
    388  * adds a new Material to the Material List
     343 * @brief adds a new Material to the Material List
    389344 * @param material the Material to add
    390345 * @returns the added material
     
    405360
    406361/**
    407  * adds a new Material to the Material List
     362 * @brief adds a new Material to the Material List
    408363 * @param materialName the name of the Material to add
    409364 * @returns the added material
    410 */
     365 */
    411366Material* StaticModel::addMaterial(const char* materialName)
    412367{
     
    421376
    422377/**
    423  * finds a Material by its name and returns it
     378 * @brief finds a Material by its name and returns it
    424379 * @param materialName the Name of the material to search for.
    425380 * @returns the Material if found, NULL otherwise
    426 */
     381 */
    427382Material* StaticModel::findMaterialByName(const char* materialName)
    428383{
     
    435390
    436391/**
    437  * parses a group String
     392 * @brief parses a group String
    438393 * @param groupString the new Group to create
    439 
    440    This function initializes a new Group.
    441    With it you should be able to create Models with more than one SubModel inside
    442 */
     394 *
     395 * This function initializes a new Group.
     396 * With it you should be able to create Models with more than one SubModel inside
     397 */
    443398bool StaticModel::addGroup(const char* groupString)
    444399{
     
    459414
    460415/**
    461  * parses a vertex-String
     416 * @brief parses a vertex-String
    462417 * @param vertexString The String that will be parsed.
    463 
    464    If a vertex line is found this function will inject it into the vertex-Array
    465 */
     418 *
     419 *  If a vertex line is found this function will inject it into the vertex-Array
     420 */
    466421bool StaticModel::addVertex (const char* vertexString)
    467422{
     
    470425  float subbuffer3;
    471426  sscanf (vertexString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
    472   this->vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor);
    473   this->vertexCount++;
     427  this->vertices.addEntry(subbuffer1*scaleFactor,
     428                          subbuffer2*scaleFactor,
     429                          subbuffer3*scaleFactor);
     430  this->pModelInfo.numVertices++;
    474431  return true;
    475432}
    476433
    477434/**
    478  * parses a vertex-String
     435 * @brief parses a vertex-String
    479436 * @param x the X-coordinate of the Vertex to add.
    480437 * @param y the Y-coordinate of the Vertex to add.
    481438 * @param z the Z-coordinate of the Vertex to add.
    482 
    483 */
     439 */
    484440bool StaticModel::addVertex(float x, float y, float z)
    485441{
    486442  PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z);
    487   this->vertices->addEntry(x*scaleFactor, y*scaleFactor, z*scaleFactor);
    488   this->vertexCount++;
     443  this->vertices.addEntry(x*scaleFactor,
     444                          y*scaleFactor,
     445                          z*scaleFactor);
     446  this->pModelInfo.numVertices++;
    489447  return true;
    490448}
    491449
    492450/**
    493  * parses a vertexNormal-String
     451 * @brief parses a vertexNormal-String
    494452 * @param normalString The String that will be parsed.
    495 
    496    If a vertexNormal line is found this function will inject it into the vertexNormal-Array
    497 */
     453 *
     454 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array
     455 */
    498456bool StaticModel::addVertexNormal (const char* normalString)
    499457{
     
    502460  float subbuffer3;
    503461  sscanf (normalString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
    504   this->normals->addEntry(subbuffer1, subbuffer2, subbuffer3);
    505   this->normalCount++;
     462  this->normals.addEntry(subbuffer1, subbuffer2, subbuffer3);
     463  this->pModelInfo.numNormals++;
    506464  return true;
    507465}
    508466
    509467/**
    510  * adds a VertexNormal.
     468 * @brief adds a VertexNormal.
    511469 * @param x The x coordinate of the Normal.
    512470 * @param y The y coordinate of the Normal.
    513471 * @param z The z coordinate of the Normal.
    514 
    515    If a vertexNormal line is found this function will inject it into the vertexNormal-Array
    516 */
     472 *
     473 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array
     474 */
    517475bool StaticModel::addVertexNormal(float x, float y, float z)
    518476{
    519477  PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z);
    520   this->normals->addEntry(x, y, z);
    521   this->normalCount++;
     478  this->normals.addEntry(x, y, z);
     479  this->pModelInfo.numNormals++;
    522480  return true;
    523481}
    524482
    525483/**
    526  * parses a vertexTextureCoordinate-String
     484 * @brief parses a vertexTextureCoordinate-String
    527485 * @param vTextureString The String that will be parsed.
    528 
    529    If a vertexTextureCoordinate line is found,
    530    this function will inject it into the vertexTexture-Array
    531 
    532    !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !!
    533 */
     486 *
     487 * If a vertexTextureCoordinate line is found,
     488 * this function will inject it into the vertexTexture-Array
     489 *
     490 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !!
     491 */
    534492bool StaticModel::addVertexTexture (const char* vTextureString)
    535493{
     
    537495  float subbuffer2;
    538496  sscanf (vTextureString, "%f %f", &subbuffer1, &subbuffer2);
    539   this->vTexture->addEntry(subbuffer1);
    540   this->vTexture->addEntry(1 - subbuffer2);
    541   this->texCoordCount++;
     497  this->vTexture.addEntry(subbuffer1);
     498  this->vTexture.addEntry(1 - subbuffer2);
     499  this->pModelInfo.numTexCoor++;
    542500  return true;
    543501}
    544502
    545503/**
    546  * adds a Texture Coordinate
     504 * @brief adds a Texture Coordinate
    547505 * @param u The u coordinate of the TextureCoordinate.
    548506 * @param v The y coordinate of the TextureCoordinate.
    549 
    550    If a TextureCoordinate line is found this function will inject it into the TextureCoordinate-Array
    551 */
     507 *
     508 * If a TextureCoordinate line is found this function will
     509 *  inject it into the TextureCoordinate-Array
     510 */
    552511bool StaticModel::addVertexTexture(float u, float v)
    553512{
    554513  PRINTF(5)("found vertex-Texture %f, %f\n", u, v);
    555   this->vTexture->addEntry(u);
    556   this->vTexture->addEntry(v);
    557   this->texCoordCount++;
     514  this->vTexture.addEntry(u);
     515  this->vTexture.addEntry(v);
     516  this->pModelInfo.numTexCoor++;
    558517  return true;
    559518}
    560519
    561520/**
    562  * parses a face-string
     521 * @brief parses a face-string
    563522 * @param faceString The String that will be parsed.
    564 
    565    If a face line is found this function will add it to the glList.
    566 
    567    String is different from the argument addFace, in this that the first Vertex/Normal/Texcoord is 1 instead of 0
    568 */
     523 *
     524 * If a face line is found this function will add it to the glList.
     525 *
     526 * String is different from the argument addFace,
     527 * in this, that the first Vertex/Normal/Texcoord is 1 instead of 0
     528 */
    569529bool StaticModel::addFace (const char* faceString)
    570530{
     
    613573      this->currentGroup->currentFace->vertexCount++;
    614574    }
    615 
     575 
    616576  this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2;
    617577  this->faceCount += this->currentGroup->currentFace->vertexCount -2;
     
    619579
    620580/**
    621  * adds a new Face
     581 * @brief adds a new Face
    622582 * @param faceElemCount the number of Vertices to add to the Face.
    623583 * @param type The information Passed with each Vertex
     
    663623
    664624  if (this->currentGroup->faceCount == 0)
    665     this->currentGroup->faceCount ++;
     625    this->currentGroup->faceCount++;
    666626}
    667627
     
    678638
    679639  if (this->currentGroup->faceCount == 0)
    680     this->currentGroup->faceCount ++;
    681 }
    682 
    683 /**
    684  * A routine that is able to create normals.
    685 
    686    The algorithm does the following:
    687    1. It calculates creates Vectors for each normale, and sets them to zero.
    688    2. It then Walks through a) all the Groups b) all the Faces c) all the FaceElements
    689    3. It searches for a points two neighbours per Face, takes Vecotrs to them calculates FaceNormals and adds it to the Points Normal.
    690    4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array.
    691 */
     640    this->currentGroup->faceCount++;
     641}
     642
     643/**
     644 * @brief A routine that is able to create normals.
     645 *
     646 * The algorithm does the following:
     647 * 1. It calculates creates Vectors for each normale, and sets them to zero.
     648 * 2. It then Walks through a) all the Groups b) all the Faces c) all the FaceElements
     649 * 3. It searches for a points two neighbours per Face, takes Vecotrs to them calculates FaceNormals and adds it to the Points Normal.
     650 * 4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array.
     651 */
    692652bool StaticModel::buildVertexNormals ()
    693653{
    694654  PRINTF(4)("Normals are being calculated.\n");
    695655
    696   Vector* normArray = new Vector [vertices->getCount()/3];
    697   for (int i=0; i<vertices->getCount()/3;i++)
     656  Vector* normArray = new Vector [vertices.getCount()/3];
     657  for (int i=0; i<vertices.getCount()/3;i++)
    698658    normArray[i] = Vector(.0,.0,.0);
    699659
     
    705665
    706666  ModelGroup* tmpGroup = firstGroup;
    707   while (tmpGroup)
     667  while (tmpGroup != NULL)
    708668    {
    709669      ModelFace* tmpFace = tmpGroup->firstFace;
    710       while (tmpFace)
     670      while (tmpFace != NULL)
    711671        {
    712           if (tmpFace->firstElem)
     672          if (tmpFace->firstElem != NULL)
    713673            {
    714674              ModelFaceElement* firstElem = tmpFace->firstElem;
     
    718678              ModelFaceElement* lastElem;
    719679              // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop.
    720               while (curElem)
     680              while (curElem != NULL)
    721681                {
    722682                  prevElem = curElem;
     
    732692                  curElem->normalNumber = curElem->vertexNumber;
    733693
    734                   curV = Vector (vertices->getArray()[curElem->vertexNumber*3], vertices->getArray()[curElem->vertexNumber*3+1], vertices->getArray()[curElem->vertexNumber*3+2]);
    735                   prevV = Vector (vertices->getArray()[prevElem->vertexNumber*3], vertices->getArray()[prevElem->vertexNumber*3+1], vertices->getArray()[prevElem->vertexNumber*3+2]) - curV;
    736                   nextV = Vector (vertices->getArray()[nextElem->vertexNumber*3], vertices->getArray()[nextElem->vertexNumber*3+1], vertices->getArray()[nextElem->vertexNumber*3+2]) - curV;
     694                  curV = Vector (this->vertices.getArray()[curElem->vertexNumber*3],
     695                                 this->vertices.getArray()[curElem->vertexNumber*3+1],
     696                                 this->vertices.getArray()[curElem->vertexNumber*3+2]);
     697
     698                  prevV = Vector (this->vertices.getArray()[prevElem->vertexNumber*3],
     699                                  this->vertices.getArray()[prevElem->vertexNumber*3+1],
     700                                  this->vertices.getArray()[prevElem->vertexNumber*3+2]) - curV;
     701
     702                  nextV = Vector (this->vertices.getArray()[nextElem->vertexNumber*3],
     703                                  this->vertices.getArray()[nextElem->vertexNumber*3+1],
     704                                  this->vertices.getArray()[nextElem->vertexNumber*3+2]) - curV;
    737705                  normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV);
    738706
     
    746714    }
    747715
    748   for (int i=0; i < vertices->getCount()/3;i++)
     716  for (int i=0; i < this->vertices.getCount()/3;i++)
    749717    {
    750718      normArray[i].normalize();
     
    754722
    755723    }
    756   delete []normArray;
     724  delete[] normArray;
    757725}
    758726
     
    766734{
    767735  // finalize the Arrays
    768   this->vertices->finalizeArray();
    769   this->vTexture->finalizeArray();
    770   if (normals->getCount() == 0) // vertices-Array must be built for this
     736  this->vertices.finalizeArray();
     737  this->vTexture.finalizeArray();
     738  if (normals.getCount() == 0) // vertices-Array must be built for this
    771739    this->buildVertexNormals();
    772   this->normals->finalizeArray();
     740  this->normals.finalizeArray();
    773741
    774742  this->currentGroup = this->firstGroup;
     
    852820}
    853821
    854 /**
    855  *  reads and includes the Faces/Materials into the openGL state Machine
    856 */
    857 bool StaticModel::importToVertexArray()
    858 {
    859   // finalize the Arrays
    860   this->vertices->finalizeArray();
    861   this->vTexture->finalizeArray();
    862   if (normals->getCount() == 0) // vertices-Array must be built for this
    863     this->buildVertexNormals();
    864   this->normals->finalizeArray();
    865 
    866   this->currentGroup = this->firstGroup;
    867   glVertexPointer(3, GL_FLOAT, 0, this->vertices->getArray());
    868   glNormalPointer(3, 0, this->normals->getArray());
    869   glTexCoordPointer(2, GL_FLOAT, 0, this->vTexture->getArray());
    870 }
    871 
    872 
    873822
    874823/**
     
    877826bool StaticModel::buildTriangleList()
    878827{
    879   if( unlikely(this->triangles != NULL))
     828  if( unlikely(this->pModelInfo.pTriangles != NULL))
    880829    return true;
    881830  /* make sure, that all the arrays are finalized */
    882   if( unlikely(!this->vertices->isFinalized()))
    883     this->vertices->finalizeArray();
    884   if( unlikely(!this->vTexture->isFinalized()))
    885     this->vTexture->finalizeArray();
    886   if( normals->getCount() == 0) // vertices-Array must be built for this
     831  if( unlikely(!this->vertices.isFinalized()))
     832    this->vertices.finalizeArray();
     833  if( unlikely(!this->vTexture.isFinalized()))
     834    this->vTexture.finalizeArray();
     835  if( normals.getCount() == 0) // vertices-Array must be built for this
    887836    this->buildVertexNormals();
    888   if( unlikely(!this->normals->isFinalized()))
    889     this->normals->finalizeArray();
     837  if( unlikely(!this->normals.isFinalized()))
     838    this->normals.finalizeArray();
    890839
    891840
     
    896845  /* count the number of triangles */
    897846  /* now iterate through all groups and build up the triangle list */
    898   this->triangleCount = 0;
    899847  this->currentGroup = this->firstGroup;
    900848  while( this->currentGroup != NULL)
     
    907855      if( tmpFace->vertexCount == 3)
    908856      {
    909         ++this->triangleCount;
     857        ++this->pModelInfo.numTriangles;
    910858      } /* if the polygon is a quad */
    911859      else if( tmpFace->vertexCount == 4)
    912860      {
    913         this->triangleCount += 2;
     861        this->pModelInfo.numTriangles += 2;
    914862      }
    915863      else if( tmpFace->vertexCount > 4)
     
    923871  }
    924872
    925   PRINTF(3)("got %i triangles, %i vertices\n", this->triangleCount, this->vertexCount);
     873  PRINTF(3)("got %i triangles, %i vertices\n", this->pModelInfo.numTriangles, this->pModelInfo.numVertices);
    926874
    927875
     
    929877
    930878  /* allocate memory for the new triangle structures */
    931   if( (this->triangles = new sTriangleExt[this->triangleCount]) == NULL)
     879  if( (this->pModelInfo.pTriangles = new sTriangleExt[this->pModelInfo.numTriangles]) == NULL)
    932880  {
    933881    PRINTF(1)("Could not allocate memory for triangle list\n");
     
    950898        for( int j = 0; j < 3; ++j)
    951899        {
    952           this->triangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3;
    953           this->triangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3;
    954           this->triangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3;
     900          this->pModelInfo.pTriangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3;
     901          this->pModelInfo.pTriangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3;
     902          this->pModelInfo.pTriangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3;
    955903          tmpElem = tmpElem->next;
    956904        }
     
    960908      {
    961909
    962         this->triangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
    963         this->triangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
    964         this->triangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
    965 
    966         this->triangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
    967         this->triangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
    968         this->triangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
     910        this->pModelInfo.pTriangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
     911        this->pModelInfo.pTriangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
     912        this->pModelInfo.pTriangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
     913
     914        this->pModelInfo.pTriangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
     915        this->pModelInfo.pTriangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
     916        this->pModelInfo.pTriangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
    969917        tmpElem = tmpElem->next;
    970918
    971         this->triangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
    972         this->triangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
    973         this->triangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
     919        this->pModelInfo.pTriangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
     920        this->pModelInfo.pTriangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
     921        this->pModelInfo.pTriangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
    974922        tmpElem = tmpElem->next;
    975923
    976         this->triangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
    977         this->triangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
    978         this->triangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
    979 
    980         this->triangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
    981         this->triangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
    982         this->triangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
     924        this->pModelInfo.pTriangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
     925        this->pModelInfo.pTriangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
     926        this->pModelInfo.pTriangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
     927
     928        this->pModelInfo.pTriangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
     929        this->pModelInfo.pTriangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
     930        this->pModelInfo.pTriangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
    983931        tmpElem = tmpElem->next;
    984932
    985         this->triangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
    986         this->triangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
    987         this->triangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
     933        this->pModelInfo.pTriangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
     934        this->pModelInfo.pTriangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
     935        this->pModelInfo.pTriangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
    988936
    989937        index += 2;
     
    1013961  if (elem->texCoordNumber != -1)
    1014962    {
    1015       if (likely(elem->texCoordNumber < this->texCoordCount))
    1016         glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2);
     963      if (likely(elem->texCoordNumber < this->pModelInfo.numTexCoor))
     964        glTexCoord2fv(this->vTexture.getArray() + elem->texCoordNumber * 2);
    1017965      else
    1018966        PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",
    1019                   elem->texCoordNumber, this->texCoordCount);
     967                  elem->texCoordNumber, this->pModelInfo.numTexCoor);
    1020968    }
    1021969  if (elem->normalNumber != -1)
    1022970    {
    1023     if (likely(elem->normalNumber < this->normalCount))
    1024       glNormal3fv(this->normals->getArray() + elem->normalNumber * 3);
     971    if (likely(elem->normalNumber < this->pModelInfo.numNormals))
     972      glNormal3fv(this->normals.getArray() + elem->normalNumber * 3);
    1025973    else
    1026974        PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",
    1027                   elem->normalNumber, this->normalCount);
     975                  elem->normalNumber, this->pModelInfo.numNormals);
    1028976    }
    1029977  if (elem->vertexNumber != -1)
    1030978    {
    1031       if (likely(elem->vertexNumber < this->vertexCount))
    1032           glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3);
     979      if (likely(elem->vertexNumber < this->pModelInfo.numVertices))
     980          glVertex3fv(this->vertices.getArray() + elem->vertexNumber * 3);
    1033981      else
    1034982        PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",
    1035                   elem->vertexNumber, this->vertexCount);
     983                  elem->vertexNumber, this->pModelInfo.numVertices);
    1036984    }
    1037985
  • trunk/src/lib/graphics/importer/static_model.h

    r6022 r6031  
    1616// FORWARD DECLARATION //
    1717template<class T> class tArray;
    18 
    19 
    20 //! an enumerator fot the different Model Types.
    21 /**
    22    MODEL_DISPLAY_LIST means, that a DisplayList will be built out of the model. This model will be STATIC, meaning it cannot be changed after initialisation.
    23    MODEL_VERTEX_ARRAY means, that a VertexArray will be built out of the model. This moel will be DYNAMIX, meaning that one can change the properties from outside of the model.
    24  * @todo implement this stuff
    25 */
    26 typedef enum MODEL_TYPE {
    27   MODEL_DISPLAY_LIST,
    28   MODEL_VERTEX_ARRAY
    29 };
    30 
    3118
    3219// definition of different modes for setting up Faces
     
    11198{
    11299 public:
    113   StaticModel(const char* modelName = NULL, MODEL_TYPE type = MODEL_DISPLAY_LIST);
     100  StaticModel(const char* modelName = NULL);
    114101  virtual ~StaticModel();
    115102
     
    120107  void rebuild();
    121108
    122   /** @returns Count of the Models (Groups) in this File */
    123   inline int getGroupCount() const { return this->groupCount; };
    124 
    125   /** @returns a Pointer to the Vertex-Array, if it was deleted it returns NULL */
    126   inline const GLfloat* getVertexArray() const { return this->vertices->getArray(); };
    127   /** @returns the VertexCount of this Model */
    128   inline unsigned int getVertexCount() const { return this->vertexCount; };
    129 
    130   /** @returns a Pointer to the Normals-Array, if it was deleted it returns NULL */
    131   inline const GLfloat* getNormalsArray() const { return this->normals->getArray(); };
    132   /** @returns the NormalsCount of this Model */
    133   inline unsigned int getNormalsCount() const { return this->normalCount; };
    134 
    135   /** @returns a Pointer to the TexCoord-Array, if it was deleted it returns NULL */
    136   inline const GLfloat* getTexCoordArray() const { return this->vTexture->getArray(); };
    137   /** @returns the TexCoord-Count of this Model */
    138   inline unsigned int getTexCoordCount() const { return this->texCoordCount; };
    139 
    140   /** @returns the Count of Faces of this Model */
    141   inline unsigned int getFaceCount() const { return this->faceCount; };
    142 
    143 
    144109  Material* addMaterial(Material* material);
    145110  Material* addMaterial(const char* materialName);
    146111
    147112  bool addGroup(const char* groupString);
     113
    148114  bool addVertex(const char* vertexString);
    149115  bool addVertex(float x, float y, float z);
     116
    150117  bool addFace(const char* faceString);
    151118  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
     119
    152120  bool addVertexNormal(const char* normalString);
    153121  bool addVertexNormal(float x, float y, float z);
     122
    154123  bool addVertexTexture(const char* vTextureString);
    155124  bool addVertexTexture(float u, float v);
     125
    156126  bool setMaterial(const char* mtlString);
    157127  bool setMaterial(Material* mtl);
     128
    158129  void finalize();
    159130
     
    163134
    164135  Material* findMaterialByName(const char* materialName);
    165 
    166136
    167137 protected:
     
    173143  bool importToDisplayList();
    174144  bool buildTriangleList();
     145
    175146  bool addGLElement(ModelFaceElement* elem);
    176147
    177   bool importToVertexArray();
    178 
    179   bool deleteArrays();
    180148  bool cleanup();
    181149
    182150 private:
    183   MODEL_TYPE                 type;            //!< A type for the Model
    184151  bool                       finalized;       //!< Sets the Object to be finalized.
    185152
    186   unsigned int               vertexCount;     //!< A modelwide Counter for vertices.
    187   unsigned int               normalCount;     //!< A modelwide Counter for the normals.
    188   unsigned int               texCoordCount;   //!< A modelwide Counter for the texCoord.
    189153  unsigned int               faceCount;       //!< A modelwide Counter for the faces
    190   unsigned int               triangleCount;   //!< Number of triangles >= faceCount
    191   tArray<GLfloat>*           vertices;        //!< The Array that handles the Vertices.
    192   tArray<GLfloat>*           normals;         //!< The Array that handles the Normals.
    193   tArray<GLfloat>*           vTexture;        //!< The Array that handles the VertexTextureCoordinates.
    194   sTriangleExt*              triangles;       //!< The Array of triangles in the model.h style
     154
     155  tArray<GLfloat>            vertices;        //!< The Array that handles the Vertices.
     156  tArray<GLfloat>            normals;         //!< The Array that handles the Normals.
     157  tArray<GLfloat>            vTexture;        //!< The Array that handles the VertexTextureCoordinates.
    195158
    196159  ModelGroup*                firstGroup;      //!< The first of all groups.
Note: See TracChangeset for help on using the changeset viewer.