Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8634 in orxonox.OLD for branches/bsp_model/src/lib


Ignore:
Timestamp:
Jun 20, 2006, 3:27:26 PM (18 years ago)
Author:
patrick
Message:

bsp: all md3 submodels are now correctly drawn, fixed the bug. now trying to do some nicer drawing and right model assembling

Location:
branches/bsp_model/src/lib/graphics/importer/md3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_data.cc

    r8602 r8634  
    4848  this->loadModel(modelFileName);
    4949//   this->loadSkin(skinFileName);
     50  this->init();
    5051}
    5152
     
    5960{
    6061  delete this->header;
     62}
     63
     64
     65/**
     66 * init data
     67 */
     68void MD3Data::init()
     69{
     70  // create the temporary data to work with (interpolation data)
     71  this->tmpBoneFrame = new MD3BoneFrame();
     72
     73  this->tmpMesh = new sVec3D*[this->header->meshNum];
     74  for( int i = 0; i < this->header->meshNum; i++)
     75    this->tmpMesh[i] = new sVec3D[this->meshes[i]->header->vertexNum];
     76
     77  this->tmpNormal = new MD3Normal*[this->header->meshNum];
     78  for( int i = 0; i < this->header->meshNum; i++)
     79    this->tmpNormal[i] = new MD3Normal[this->meshes[i]->header->vertexNum];
     80
     81  this->tmpMatrix = new float*[this->header->tagNum];
     82  for( int i = 0; i < this->header->tagNum; i++)
     83    this->tmpMatrix[i] = new float[16];
     84
    6185}
    6286
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_data.h

    r8602 r8634  
    3939  class MD3BoneFrame;
    4040  class MD3Mesh;
     41  class MD3Normal;
    4142
    4243  //! This holds the header information that is read in at the beginning of the file: id software definition
     
    8384      bool loadSkin(const std::string& fileName = "");
    8485
     86      void init();
     87
    8588      int readHeader(FILE* pFile, int fileOffset);
    8689      int readBoneFrames(FILE* pFile, int fileOffset);
     
    110113      MD3Mesh**                 meshes;            //!< array of meshes in the model. each containing the mesh for each of the animation
    111114
    112 
     115      MD3BoneFrame*             tmpBoneFrame;      //!< a temporary bone frame
     116      sVec3D**                  tmpMesh;           //!< a temporary mesh frame
     117      MD3Normal**               tmpNormal;         //!< a temporary normals frame
     118      float**                   tmpMatrix;         //!< a temporary matrix
    113119
    114120  };
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_model.cc

    r8602 r8634  
    4141    this->autoAssemblePlayerModel(filename, scaling);
    4242
    43 
    44     // create the temporary data to work with (interpolation data)
    45     this->tmpBoneFrame = new MD3BoneFrame();
    46 
    47     this->tmpMesh = new sVec3D*[this->md3Data->header->meshNum];
    48     for( int i = 0; i < this->md3Data->header->meshNum; i++)
    49       this->tmpMesh[i] = new sVec3D[this->md3Data->meshes[i]->header->vertexNum];
    50 
    51     this->tmpNormal = new MD3Normal*[this->md3Data->header->meshNum];
    52     for( int i = 0; i < this->md3Data->header->meshNum; i++)
    53       this->tmpNormal[i] = new MD3Normal[this->md3Data->meshes[i]->header->vertexNum];
    54 
    55     this->tmpMatrix = new float*[this->md3Data->header->tagNum];
    56     for( int i = 0; i < this->md3Data->header->tagNum; i++)
    57       this->tmpMatrix[i] = new float[16];
    58 
    5943    this->bDrawBones = false;
    6044    this->bDrawNormals = false;
     
    6549  MD3Model::~MD3Model()
    6650  {
    67     delete this->tmpBoneFrame;
     51//     delete this->tmpBoneFrame;
    6852//     delete [] this->tmpMesh;
    6953
     
    152136      {
    153137        //interpolate bone frame
    154         this->tmpBoneFrame = this->interpolateBoneFrame(data->boneFrames[data->animationState.currentFrame],
     138        data->tmpBoneFrame = this->interpolateBoneFrame(data, data->boneFrames[data->animationState.currentFrame],
    155139                                                        data->boneFrames[data->animationState.nextFrame],
    156140                                                        data->animationState.interpolationFraction);
     
    158142      else
    159143      {
    160         this->tmpBoneFrame = data->boneFrames[data->animationState.currentFrame];
     144        data->tmpBoneFrame = data->boneFrames[data->animationState.currentFrame];
    161145      }
    162146    }
     
    173157      {
    174158        //interpolate mesh frame between the 2 current mesh frames
    175         frame = this->interpolateMeshFrame( data->meshes[data->animationState.currentFrame]->meshFrames,
     159        frame = this->interpolateMeshFrame( data, data->meshes[data->animationState.currentFrame]->meshFrames,
    176160                                            data->meshes[data->animationState.nextFrame]->meshFrames,
    177161                                            data->animationState.interpolationFraction, mesh, i);
     
    182166        frame = &mesh->meshFrames[data->animationState.currentFrame];
    183167      }
    184       this->tmpMesh[i] = frame;
     168      data->tmpMesh[i] = frame;
    185169
    186170      // draw vertex normals if needed
     
    192176        {
    193177          //interpolate vertex normals
    194           this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame],
     178          this->interpolateVertexNormals(data, &mesh->normals[data->animationState.currentFrame],
    195179                                         &mesh->normals[data->animationState.nextFrame],
    196180                                         data->animationState.interpolationFraction, mesh, i);
     
    216200        //we need to interpolate
    217201        MD3Tag* nextFrameTag = data->boneFrames[data->animationState.nextFrame]->tags[child->parentTagIndex];
    218         this->interpolateTransformation(currFrameTag, nextFrameTag, data->animationState.interpolationFraction, i);
     202        this->interpolateTransformation(child, currFrameTag, nextFrameTag, data->animationState.interpolationFraction, i);
    219203      }
    220204      else
     
    222206        //no interpolation needed, stay with last transformation
    223207        //OpenGL matrix is in column-major order
    224         this->tmpMatrix[i][0] = currFrameTag->matrix[0][0];
    225         this->tmpMatrix[i][1] = currFrameTag->matrix[1][0];
    226         this->tmpMatrix[i][2] = currFrameTag->matrix[2][0];
    227         this->tmpMatrix[i][3] = 0.0f;
    228         this->tmpMatrix[i][4] = currFrameTag->matrix[0][1];
    229         this->tmpMatrix[i][5] = currFrameTag->matrix[1][1];
    230         this->tmpMatrix[i][6] = currFrameTag->matrix[2][1];
    231         this->tmpMatrix[i][7] = 0.0f;
    232         this->tmpMatrix[i][8] = currFrameTag->matrix[0][2];
    233         this->tmpMatrix[i][9] = currFrameTag->matrix[1][2];
    234         this->tmpMatrix[i][10]= currFrameTag->matrix[2][2];
    235         this->tmpMatrix[i][11]= 0.0f;
    236         this->tmpMatrix[i][12] = currFrameTag->position.x;
    237         this->tmpMatrix[i][13] = currFrameTag->position.y;
    238         this->tmpMatrix[i][14] = currFrameTag->position.z;
    239         this->tmpMatrix[i][15] = 1.0f;
    240       }
    241 
    242 //       PRINTF(0)("matrix: \n%f, %f, %f, %f\n%f, %f, %f, %f\n%f, %f, %f, %f\n%f, %f, %f, %f\n",
    243 //       this->tmpMatrix[i][0],
    244 //       this->tmpMatrix[i][1],
    245 //       this->tmpMatrix[i][2],
    246 //       this->tmpMatrix[i][3],
    247 //       this->tmpMatrix[i][4],
    248 //       this->tmpMatrix[i][5],
    249 //       this->tmpMatrix[i][6],
    250 //       this->tmpMatrix[i][7],
    251 //       this->tmpMatrix[i][8],
    252 //       this->tmpMatrix[i][9],
    253 //       this->tmpMatrix[i][10],
    254 //       this->tmpMatrix[i][11],
    255 //       this->tmpMatrix[i][12],
    256 //       this->tmpMatrix[i][13],
    257 //       this->tmpMatrix[i][14],
    258 //       this->tmpMatrix[i][15]
    259 //                );
     208        data->tmpMatrix[i][0] = currFrameTag->matrix[0][0];
     209        data->tmpMatrix[i][1] = currFrameTag->matrix[1][0];
     210        data->tmpMatrix[i][2] = currFrameTag->matrix[2][0];
     211        data->tmpMatrix[i][3] = 0.0f;
     212        data->tmpMatrix[i][4] = currFrameTag->matrix[0][1];
     213        data->tmpMatrix[i][5] = currFrameTag->matrix[1][1];
     214        data->tmpMatrix[i][6] = currFrameTag->matrix[2][1];
     215        data->tmpMatrix[i][7] = 0.0f;
     216        data->tmpMatrix[i][8] = currFrameTag->matrix[0][2];
     217        data->tmpMatrix[i][9] = currFrameTag->matrix[1][2];
     218        data->tmpMatrix[i][10]= currFrameTag->matrix[2][2];
     219        data->tmpMatrix[i][11]= 0.0f;
     220        data->tmpMatrix[i][12] = currFrameTag->position.x;
     221        data->tmpMatrix[i][13] = currFrameTag->position.y;
     222        data->tmpMatrix[i][14] = currFrameTag->position.z;
     223        data->tmpMatrix[i][15] = 1.0f;
     224      }
     225
    260226      // switch to child coord system
    261227
     
    294260          data->animationState.currentFrame != data->animationState.nextFrame) {
    295261        //interpolate bone frame
    296         this->drawBoneFrame(this->tmpBoneFrame);
     262        this->drawBoneFrame(data->tmpBoneFrame);
    297263      }
    298264      else {
     
    312278
    313279      // get mesh frame, do interpolation if necessary
    314       sVec3D* frame = this->tmpMesh[i];
     280      sVec3D* frame = data->tmpMesh[i];
    315281
    316282      this->drawMesh(mesh, frame);
     
    324290        {
    325291          //interpolate vertex normals
    326           this->drawVertexNormals(frame, this->tmpNormal[i]);
     292          this->drawVertexNormals(frame, data->tmpNormal[i]);
    327293        }
    328294        else {
     
    402368    }
    403369    glEnd();
    404 
    405370  }
    406371
     
    476441   * @param frac Interpolation fraction, in [0,1].
    477442   */
    478   MD3BoneFrame* MD3Model::interpolateBoneFrame(MD3BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac)
    479   {
    480     this->tmpBoneFrame->mins.x      = (1.0f - frac) * currBoneFrame->mins.x       + frac * nextBoneFrame->mins.x;
    481     this->tmpBoneFrame->maxs.x      = (1.0f - frac) * currBoneFrame->maxs.x       + frac * nextBoneFrame->maxs.x;
    482     this->tmpBoneFrame->position.x  = (1.0f - frac) * currBoneFrame->position.x   + frac * nextBoneFrame->position.x;
    483     this->tmpBoneFrame->mins.y      = (1.0f - frac) * currBoneFrame->mins.y       + frac * nextBoneFrame->mins.y;
    484     this->tmpBoneFrame->maxs.y      = (1.0f - frac) * currBoneFrame->maxs.y       + frac * nextBoneFrame->maxs.y;
    485     this->tmpBoneFrame->position.y  = (1.0f - frac) * currBoneFrame->position.y   + frac * nextBoneFrame->position.y;
    486     this->tmpBoneFrame->mins.z      = (1.0f - frac) * currBoneFrame->mins.z       + frac * nextBoneFrame->mins.z;
    487     this->tmpBoneFrame->maxs.z      = (1.0f - frac) * currBoneFrame->maxs.z       + frac * nextBoneFrame->maxs.z;
    488     this->tmpBoneFrame->position.z  = (1.0f - frac) * currBoneFrame->position.z   + frac * nextBoneFrame->position.z;
    489 
    490     return this->tmpBoneFrame;
     443  MD3BoneFrame* MD3Model::interpolateBoneFrame(MD3Data* data, MD3BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac)
     444  {
     445    data->tmpBoneFrame->mins.x      = (1.0f - frac) * currBoneFrame->mins.x       + frac * nextBoneFrame->mins.x;
     446    data->tmpBoneFrame->maxs.x      = (1.0f - frac) * currBoneFrame->maxs.x       + frac * nextBoneFrame->maxs.x;
     447    data->tmpBoneFrame->position.x  = (1.0f - frac) * currBoneFrame->position.x   + frac * nextBoneFrame->position.x;
     448    data->tmpBoneFrame->mins.y      = (1.0f - frac) * currBoneFrame->mins.y       + frac * nextBoneFrame->mins.y;
     449    data->tmpBoneFrame->maxs.y      = (1.0f - frac) * currBoneFrame->maxs.y       + frac * nextBoneFrame->maxs.y;
     450    data->tmpBoneFrame->position.y  = (1.0f - frac) * currBoneFrame->position.y   + frac * nextBoneFrame->position.y;
     451    data->tmpBoneFrame->mins.z      = (1.0f - frac) * currBoneFrame->mins.z       + frac * nextBoneFrame->mins.z;
     452    data->tmpBoneFrame->maxs.z      = (1.0f - frac) * currBoneFrame->maxs.z       + frac * nextBoneFrame->maxs.z;
     453    data->tmpBoneFrame->position.z  = (1.0f - frac) * currBoneFrame->position.z   + frac * nextBoneFrame->position.z;
     454
     455    return data->tmpBoneFrame;
    491456  }
    492457
     
    496461   * interpolate mesh frame
    497462   */
    498   sVec3D* MD3Model::interpolateMeshFrame(sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i)
     463  sVec3D* MD3Model::interpolateMeshFrame(MD3Data* data, sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i)
    499464  {
    500465    int vertexNum = mesh->header->vertexNum;
     
    503468    for( int t = 0; t < vertexNum * 3.0f; t++)
    504469    {
    505 
    506 //       PRINTF(0)("tmp mesh: %f, %f, %f\n", this->tmpMesh[i][t][0], this->tmpMesh[i][t][1], this->tmpMesh[i][t][2]);
    507 
    508       this->tmpMesh[i][t][0]  = (1.0f - frac)   * currMeshFrame[t][0]  + frac * nextMeshFrame[t][0];
    509       this->tmpMesh[i][t][1]  = (1.0f - frac)   * currMeshFrame[t][1]  + frac * nextMeshFrame[t][1];
    510       this->tmpMesh[i][t][2]  = (1.0f - frac)   * currMeshFrame[t][2]  + frac * nextMeshFrame[t][2];
    511     }
    512 
    513     return this->tmpMesh[i];
     470      data->tmpMesh[i][t][0]  = (1.0f - frac)   * currMeshFrame[t][0]  + frac * nextMeshFrame[t][0];
     471      data->tmpMesh[i][t][1]  = (1.0f - frac)   * currMeshFrame[t][1]  + frac * nextMeshFrame[t][1];
     472      data->tmpMesh[i][t][2]  = (1.0f - frac)   * currMeshFrame[t][2]  + frac * nextMeshFrame[t][2];
     473    }
     474
     475    return data->tmpMesh[i];
    514476  }
    515477
     
    518480   * interpolate vertex normal
    519481   */
    520   MD3Normal* MD3Model::interpolateVertexNormals(MD3Normal* currNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i)
     482  MD3Normal* MD3Model::interpolateVertexNormals(MD3Data* data, MD3Normal* currNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i)
    521483  {
    522484    for( int j = 0; j < mesh->header->vertexNum; j++)
    523485    {
    524       this->tmpNormal[i][j].vertexNormal[0] = (int)((1.0f - frac) * currNormals[j].vertexNormal[0] + frac * nextNormals[j].vertexNormal[0]);
    525       this->tmpNormal[i][j].vertexNormal[1] = (int)((1.0f - frac) * currNormals[j].vertexNormal[1] + frac * nextNormals[j].vertexNormal[1]);
    526     }
    527 
    528     return this->tmpNormal[i];
     486      data->tmpNormal[i][j].vertexNormal[0] = (int)((1.0f - frac) * currNormals[j].vertexNormal[0] + frac * nextNormals[j].vertexNormal[0]);
     487      data->tmpNormal[i][j].vertexNormal[1] = (int)((1.0f - frac) * currNormals[j].vertexNormal[1] + frac * nextNormals[j].vertexNormal[1]);
     488    }
     489
     490    return data->tmpNormal[i];
    529491  }
    530492
     
    533495   * interpolate transformation
    534496   */
    535   float* MD3Model::interpolateTransformation(MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i)
     497  float* MD3Model::interpolateTransformation(MD3Data* data, MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i)
    536498  {
    537499    // interpolate position
     
    550512
    551513    // quaternion code is column based, so use transposed matrix when spitting out to gl
    552     this->tmpMatrix[i][0] = interpolatedMatrix[0][0];
    553     this->tmpMatrix[i][4] = interpolatedMatrix[1][0];
    554     this->tmpMatrix[i][8] = interpolatedMatrix[2][0];
    555     this->tmpMatrix[i][12] = interpolatedPosition.x;
    556     this->tmpMatrix[i][1] = interpolatedMatrix[0][1];
    557     this->tmpMatrix[i][5] = interpolatedMatrix[1][1];
    558     this->tmpMatrix[i][9] = interpolatedMatrix[2][1];
    559     this->tmpMatrix[i][13] = interpolatedPosition.y;
    560     this->tmpMatrix[i][2] = interpolatedMatrix[0][2];
    561     this->tmpMatrix[i][6] = interpolatedMatrix[1][2];
    562     this->tmpMatrix[i][10]= interpolatedMatrix[2][2];
    563     this->tmpMatrix[i][14] = interpolatedPosition.z;
    564     this->tmpMatrix[i][3] = 0.0f;
    565     this->tmpMatrix[i][7] = 0.0f;
    566     this->tmpMatrix[i][11]= 0.0f;
    567     this->tmpMatrix[i][15] = 1.0f;
    568 
    569     return this->tmpMatrix[i];
     514    data->tmpMatrix[i][0] = interpolatedMatrix[0][0];
     515    data->tmpMatrix[i][4] = interpolatedMatrix[1][0];
     516    data->tmpMatrix[i][8] = interpolatedMatrix[2][0];
     517    data->tmpMatrix[i][12] = interpolatedPosition.x;
     518    data->tmpMatrix[i][1] = interpolatedMatrix[0][1];
     519    data->tmpMatrix[i][5] = interpolatedMatrix[1][1];
     520    data->tmpMatrix[i][9] = interpolatedMatrix[2][1];
     521    data->tmpMatrix[i][13] = interpolatedPosition.y;
     522    data->tmpMatrix[i][2] = interpolatedMatrix[0][2];
     523    data->tmpMatrix[i][6] = interpolatedMatrix[1][2];
     524    data->tmpMatrix[i][10]= interpolatedMatrix[2][2];
     525    data->tmpMatrix[i][14] = interpolatedPosition.z;
     526    data->tmpMatrix[i][3] = 0.0f;
     527    data->tmpMatrix[i][7] = 0.0f;
     528    data->tmpMatrix[i][11]= 0.0f;
     529    data->tmpMatrix[i][15] = 1.0f;
     530
     531    return data->tmpMatrix[i];
    570532
    571533  }
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_model.h

    r8597 r8634  
    5050    void drawBoneFrame(MD3BoneFrame* frame) const;
    5151
    52     MD3BoneFrame* interpolateBoneFrame(MD3BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac);
    53     sVec3D* interpolateMeshFrame(sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i);
    54     MD3Normal* interpolateVertexNormals(MD3Normal* curNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i);
    55     float* interpolateTransformation(MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i);
     52    MD3BoneFrame* interpolateBoneFrame(MD3Data* data, MD3BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac);
     53    sVec3D* interpolateMeshFrame(MD3Data* data, sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i);
     54    MD3Normal* interpolateVertexNormals(MD3Data* data, MD3Normal* curNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i);
     55    float* interpolateTransformation(MD3Data* data, MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i);
    5656
    5757  private:
     
    6363    MD3AnimationCfg*    config;            //!< the config file parsed
    6464
    65     MD3BoneFrame*       tmpBoneFrame;      //!< a temporary bone frame
    66     sVec3D**            tmpMesh;           //!< a temporary mesh frame
    67     MD3Normal**         tmpNormal;         //!< a temporary normals frame
    68     float**             tmpMatrix;         //!< a temporary matrix
    6965
    7066};
Note: See TracChangeset for help on using the changeset viewer.