Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3072 in orxonox.OLD for orxonox/trunk/importer/object.cc


Ignore:
Timestamp:
Dec 3, 2004, 10:25:20 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk/importer: improved FaceElement-Read-function. Now not strings, but ints are passed along

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/importer/object.cc

    r3071 r3072  
    302302bool Object::cleanupFaceElement(FaceElement* faceElem)
    303303{
    304   if (faceElem->value != NULL)
    305     if (verbose>=4)
    306       printf ("Cleaning up faceElement %s\n", faceElem->value);
    307     //delete faceElem->value;
    308 
    309304  if (faceElem->next != NULL)
    310305    {
    311306      cleanupFaceElement (faceElem->next);
    312       //      delete faceElem->next;
     307      delete faceElem->next;
    313308    }
    314309}
     
    456451  FaceElement* tmpElem = currentGroup->currentFace->firstElem = new FaceElement;
    457452  tmpElem->next = NULL;
    458   tmpElem->value = NULL;
    459453  while(strcmp (faceString, "\0"))
    460454    {
     
    462456          tmpElem = tmpElem->next = new FaceElement;
    463457      tmpElem->next = NULL;
    464       tmpElem->value = NULL;
    465458
    466459      char tmpValue [50];
     460      int tmpLen;
     461      char* vertex = NULL;
     462      char* texture = NULL;
     463      char* normal = NULL;
     464
    467465      sscanf (faceString, "%s", tmpValue);
    468       tmpElem->value = new char [strlen(tmpValue)];
    469       strcpy (tmpElem->value, tmpValue);
    470 
    471       faceString += strlen(tmpElem->value);
     466      tmpLen = strlen(tmpValue);
     467      vertex = tmpValue;
     468
     469      if ((texture = strstr (vertex, "/")) != NULL)
     470        {
     471          texture[0] = '\0';
     472          texture ++;
     473         
     474          if ((normal = strstr (texture, "/")) !=NULL)
     475            {
     476              normal[0] = '\0';
     477              normal ++;
     478            }     
     479        }
     480      if (vertex)
     481        tmpElem->vertexNumber = atoi(vertex);
     482      else
     483        tmpElem->vertexNumber = 0;
     484      if (texture)
     485        tmpElem->texCoordNumber = atoi(texture);
     486      else
     487        tmpElem->texCoordNumber = 0;
     488      if (normal)
     489        tmpElem->normalNumber = atoi(normal);
     490      else
     491        tmpElem->normalNumber = 0;
     492
     493      faceString += tmpLen;
    472494      if (strcmp (faceString, "\0"))
    473495        faceString++;
     
    709731            {
    710732              //      printf ("%s\n", tmpElem->value);
    711               addGLElement(tmpElem->value);
     733              addGLElement(tmpElem);
    712734              tmpElem = tmpElem->next;
    713735            }
     
    729751
    730752*/
    731 bool Object::addGLElement (char* elementString)
     753bool Object::addGLElement (FaceElement* elem)
    732754{
    733755  if (verbose >=3)
    734     printf ("importing grafical Element to openGL: %s\n", elementString);
    735   char vertex [100];
    736   strcpy (vertex, elementString);
    737 
    738   char* texture;
    739   if ((texture = strstr (vertex, "/")) != NULL)
    740     {
    741       texture[0] = '\0';
    742       texture ++;
    743       glTexCoord2fv(vTexture->getArray()+(atoi(texture)-1)*2);
    744 
    745       char* normal;
    746       if ((normal = strstr (texture, "/")) !=NULL)
    747         {
    748           normal[0] = '\0';
    749           normal ++;
    750           //glArrayElement(atoi(vertex)-1);
    751           glNormal3fv(normals->getArray() +(atoi(normal)-1)*3);
    752         }
    753     }
    754   glVertex3fv(vertices->getArray() +(atoi(vertex)-1)*3);
     756    printf ("importing grafical Element to openGL.\n");
     757
     758  if (elem->texCoordNumber)
     759    glTexCoord2fv(vTexture->getArray()+(elem->texCoordNumber-1)*2);
     760  if (elem->normalNumber)
     761    glNormal3fv(normals->getArray() +(elem->normalNumber-1)*3);
     762  if (elem->vertexNumber)
     763    glVertex3fv(vertices->getArray() +(elem->vertexNumber-1)*3);
    755764
    756765}
Note: See TracChangeset for help on using the changeset viewer.