Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5085 in orxonox.OLD for trunk/src/lib/graphics/importer


Ignore:
Timestamp:
Aug 20, 2005, 3:37:12 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: bugfixing the md2 animation class. there seems to be a problem with the animation itself which prevents the model from being drawn correctly

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

Legend:

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

    r5075 r5085  
    169169  glPushMatrix();
    170170
    171   this->renderFrame();
     171    this->renderFrameGLList();
     172//  this->renderFrameTriangles();
    172173
    173174  glPopMatrix();
     
    178179  \brief this is an internal function to render this special frame selected by animate()
    179180*/
    180 void MD2Model::renderFrame()
     181void MD2Model::renderFrameGLList()
    181182{
    182183  static sVec3D verticesList[MD2_MAX_VERTICES]; /* performance: created only once in a lifetime */
     
    209210      for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */
    210211        {
     212 verticesList[pCommands[2]][2]);
    211213          glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] );
    212214          glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]);
     
    216218
    217219    }
     220  glDisable(GL_CULL_FACE);
     221  glPopAttrib();
     222}
     223
     224
     225/**
     226 *  renders the frame using triangles
     227 */
     228void MD2Model::renderFrameTriangles()
     229{
     230  static sVec3D verticesList[MD2_MAX_VERTICES]; /* performance: created only once in a lifetime */
     231  int* pCommands = this->data->pGLCommands;
     232
     233  /* some face culling stuff */
     234  glPushAttrib(GL_POLYGON_BIT);
     235  glFrontFace(GL_CW);
     236  glEnable(GL_CULL_FACE);
     237  glCullFace(GL_BACK);
     238
     239  this->processLighting();
     240  this->interpolate(verticesList);
     241  this->data->material->select();
     242
     243  /* draw the triangles */
     244  glBegin(GL_TRIANGLES);
     245
     246  for( int i = 0, k = 0; i < this->data->numTriangles; ++i, k += 3)
     247  {
     248    printf("%i: (%f, %f)\n", i, (float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[2]].s, (float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[2]].t);
     249
     250    glTexCoord2f((float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[0]].s,
     251                 (float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[0]].t);
     252    //glNormal3f(Md2Model.normal[i].x, Md2Model.normal[i].y, Md2Model.normal[i].z);
     253    glVertex3fv(verticesList[this->data->pTriangles[i].indexToVertices[0]]);
     254
     255    glTexCoord2f((float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[1]].s,
     256                  (float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[1]].t);
     257
     258//    glNormal3f(Md2Model.normal[i].x, Md2Model.normal[i].y, Md2Model.normal[i].z);
     259    glVertex3fv(verticesList[this->data->pTriangles[i].indexToVertices[1]]);
     260
     261    glTexCoord2f((float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[2]].s,
     262                  (float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[2]].t);
     263//    glNormal3f(Md2Model.normal[i].x, Md2Model.normal[i].y, Md2Model.normal[i].z);
     264    glVertex3fv(verticesList[this->data->pTriangles[i].indexToVertices[2]]);
     265  }
     266
     267  glEnd();
     268
     269
    218270  glDisable(GL_CULL_FACE);
    219271  glPopAttrib();
     
    288340  this->pGLCommands = NULL;
    289341  this->pLightNormals = NULL;
     342  this->pTexCoor = NULL;
    290343
    291344  this->numFrames = 0;
    292345  this->numVertices = 0;
    293346  this->numGLCommands = 0;
     347  this->numTexCoor = 0;
    294348
    295349  this->scaleFactor = 0.2f;
     
    313367  delete [] this->pGLCommands;
    314368  delete [] this->pLightNormals;
     369  delete [] this->pTexCoor;
    315370
    316371  delete this->material;
     
    354409  this->numTriangles = this->header->numTriangles;
    355410  this->numGLCommands = this->header->numGlCommands;
     411  this->numTexCoor = this->header->numTexCoords;
    356412  /* allocate memory for the data storage */
    357413  this->pVertices = new sVec3D[this->numVertices * this->numFrames];
     
    359415  this->pLightNormals = new int[this->numVertices * this->numFrames];
    360416  this->pTriangles = new sTriangle[this->numTriangles];
     417  this->pTexCoor = new sTexCoor[this->numTexCoor];
    361418  buffer = new char[this->numFrames * this->header->frameSize];
    362 
    363   /*
    364   TriangleList = new stTriangleIndice[md2Header.numTriangles];
    365 
    366   // Next extract the data by moving to the spot in the data where the triangle data start.
    367   stTriangleIndice *pTriList;
    368 
    369   // Get the data.
    370   pTriList = (stTriangleIndice*)&buffer[md2Header.offsetTriangles];
    371 
    372   // Now we pretty much store the data in our TriangleList object.
    373   for(i = 0; i < md2Header.numTriangles; i++)
    374     {
    375       TriangleList[i].triIndex[0] = pTriList[i].triIndex[0];
    376       TriangleList[i].triIndex[1] = pTriList[i].triIndex[1];
    377       TriangleList[i].triIndex[2] = pTriList[i].triIndex[2];
    378       TriangleList[i].texCoordIndex[0] = pTriList[i].texCoordIndex[0];
    379       TriangleList[i].texCoordIndex[1] = pTriList[i].texCoordIndex[1];
    380       TriangleList[i].texCoordIndex[2] = pTriList[i].texCoordIndex[2];
    381     }
    382   */
    383 
    384 
    385419
    386420
     
    394428  fseek(pFile, this->header->offsetTriangles, SEEK_SET);
    395429  fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile);
     430  /*  read in texture coordinates */
     431  fseek(pFile, this->header->offsetTexCoords, SEEK_SET);
     432  fread(this->pTexCoor, sizeof(sTexCoor), this->numTexCoor, pFile);
     433  for( int i = 0; i < this->numTexCoor; ++i)
     434  {
     435    printf("%i: (%i, %i)\n", i, this->pTexCoor[i].s, this->pTexCoor[i].t);
     436  }
    396437
    397438  for(int i = 0; i < this->numFrames; ++i)
  • trunk/src/lib/graphics/importer/md2Model.h

    r5039 r5085  
    6666
    6767
     68
    6869//! animation names enumeration
    6970typedef enum animType
     
    116117  int                numVertices;           //!< number of vertices
    117118  int                numTriangles;          //!< number of triangles
     119  int                numTexCoor;            //!< number of texture coordinates
    118120  int                numGLCommands;         //!< number of gl commands in the glList (tells how to draw)
    119121  char*              fileName;              //!< file name of the model File
     
    123125  sVec3D*            pVertices;             //!< pointer to the vertices data block
    124126  sTriangle*         pTriangles;            //!< pointer to the triangles data
     127  sTexCoor*          pTexCoor;              //!< pointer to the texture coordinate data
    125128  int*               pGLCommands;           //!< pointer to the gllist data block
    126129  int*               pLightNormals;         //!< pointer to the light normals
     
    129132  float              scaleFactor;           //!< the scale factor of the model, (global)
    130133};
     134
     135
    131136
    132137
     
    155160  void processLighting();
    156161  void interpolate(sVec3D* verticesList);
    157   void renderFrame();
     162  void renderFrameGLList();
     163  void renderFrameTriangles();
    158164
    159165 public:
Note: See TracChangeset for help on using the changeset viewer.