Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8550 in orxonox.OLD


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

bsp: working on the drawing structure, interpolation is quite a bit work

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

Legend:

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

    r8549 r8550  
    4040  class MD3Mesh;
    4141
    42 //! This holds the header information that is read in at the beginning of the file: id software definition
    43 struct MD3Header
    44 {
    45    int ident;                           //!< This is used to identify the file
    46    int version;                         //!< The version number of the file (Must be 8)
     42  //! This holds the header information that is read in at the beginning of the file: id software definition
     43  typedef struct MD3Header
     44  {
     45    int ident;                           //!< This is used to identify the file
     46    int version;                         //!< The version number of the file (Must be 8)
    4747
    48    char filename[68];                   //!< The filename of the model
     48    char filename[68];                   //!< The filename of the model
    4949
    50    int boneFrameNum;                    //!< number of frames
    51    int tagNum;                          //!< number of tags
    52    int meshNum;                         //!< number of mesh
    53    int maxTexNum;                       //!< number of texture
     50    int boneFrameNum;                    //!< number of frames
     51    int tagNum;                          //!< number of tags
     52    int meshNum;                         //!< number of mesh
     53    int maxTexNum;                       //!< number of texture
    5454
    55    int boneFrameStart;                  //!< start of bone frames
    56    int tagStart;                        //!< start of the tag
    57    int meshStart;                       //!< mesh start
     55    int boneFrameStart;                  //!< start of bone frames
     56    int tagStart;                        //!< start of the tag
     57    int meshStart;                       //!< mesh start
    5858
    59    int fileSize;                        //!< file size
    60 };
     59    int fileSize;                        //!< file size
     60  };
     61
     62  //!< holding the informations about the current animation state
     63  typedef struct MD3AnimationState
     64  {
     65    int     currentFrame;          //!< currently rendered animation key frame of this model. Every part has its own current frame!
     66    int     nextFrame;             //!< next animation key frame of the model.
     67    float   interpolationFraction; //!< interpolation position between currentFrame and nextFrame [0,1]
     68  };
     69
     70
     71  //! class to store the md2 data in
     72  class MD3Data : public BaseObject
     73  {
     74    public:
     75      MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f);
     76      virtual ~MD3Data();
     77
     78      void addLinkedModel(int tagIndex, MD3Data* child);
     79
     80
     81    private:
     82      bool loadModel(const std::string& fileName);
     83      bool loadSkin(const std::string& fileName = "");
     84
     85      int readHeader(FILE* pFile, int fileOffset);
     86      int readBoneFrames(FILE* pFile, int fileOffset);
     87      int readTags(FILE* pFile, int fileOffset);
     88      int readMeshes(FILE* pFile, int fileOffset);
     89
     90
     91      int readMeshTriangles(FILE* pFile, int fileOffset, int mesh);
     92      int readMeshTextures(FILE* pFile, int fileOffset, int mesh);
     93      int readMeshTexVecs(FILE* pFile, int fileOffset, int mesh);
     94      int readMeshVertices(FILE* pFile, int fileOffset, int mesh);
     95
     96
     97    public:
     98
     99      MD3Header*                header;            //!< the header file
     100
     101      std::map<int, MD3Data*>   sortedMap;         //!< map
     102      int                       parentTagIndex;    //!< the tag index of the parent model
     103      MD3Data*                  parent;            //!< the parent model
     104
     105      std::string               filename;          //!< the name of the file as recorded in the .md3 file
     106      std::string               loadFilename;      //!< filename of the actual file from which data was loaded
     107
     108      int                       boneFrameNum;      //!< number of anumation key fames in the models
     109      int                       tagNum;            //!< number of tags
     110      int                       meshNum;           //!< number of meshes
     111
     112      int                       maxTextureNum;     //!< maximum number of unique used in an md3 file
     113      int                       boneFrameStart;    //!< starting position of bone frame data structures
     114      int                       tagStart;          //!< starting position of tag-structures
     115
     116      int                       meshStart;         //!< starting position of mesh structures
     117
     118      int                       fileSize;          //!< file size
     119
     120      MD3AnimationState         animationState;    //!< the animation state of this model
     121
     122      MD3BoneFrame**            boneFrames;        //!< array of bone frames, contains the metadata (bounding box, tags,...) for each frame
     123      MD3Mesh**                 meshes;            //!< array of meshes in the model. each containing the mesh for each of the animation
    61124
    62125
    63126
    64 //! class to store the md2 data in
    65 class MD3Data : public BaseObject
    66 {
    67  public:
    68    MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f);
    69   virtual ~MD3Data();
    70 
    71   void addLinkedModel(int tagIndex, MD3Data* child);
    72 
    73 
    74  private:
    75    bool loadModel(const std::string& fileName);
    76    bool loadSkin(const std::string& fileName = "");
    77 
    78    int readHeader(FILE* pFile, int fileOffset);
    79    int readBoneFrames(FILE* pFile, int fileOffset);
    80    int readTags(FILE* pFile, int fileOffset);
    81    int readMeshes(FILE* pFile, int fileOffset);
    82 
    83 
    84    int readMeshTriangles(FILE* pFile, int fileOffset, int mesh);
    85    int readMeshTextures(FILE* pFile, int fileOffset, int mesh);
    86    int readMeshTexVecs(FILE* pFile, int fileOffset, int mesh);
    87    int readMeshVertices(FILE* pFile, int fileOffset, int mesh);
    88 
    89 
    90  public:
    91 
    92   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
    97 
    98   std::string         filename;          //!< the name of the file as recorded in the .md3 file
    99   std::string         loadFilename;      //!< filename of the actual file from which data was loaded
    100 
    101   int                 boneFrameNum;      //!< number of anumation key fames in the models
    102   int                 tagNum;            //!< number of tags
    103   int                 meshNum;           //!< number of meshes
    104 
    105   int                 maxTextureNum;     //!< maximum number of unique used in an md3 file
    106   int                 boneFrameStart;    //!< starting position of bone frame data structures
    107   int                 tagStart;          //!< starting position of tag-structures
    108 
    109   int                 meshStart;         //!< starting position of mesh structures
    110 
    111   int                 fileSize;          //!< file size
    112 
    113 
    114   MD3BoneFrame**      boneFrames;        //!< array of bone frames, contains the metadata (bounding box, tags,...) for each frame
    115   MD3Mesh**           meshes;            //!< array of meshes in the model. each containing the mesh for each of the animation
    116 
    117 };
     127  };
    118128
    119129
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_model.cc

    r8549 r8550  
    4747  {
    4848    //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     }
     49    this->draw(this->md3Data);
     50  }
    6051
    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];
    6452
    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   }
     53  /**
     54   * draw the md3model
     55   * @param data: the data to be drawn
     56   */
     57  void MD3Model::draw(MD3Data* data)
     58  {}
    12659
    12760
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_model.h

    r8549 r8550  
    3232    virtual void draw();
    3333
     34
     35  private:
     36    void draw(MD3Data* data);
     37
     38
    3439  private:
    3540    MD3Data*            md3Data;           //!< reference to the md3 model data
Note: See TracChangeset for help on using the changeset viewer.