Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8565 in orxonox.OLD for branches/bsp_model


Ignore:
Timestamp:
Jun 17, 2006, 2:13:26 PM (19 years ago)
Author:
patrick
Message:

bsp: switched to const drawing function… this was quite messy

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

Legend:

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

    r8564 r8565  
    4747      this->tmpMesh[i] = new sVec3D[this->md3Data->meshes[i]->header->vertexNum];
    4848
    49     this->tmpNormal = new MD3Normal[2048];                    //!< the temporary normals
     49    this->tmpNormal = new MD3Normal*[this->md3Data->meshNum];
     50    for( int i = 0; i < this->md3Data->meshNum; i++)
     51      this->tmpNormal[i] = new MD3Normal[this->md3Data->meshes[i]->header->vertexNum];
    5052
    5153    this->tmpMatrix = new float*[this->md3Data->tagNum];
     
    112114
    113115
    114       // draw vertex normals if needed
    115           if( this->bDrawNormals) {
    116         // get vertex normals, interpolate if necessary
     116
     117
     118          // draw vertex normals if needed
     119          if( this->bDrawNormals)
     120          {
     121            // get vertex normals, interpolate if necessary
    117122            if( data->animationState.interpolationFraction != 0.0 &&
    118                 data->animationState.currentFrame != data->animationState.nextFrame) {
    119           //interpolate vertex normals
    120               this->drawVertexNormals(frame, this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame],
    121                                       &mesh->normals[data->animationState.nextFrame], data->animationState.interpolationFraction, mesh));
    122                 }
    123                 else {
    124           //stick with current vertex normals
    125                   this->drawVertexNormals(frame, &mesh->normals[data->animationState.currentFrame]);
    126                 }
     123                data->animationState.currentFrame != data->animationState.nextFrame)
     124            {
     125              //interpolate vertex normals
     126              this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame],
     127                                              &mesh->normals[data->animationState.nextFrame],
     128                                              data->animationState.interpolationFraction, mesh, i);
     129             }
    127130          }
    128131    }
     132
    129133
    130134
     
    184188   * this draws the md3 model
    185189   */
    186   void MD3Model::draw()
    187   {
     190  void MD3Model::draw() const
     191  {
     192    PRINTF(0)("draw\n");
     193
    188194    //draw current bone frame
    189 //     this->draw(this->md3Data);
    190 
    191     PRINTF(0)("draw\n");
     195    this->draw(this->md3Data);
    192196  }
    193197
     
    197201   * @param data: the data to be drawn
    198202   */
    199   void MD3Model::draw(MD3Data* data)
     203  void MD3Model::draw(MD3Data* data) const
    200204  {
    201205
     
    207211          data->animationState.currentFrame != data->animationState.nextFrame) {
    208212        //interpolate bone frame
    209         this->drawBoneFrame(this->interpolateBoneFrame(data->boneFrames[data->animationState.currentFrame],
    210                             data->boneFrames[data->animationState.nextFrame],
    211                             data->animationState.interpolationFraction));
     213        this->drawBoneFrame(this->tmpBoneFrame);
    212214      }
    213215      else {
     
    230232
    231233      // get mesh frame, do interpolation if necessary
    232       sVec3D* frame;
    233       if( data->animationState.interpolationFraction != 0.0 &&
    234           data->animationState.currentFrame != data->animationState.nextFrame) {
    235         //interpolate mesh frame between the 2 current mesh frames
    236 //         frame = this->interpolateMeshFrame(mesh, data->animationState.currentFrame, data->animationState.nextFrame,
    237 //                                            data->animationState.interpolationFraction);
    238         frame = this->interpolateMeshFrame( data->meshes[data->animationState.currentFrame]->meshFrames,
    239                                             data->meshes[data->animationState.nextFrame]->meshFrames,
    240                                             data->animationState.interpolationFraction, mesh, i);
    241       }
     234      sVec3D* frame = this->tmpMesh[i];
     235
     236      this->drawMesh(mesh, frame);
    242237
    243238
     
    248243            data->animationState.currentFrame != data->animationState.nextFrame) {
    249244          //interpolate vertex normals
    250           this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame],
    251                                          &mesh->normals[data->animationState.nextFrame],
    252                                          data->animationState.interpolationFraction, mesh);
    253         }
     245          this->drawVertexNormals(frame, this->tmpNormal[i]);
     246            }
     247            else {
     248          //stick with current vertex normals
     249              this->drawVertexNormals(frame, &mesh->normals[data->animationState.currentFrame]);
     250            }
    254251      }
    255252    }
     
    257254
    258255    // draw all models linked to this model
     256    int i = 0;
    259257    std::map<int, MD3Data*>::iterator it = data->sortedMap.begin();
    260258    while( it != data->sortedMap.end())
     
    270268          data->animationState.currentFrame != data->animationState.nextFrame) {
    271269        //we need to interpolate
    272         MD3Tag* nextFrameTag = data->boneFrames[data->animationState.nextFrame]->tags[child->parentTagIndex];
    273 //         m = this->interpolateTransformation(currFrameTag, nextFrameTag, data->animationState.interpolationFraction);
     270        m = this->tmpMatrix[i];
    274271      }
    275272      else {
     
    302299
    303300      glPopMatrix();
     301      i++;
    304302    }
    305303  }
     
    309307   * draws the mesh
    310308   */
    311   void MD3Model::drawMesh(MD3Mesh* mesh, sVec3D* frame)
     309  void MD3Model::drawMesh(MD3Mesh* mesh, sVec3D* frame) const
    312310  {
    313311    glColor3f(1.0f, 1.0f, 1.0f);
    314312    glBegin( GL_TRIANGLES );
     313
     314    Vector tmpVec1, tmpVec2;
    315315
    316316    // upload all triangles in the frame to OpenGL
    317317    for( int t = 0; t < mesh->header->triangleNum; t++) {
    318318      // calc normal vector
    319       this->tmpVec1.x = frame[mesh->triangles[t].vertexOffset[1]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];
    320       this->tmpVec2.x = frame[mesh->triangles[t].vertexOffset[2]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];
    321 
    322       this->tmpVec1.y = frame[mesh->triangles[t].vertexOffset[1]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];
    323       this->tmpVec2.y = frame[mesh->triangles[t].vertexOffset[2]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];
    324 
    325       this->tmpVec1.z = frame[mesh->triangles[t].vertexOffset[1]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];
    326       this->tmpVec2.z = frame[mesh->triangles[t].vertexOffset[2]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];
    327 
    328       Vector normal = this->tmpVec1.cross(tmpVec2);
     319      tmpVec1.x = frame[mesh->triangles[t].vertexOffset[1]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];
     320      tmpVec2.x = frame[mesh->triangles[t].vertexOffset[2]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];
     321
     322      tmpVec1.y = frame[mesh->triangles[t].vertexOffset[1]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];
     323      tmpVec2.y = frame[mesh->triangles[t].vertexOffset[2]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];
     324
     325      tmpVec1.z = frame[mesh->triangles[t].vertexOffset[1]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];
     326      tmpVec2.z = frame[mesh->triangles[t].vertexOffset[2]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];
     327
     328      Vector normal = tmpVec1.cross(tmpVec2);
    329329      normal.normalize();
    330330
     
    353353   *  drawo vertex normals
    354354   */
    355   void MD3Model::drawVertexNormals(sVec3D* frame, MD3Normal* normals)
     355  void MD3Model::drawVertexNormals(sVec3D* frame, MD3Normal* normals) const
    356356  {}
    357357
     
    360360   * draw bone frame
    361361   */
    362   void MD3Model::drawBoneFrame(MD3BoneFrame* frame)
     362  void MD3Model::drawBoneFrame(MD3BoneFrame* frame) const
    363363  {
    364364    float x1 = frame->mins.x;
     
    459459   * interpolate vertex normal
    460460   */
    461   MD3Normal* MD3Model::interpolateVertexNormals(MD3Normal* currNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh)
    462   {
    463     for( int i = 0; i < mesh->header->vertexNum; i++)
    464     {
    465       this->tmpNormal[i].vertexNormal[0] = (int)((1.0f - frac) * currNormals[i].vertexNormal[0] + frac * nextNormals[i].vertexNormal[0]);
    466       this->tmpNormal[i].vertexNormal[1] = (int)((1.0f - frac) * currNormals[i].vertexNormal[1] + frac * nextNormals[i].vertexNormal[1]);
    467     }
    468 
    469     return this->tmpNormal;
     461  MD3Normal* MD3Model::interpolateVertexNormals(MD3Normal* currNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i)
     462  {
     463    for( int j = 0; j < mesh->header->vertexNum; j++)
     464    {
     465      this->tmpNormal[i][j].vertexNormal[0] = (int)((1.0f - frac) * currNormals[j].vertexNormal[0] + frac * nextNormals[j].vertexNormal[0]);
     466      this->tmpNormal[i][j].vertexNormal[1] = (int)((1.0f - frac) * currNormals[j].vertexNormal[1] + frac * nextNormals[j].vertexNormal[1]);
     467    }
     468
     469    return this->tmpNormal[i];
    470470  }
    471471
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_model.h

    r8564 r8565  
    3535
    3636    virtual void tick(float dt);
    37     virtual void draw() ;
     37    virtual void draw() const;
    3838
    3939
    4040  private:
    41     void draw(MD3Data* data);
     41    void draw(MD3Data* data) const;
    4242    void tick(float dt, MD3Data* data);
    4343
    44     void drawMesh(MD3Mesh* mesh, sVec3D* frame) ;
    45     void drawVertexNormals(sVec3D* frame, MD3Normal* normals) ;
    46     void drawBoneFrame(MD3BoneFrame* frame) ;
     44    void drawMesh(MD3Mesh* mesh, sVec3D* frame) const;
     45    void drawVertexNormals(sVec3D* frame, MD3Normal* normals) const;
     46    void drawBoneFrame(MD3BoneFrame* frame) const;
    4747
    4848    MD3BoneFrame* interpolateBoneFrame(MD3BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac);
    4949    sVec3D* interpolateMeshFrame(sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i);
    50     MD3Normal* interpolateVertexNormals(MD3Normal* curNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh);
     50    MD3Normal* interpolateVertexNormals(MD3Normal* curNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i);
    5151    float* interpolateTransformation(MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i);
    5252
     
    5959    MD3BoneFrame*       tmpBoneFrame;      //!< a temporary bone frame
    6060    sVec3D**            tmpMesh;           //!< a temporary mesh frame
    61     MD3Normal*          tmpNormal;         //!< a temporary normals frame
     61    MD3Normal**         tmpNormal;         //!< a temporary normals frame
    6262    float**             tmpMatrix;         //!< a temporary matrix
    63     Vector              tmpVec1;
    64     Vector              tmpVec2;
     63
    6564};
    6665
Note: See TracChangeset for help on using the changeset viewer.