Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4146 in orxonox.OLD for orxonox/branches/md2_loader/src/lib


Ignore:
Timestamp:
May 10, 2005, 5:07:46 PM (19 years ago)
Author:
patrick
Message:

orxonox/branches/md2_loader: md2 model now gets loaded: all animations and frames are parsed and referenced

Location:
orxonox/branches/md2_loader/src/lib/graphics/importer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/md2_loader/src/lib/graphics/importer/abstract_model.h

    r4142 r4146  
    2323
    2424#include "stdincl.h"
     25#include "base_object.h"
     26#include <vector>
    2527
    26 #include "base_object.h"
     28using namespace std;
    2729
    2830//template<class T> class tList;
    29 template<class T> class vector;
     31;
    3032
    3133//! This is our 3D point class.  CONFLICTING with Vector.cc
     
    9496        int currentAnim;                                        // The current index into pAnimations list (NEW)
    9597        int currentFrame;                                       // The current frame of the current animation (NEW)
    96         vector<tAnimationInfo>* animationList; // The list of animations (NEW)
    97         vector<tMaterialInfo>* materialList;    // The list of material information (Textures and colors)
    98         vector<t3DObject>* objectList;                  // The object list for our model
     98        vector<tAnimationInfo> animationList; // The list of animations (NEW)
     99        vector<tMaterialInfo> materialList;     // The list of material information (Textures and colors)
     100        vector<t3DObject> objectList;                   // The object list for our model
    99101};
    100102
  • orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.cc

    r4142 r4146  
    1919#include <fstream>
    2020#include <string>
    21 
    2221#include <vector>
    2322
     
    5655void MD2Model::draw(t3DModel *pModel)
    5756{
    58   if( pModel->objectList->size() <= 0) return;
    59 
    60   t3DObject *pObject = pModel->objectList->firstElement();
     57  if( pModel->objectList.size() <= 0) return;
     58
     59  t3DObject *pObject = &pModel->objectList[0];
    6160  glBegin(GL_TRIANGLES);
    6261  for(int j = 0; j < pObject->numOfFaces; j++)
     
    112111bool MD2Loader::importMD2(t3DModel *pModel, char *fileName, char *textureName)
    113112{
    114 
    115   pModel->animationList = new vector<tAnimationInfo>();
    116   pModel->objectList = new vector<t3DObject>();
    117   pModel->materialList = new vector<tMaterialInfo>();
    118 
    119113  this->pFile = fopen(fileName, "rb");
    120114  if( unlikely(!pFile))
     
    136130  if( likely((int)textureName))
    137131    {
    138       tMaterialInfo* textureInfo = new tMaterialInfo;
    139       strcpy(textureInfo->strFile, textureName);
     132      tMaterialInfo textureInfo;
     133      strcpy(textureInfo.strFile, textureName);
    140134      /* since there is only one texture for a .Md2 file, the ID is always 0 */
    141       textureInfo->texureId = 0;
    142       textureInfo->uTile = 1;
     135      textureInfo.texureId = 0;
     136      textureInfo.uTile = 1;
    143137      /* we only have 1 material for a model */
    144138      pModel->numOfMaterials = 1;
    145       pModel->materialList->add(textureInfo);
     139      pModel->materialList.push_back(textureInfo);
    146140    }
    147141       
     
    200194void MD2Loader::parseAnimations(t3DModel *pModel)
    201195{
    202   tAnimationInfo* animationInfo = new tAnimationInfo;
     196  tAnimationInfo animationInfo;
    203197  string strLastName = "";
    204198
     
    231225          if( strLastName != "")
    232226            {
    233               strcpy(animationInfo->strName, strLastName.c_str());
    234               animationInfo->endFrame = i;
    235               pModel->animationList->add(animationInfo);
     227              strcpy(animationInfo.strName, strLastName.c_str());
     228              animationInfo.endFrame = i;
     229              pModel->animationList.push_back(animationInfo);
    236230              memset(&animationInfo, 0, sizeof(tAnimationInfo));
    237231              pModel->numOfAnimations++;
    238232            }
    239           animationInfo->startFrame = frameNum - 1 + i;
     233          animationInfo.startFrame = frameNum - 1 + i;
    240234        }
    241235      strLastName = strName;
     
    258252  for (i = 0; i < pModel->numOfObjects; i++)
    259253    {
    260       t3DObject* currentFrame = new t3DObject;
    261 
    262       currentFrame->numOfVerts = this->header.numVertices;
    263       currentFrame->numTexVertex = this->header.numTexCoords;
    264       currentFrame->numOfFaces = this->header.numTriangles;
    265 
    266       currentFrame->pVerts = new CVector3[currentFrame->numOfVerts];
    267 
    268       for (j = 0; j < currentFrame->numOfVerts; j++)
    269         {
    270           currentFrame->pVerts[j].x = this->pFrames[i].pVertices[j].vertex[0];
    271           currentFrame->pVerts[j].y = this->pFrames[i].pVertices[j].vertex[1];
    272           currentFrame->pVerts[j].z = this->pFrames[i].pVertices[j].vertex[2];
     254      t3DObject currentFrame;
     255
     256      currentFrame.numOfVerts = this->header.numVertices;
     257      currentFrame.numTexVertex = this->header.numTexCoords;
     258      currentFrame.numOfFaces = this->header.numTriangles;
     259
     260      currentFrame.pVerts = new CVector3[currentFrame.numOfVerts];
     261
     262      for (j = 0; j < currentFrame.numOfVerts; j++)
     263        {
     264          currentFrame.pVerts[j].x = this->pFrames[i].pVertices[j].vertex[0];
     265          currentFrame.pVerts[j].y = this->pFrames[i].pVertices[j].vertex[1];
     266          currentFrame.pVerts[j].z = this->pFrames[i].pVertices[j].vertex[2];
    273267        }
    274268
     
    277271      if( likely(i > 0))
    278272        {
    279           pModel->objectList->add(currentFrame);
     273          pModel->objectList.push_back(currentFrame);
    280274          continue;
    281275        }
    282276                       
    283       currentFrame->pTexVerts = new CVector2[currentFrame->numTexVertex];
    284       currentFrame->pFaces = new tFace[currentFrame->numOfFaces];
    285 
    286       for(j = 0; j < currentFrame->numTexVertex; j++)
    287         {
    288           currentFrame->pTexVerts[j].x = this->pTexCoords[j].u / float(this->header.skinWidth);
    289           currentFrame->pTexVerts[j].y = 1 - this->pTexCoords[j].v / float(this->header.skinHeight);
    290         }
    291 
    292       for(j = 0; j < currentFrame->numOfFaces; j++)
    293         {
    294           currentFrame->pFaces[j].vertIndex[0] = this->pTriangles[j].vertexIndices[0];
    295           currentFrame->pFaces[j].vertIndex[1] = this->pTriangles[j].vertexIndices[1];
    296           currentFrame->pFaces[j].vertIndex[2] = this->pTriangles[j].vertexIndices[2];
    297 
    298           currentFrame->pFaces[j].coordIndex[0] = this->pTriangles[j].textureIndices[0];
    299           currentFrame->pFaces[j].coordIndex[1] = this->pTriangles[j].textureIndices[1];
    300           currentFrame->pFaces[j].coordIndex[2] = this->pTriangles[j].textureIndices[2];
    301         }
    302       pModel->objectList->add(currentFrame);
     277      currentFrame.pTexVerts = new CVector2[currentFrame.numTexVertex];
     278      currentFrame.pFaces = new tFace[currentFrame.numOfFaces];
     279
     280      for(j = 0; j < currentFrame.numTexVertex; j++)
     281        {
     282          currentFrame.pTexVerts[j].x = this->pTexCoords[j].u / float(this->header.skinWidth);
     283          currentFrame.pTexVerts[j].y = 1 - this->pTexCoords[j].v / float(this->header.skinHeight);
     284        }
     285
     286      for(j = 0; j < currentFrame.numOfFaces; j++)
     287        {
     288          currentFrame.pFaces[j].vertIndex[0] = this->pTriangles[j].vertexIndices[0];
     289          currentFrame.pFaces[j].vertIndex[1] = this->pTriangles[j].vertexIndices[1];
     290          currentFrame.pFaces[j].vertIndex[2] = this->pTriangles[j].vertexIndices[2];
     291
     292          currentFrame.pFaces[j].coordIndex[0] = this->pTriangles[j].textureIndices[0];
     293          currentFrame.pFaces[j].coordIndex[1] = this->pTriangles[j].textureIndices[1];
     294          currentFrame.pFaces[j].coordIndex[2] = this->pTriangles[j].textureIndices[2];
     295        }
     296      pModel->objectList.push_back(currentFrame);
    303297    }
    304298}
Note: See TracChangeset for help on using the changeset viewer.