Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8549 in orxonox.OLD for branches/bsp_model/src/lib/graphics


Ignore:
Timestamp:
Jun 17, 2006, 1:33:05 AM (18 years ago)
Author:
patrick
Message:

bsp: model now can be interconnected with other models on specified tags

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

    r8490 r8549  
    3838{
    3939
    40 
     40  this->parentTagIndex = -1;
     41  this->parent = NULL;
    4142
    4243  this->loadModel(modelFileName);
     
    5556}
    5657
     58
     59/**
     60 * link a model at the specified tag position to this model. if the position is allready
     61 * occupied, the old submodel will be replaced
     62 *
     63 *  @param tagIndex: tag to link the submodel to
     64 *  @param child: the submodel that should be linked to this model
     65 */
     66void MD3Data::addLinkedModel(int tagIndex, MD3Data* child)
     67{
     68  this->sortedMap[tagIndex] = child;
     69  child->parentTagIndex = tagIndex;
     70}
    5771
    5872
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_data.h

    r8547 r8549  
    6969  virtual ~MD3Data();
    7070
     71  void addLinkedModel(int tagIndex, MD3Data* child);
     72
    7173
    7274 private:
     
    8587   int readMeshVertices(FILE* pFile, int fileOffset, int mesh);
    8688
     89
    8790 public:
    8891
    8992  MD3Header*          header;            //!< the header file
     93
     94  std::map<int, MD3Data*> sortedMap;         //!< map
     95  int                 parentTagIndex;    //!< the tag index of the parent model
     96  MD3Data*            parent;            //!< the parent model
    9097
    9198  std::string         filename;          //!< the name of the file as recorded in the .md3 file
     
    108115  MD3Mesh**           meshes;            //!< array of meshes in the model. each containing the mesh for each of the animation
    109116
    110   int                 parentTagIndex;    //!< tag index
    111 
    112   //MD3Model*           parent;            //!< reference to the MD3Model
    113 
    114 
    115117};
    116118
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_model.cc

    r8533 r8549  
    4040
    4141
     42
     43  /**
     44   * this draws the md3 model
     45   */
     46  void MD3Model::draw()
     47  {
     48    //draw current bone frame
     49#if 0
     50    if( this->bDrawBones)
     51    {
     52      //get bone frame, interpolate if necessary
     53      if( model.interpolationFraction!=0.0 && model.currentFrame!=model.nextFrame)
     54        //interpolate bone frame
     55        drawBoneFrame(interpolateBoneFrame(model.boneFrames[model.currentFrame], model.boneFrames[model.nextFrame], model.interpolationFraction));
     56      else
     57        //stick with current bone frame
     58        drawBoneFrame(model.boneFrames[model.currentFrame]);
     59    }
     60
     61    //draw all meshes of current frame of this model
     62    for (int i=0; i<model.meshNum; i++) {
     63      MD3GLMesh mesh = (MD3GLMesh)model.meshes[i];
     64
     65      gl.glBlendFunc(mesh.GLSrcBlendFunc, mesh.GLDstBlendFunc);
     66      gl.glDepthMask(mesh.GLDepthMask);
     67      if (mesh.textureNum > 0 && mesh.textures[0]!=null)
     68        gl.glBindTexture(GLEnum.GL_TEXTURE_2D, ((MD3GLTexture)mesh.textures[0]).bind);
     69      else
     70        gl.glBindTexture(GLEnum.GL_TEXTURE_2D, 0);
     71
     72      //get mesh frame, do interpolation if necessary
     73      Vec3[] frame;
     74      if (model.interpolationFraction!=0.0 && model.currentFrame!=model.nextFrame)
     75        //interpolate mesh frame between the 2 current mesh frames
     76        frame=interpolateMeshFrame(mesh.meshFrames[model.currentFrame], mesh.meshFrames[model.nextFrame], model.interpolationFraction);
     77      else
     78        //no interpolation needed, just draw current frame
     79        frame=mesh.meshFrames[model.currentFrame];
     80
     81      drawMesh(mesh, frame);
     82
     83      //draw vertex normals
     84      if (canvas.showVertexNormals) {
     85                                //get vertex normals, interpolate if necessary
     86        if (model.interpolationFraction!=0.0 && model.currentFrame!=model.nextFrame)
     87                //interpolate vertex normals
     88          drawVertexNormals(frame, interpolateVertexNormals(mesh.meshVertexNormals[model.currentFrame], mesh.meshVertexNormals[model.nextFrame], model.interpolationFraction));
     89        else
     90                //stick with current vertex normals
     91          drawVertexNormals(frame, mesh.meshVertexNormals[model.currentFrame]);
     92      }
     93    }
     94
     95    //draw all models linked to this model
     96
     97    Iterator it=model.linkedModels();
     98    while (it.hasNext()) {
     99      MD3Model child=(MD3Model)it.next();
     100
     101      //build transformation array m from matrix, interpolate if necessary
     102      float[] m=new float[16];
     103      MD3Tag currFrameTag=model.boneFrames[model.currentFrame].tags[child.getParentTagIndex()];
     104      if (model.interpolationFraction!=0.0f && model.currentFrame!=model.nextFrame) {
     105        //we need to interpolate
     106        MD3Tag nextFrameTag=model.boneFrames[model.nextFrame].tags[child.getParentTagIndex()];
     107        m=interpolateTransformation(currFrameTag, nextFrameTag, model.interpolationFraction);
     108      }
     109      else {
     110        //no interpolation needed, stay with last transformation
     111              //OpenGL matrix is in column-major order
     112        m[0] = currFrameTag.matrix[0][0]; m[4] = currFrameTag.matrix[0][1]; m[8] = currFrameTag.matrix[0][2]; m[12] = currFrameTag.position.x;
     113        m[1] = currFrameTag.matrix[1][0]; m[5] = currFrameTag.matrix[1][1]; m[9] = currFrameTag.matrix[1][2]; m[13] = currFrameTag.position.y;
     114        m[2] = currFrameTag.matrix[2][0]; m[6] = currFrameTag.matrix[2][1]; m[10]= currFrameTag.matrix[2][2]; m[14] = currFrameTag.position.z;
     115        m[3] = 0.0f;                                              m[7] = 0.0f;                                              m[11]= 0.0f;                            m[15] = 1.0f;
     116      }
     117
     118      //switch to child coord system and draw child
     119      gl.glPushMatrix();
     120      gl.glMultMatrixf(m);
     121      child.accept(this);
     122      gl.glPopMatrix();
     123    }
     124#endif
     125  }
     126
     127
     128
     129
    42130}
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_model.h

    r8490 r8549  
    2626    ~MD3Model();
    2727
     28    virtual void setAnimation(int animNum, int playbackMode = 0) {}
     29
    2830    virtual void tick(float dt) {}
    29     virtual void setAnimation(int animNum, int playbackMode = 0) {}
     31
     32    virtual void draw();
    3033
    3134  private:
    3235    MD3Data*            md3Data;           //!< reference to the md3 model data
     36
     37    bool                bDrawBones;        //!< draws the bone frames too
    3338};
    3439
Note: See TracChangeset for help on using the changeset viewer.