Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3151 in orxonox.OLD for orxonox/branches/dave/src/object.cc


Ignore:
Timestamp:
Dec 11, 2004, 5:26:18 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/dave: src of trunk copied into branches/dave/src

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/dave/src/object.cc

    r2860 r3151  
    119119
    120120/**
    121    \brief finalizes an Object.
     121  \brief finalizes an Object.
    122122   This funcion is needed, to close the glList and all the other lists.
    123123*/
     
    226226  if (verbose >= 2)
    227227    printf("Adding new Group\n");
     228  group->name = "";
    228229  group->faceMode = -1;
    229   group->name = "";
     230  group->faceCount =0; 
    230231  if ((group->listNumber = glGenLists(1)) == 0 )
    231232    {
     
    246247      group->firstVertexTexture = currentGroup->firstVertexTexture + currentGroup->vTexture->getCount()/2;
    247248    }
    248 
     249  if (verbose >=2)
     250    printf ("Creating new Arrays, with starting points v:%i, vt:%i, vn:%i .\n", group->firstVertex, group->firstVertexTexture, group->firstNormal);
    249251  group->vertices = new Array();
    250252  group->normals = new Array();
     
    256258/**
    257259   \brief finalizes a Group.
     260   \param group the group to finalize.
    258261*/
    259262bool Object::finalizeGroup(Group* group)
    260263{
     264  if (verbose >=2)
     265    printf ("Finalize group %s.\n", group->name);
    261266  glEnd();
    262267  glEndList();
     268}
     269/**
     270   \brief deletes the Arrays of the Group to save space.
     271   \param group the group to delete the arrays from.
     272*/
     273bool Object::cleanupGroup(Group* group)
     274{
     275  if (verbose >=2)
     276    printf ("cleaning up group %s.\n", group->name);
    263277 
    264278  delete group->vertices;
     
    266280  delete group->vTexture;
    267281}
     282
    268283/**
    269284   \brief Reads in the .obj File and sets all the Values.
     
    282297    }
    283298  objFileName = fileName;
    284   char Buffer[500];
     299  char Buffer[10000];
    285300  while(!OBJ_FILE->eof())
    286301    {
    287       OBJ_FILE->getline(Buffer, 500);
     302      OBJ_FILE->getline(Buffer, 10000);
    288303      if (verbose >=4)
    289304        printf ("Read input line: %s\n",Buffer);
     
    330345    }
    331346  OBJ_FILE->close();
     347  return true;
    332348
    333349}
     
    363379    {
    364380      currentGroup->vertices->finalizeArray();
    365       glVertexPointer(3, GL_FLOAT, 0, currentGroup->vertices->getArray());
     381      //      glVertexPointer(3, GL_FLOAT, 0, currentGroup->vertices->getArray());
    366382      currentGroup->normals->finalizeArray();
    367       glNormalPointer(GL_FLOAT, 0, currentGroup->normals->getArray());
     383      //      glNormalPointer(GL_FLOAT, 0, currentGroup->normals->getArray());
    368384      currentGroup->vTexture->finalizeArray();
    369385    }
    370386
    371387  readingVertices = false;
    372   char subbuffer1[20];
    373   char subbuffer2[20];
    374   char subbuffer3[20];
    375   char subbuffer4[20] ="";
    376   sscanf (faceString, "%s %s %s %s", subbuffer1, subbuffer2, subbuffer3, subbuffer4);
    377   if (!strcmp(subbuffer4, ""))
     388  currentGroup->faceCount++;
     389
     390  int elemCount = 0;
     391 
     392  FaceElement* firstElem = new FaceElement;
     393  FaceElement* tmpElem = firstElem;
     394
     395 
     396  while(strcmp (faceString, "\0"))
     397    {
     398      if (elemCount>0)
     399          tmpElem = tmpElem->next = new FaceElement;
     400      tmpElem->next = NULL;
     401
     402
     403      sscanf (faceString, "%s", tmpElem->value);
     404      faceString += strlen(tmpElem->value);
     405      if (strcmp (faceString, "\0"))
     406        faceString++;
     407      elemCount++;
     408
     409
     410    }
     411 
     412 
     413  if (elemCount == 3)
    378414    {
    379415      if (currentGroup->faceMode != 3)
     
    386422      currentGroup->faceMode = 3;
    387423      if (verbose >=3)
    388         printf ("found triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3);
    389       addGLElement(subbuffer1);
    390       addGLElement(subbuffer2);
    391       addGLElement(subbuffer3);
    392       return true;
    393     }
    394   else
     424        printf ("found triag.\n");
     425    }
     426 
     427  else if (elemCount == 4)
    395428    {
    396429      if (currentGroup->faceMode != 4)
     
    402435      currentGroup->faceMode = 4;
    403436      if (verbose >=3 )
    404         printf ("found quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4);
    405       addGLElement(subbuffer1);
    406       addGLElement(subbuffer2);
    407       addGLElement(subbuffer3);
    408       addGLElement(subbuffer4);
    409       return true;
    410     }
     437        printf ("found quad.\n");
     438    }
     439 
     440  else if (elemCount > 4)
     441    {
     442      if (currentGroup->faceMode != -1)
     443        glEnd();
     444      glBegin(GL_POLYGON);
     445      if (verbose >=3)
     446        printf ("Polygon with %i faces found.", elemCount);
     447      currentGroup->faceMode = elemCount;
     448    }
     449
     450  tmpElem = firstElem;
     451  while (tmpElem != NULL)
     452    {
     453      //      printf ("%s\n", tmpElem->value);
     454      addGLElement(tmpElem->value);
     455      tmpElem = tmpElem->next;
     456    }
     457
    411458}
    412459
     
    423470{
    424471  if (verbose >=3)
    425     printf ("importing grafical Element.... including to openGL\n");
     472    printf ("importing grafical Element to openGL\n");
    426473  char* vertex = elementString;
    427474
    428475  char* texture;
    429   texture = strstr (vertex, "/");
    430   texture[0] = '\0';
    431   texture ++;
    432   glTexCoord2fv(currentGroup->vTexture->getArray()+(atoi(texture)-1 - currentGroup->firstVertexTexture)*2);
    433 
    434   char* normal;
    435   if ((normal = strstr (texture, "/")) !=NULL)
    436     {
    437       normal[0] = '\0';
    438       normal ++;
    439       //glArrayElement(atoi(vertex)-1);
    440       glNormal3fv(currentGroup->normals->getArray() +(atoi(normal)-1 - currentGroup->firstNormal)*3);
    441     }
     476  if ((texture = strstr (vertex, "/")) != NULL)
     477    {
     478      texture[0] = '\0';
     479      texture ++;
     480      if (verbose>=3)
     481        printf ("includeing texture #%i, and mapping it to group texture #%i, textureArray has %i entries.\n", atoi(texture), (atoi(texture)-1 - currentGroup->firstVertexTexture)*3, currentGroup->vTexture->getCount());
     482      glTexCoord2fv(currentGroup->vTexture->getArray()+(atoi(texture)-1 - currentGroup->firstVertexTexture)*2);
     483
     484      char* normal;
     485      if ((normal = strstr (texture, "/")) !=NULL)
     486        {
     487          normal[0] = '\0';
     488          normal ++;
     489          //glArrayElement(atoi(vertex)-1);
     490          glNormal3fv(currentGroup->normals->getArray() +(atoi(normal)-1 - currentGroup->firstNormal)*3);
     491        }
     492    }
     493  if (verbose>=3)
     494    printf ("includeing vertex #%i, and mapping it to group vertex #%i, vertexArray has %i entries.\n", atoi(vertex), (atoi(vertex)-1 - currentGroup->firstVertex)*3, currentGroup->vertices->getCount());
    442495  glVertex3fv(currentGroup->vertices->getArray() +(atoi(vertex)-1 - currentGroup->firstVertex)*3);
    443496
     
    488541bool Object::readGroup (char* groupString)
    489542{
    490   //  printf ("test\n");
    491   if (!strcmp(groupString, "default"))
    492     {
    493       if (groupCount != 0)
    494         {
    495           Group* newGroup = new Group;
    496           finalizeGroup(currentGroup);
    497           currentGroup->nextGroup = newGroup;
    498           initGroup(newGroup);
    499           currentGroup = newGroup; // must be after init see initGroup for more info
    500         }
    501       ++groupCount;
    502     }
    503   else
    504     {
    505      
    506       currentGroup->name = new char [strlen(groupString)];     
     543  // setting the group name if not default.
     544  if (strcmp(currentGroup->name, "default"))
     545    {
     546      currentGroup->name = (char*) malloc ( strlen(groupString) * sizeof (char));
    507547      strcpy(currentGroup->name, groupString);
    508548    }
     549  if (groupCount != 0 && currentGroup->faceCount>0)
     550    {
     551      Group* newGroup = new Group;
     552      finalizeGroup(currentGroup);
     553      currentGroup->nextGroup = newGroup;
     554      initGroup(newGroup);
     555      cleanupGroup(currentGroup); // deletes the arrays of the group; must be after initGroup.
     556      currentGroup = newGroup; // must be after init see initGroup for more info
     557    }
     558
     559  ++groupCount;
     560
    509561}
    510562
Note: See TracChangeset for help on using the changeset viewer.