Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.h @ 4168

Last change on this file since 4168 was 4168, checked in by patrick, 19 years ago

orxonox/branches/md2_loader: started cleaning up: put model and md2model together

File size: 4.8 KB
Line 
1/*!
2    \file md2Model.h
3    \brief Definition of an MD2 Model, a model format invented by ID Software.
4       
5        We are deeply thankfull for all the wunderfull things id software made for us gamers!
6
7        The md2 file format is structured in a very simple way: it contains animations which are made out of
8        frames (so called keyframes). Each frame is a complete draweable model in a specific position.
9        A frame is a collection of vertex and its compagnions (normals, texture coordinates).
10       
11        A typical model has about 200 frames, the maximum frame count is fixed by MD2_MAX_FRAMES to currently
12        512 frames. The maximal vetices count is set to 2048 verteces, not enough?
13        You just have to change the MD2_MAX_* values if it doesn't fit your purposes...
14
15        Surface Culling is fully implemented in md2 models: quake2 uses front face culling.
16*/
17
18#ifndef _MD2MODEL_H
19#define _MD2MODEL_H
20
21#include "abstract_model.h"
22#include "base_object.h"
23#include "stdincl.h"
24
25
26//! These are the needed defines for the max values when loading .MD2 files
27#define MD2_MAX_TRIANGLES               4096
28#define MD2_MAX_VERTICES                2048
29#define MD2_MAX_TEXCOORDS               2048
30#define MD2_MAX_FRAMES                  512
31#define MD2_MAX_SKINS                   32
32#define MD2_MAX_FRAMESIZE               (MD2_MAX_VERTICES * 4 + 128)
33
34//! This stores the speed of the animation between each key frame - currently conflicting with the animation framework
35#define kAnimationSpeed                 12.0f
36
37//! This holds the header information that is read in at the beginning of the file: id software definition
38struct tMd2Header
39{ 
40   int ident;                           //!< This is used to identify the file
41   int version;                         //!< The version number of the file (Must be 8)
42   
43   int skinWidth;                       //!< The skin width in pixels
44   int skinHeight;                      //!< The skin height in pixels
45   int frameSize;                       //!< The size in bytes the frames are
46   
47   int numSkins;                        //!< The number of skins associated with the model
48   int numVertices;                     //!< The number of vertices (constant for each frame)
49   int numTexCoords;                    //!< The number of texture coordinates
50   int numTriangles;                    //!< The number of faces (polygons)
51   int numGlCommands;                   //!< The number of gl commands
52   int numFrames;                       //!< The number of animation frames
53   
54   int offsetSkins;                     //!< The offset in the file for the skin data
55   int offsetTexCoords;                 //!< The offset in the file for the texture data
56   int offsetTriangles;                 //!< The offset in the file for the face data
57   int offsetFrames;                    //!< The offset in the file for the frames data
58   int offsetGlCommands;                //!< The offset in the file for the gl commands data
59   int offsetEnd;                       //!< The end of the file offset
60};
61
62
63//! This is used to store the vertices that are read in for the current frame directly from the file (compressed)
64struct tMd2AliasTriangle
65{
66   byte vertex[3];
67   byte lightNormalIndex;
68};
69
70//! This stores the normals and vertices for the frames (uncompressed)
71struct tMd2Triangle
72{
73   float vertex[3];
74   float normal[3];
75};
76
77//! This stores the indices into the vertex and texture coordinate arrays
78struct tMd2Face
79{
80   short vertexIndices[3];
81   short textureIndices[3];
82};
83
84//! This stores UV coordinates
85struct tMd2TexCoord
86{
87   short u, v;
88};
89
90//! This stores the animation scale, translation and name information for a frame, plus verts
91struct tMd2AliasFrame
92{
93   float scale[3];
94   float translate[3];
95   char name[16];
96   tMd2AliasTriangle aliasVertices[1];
97};
98
99//! This stores the frames vertices after they have been transformed
100struct tMd2Frame
101{
102   char strName[16];
103   tMd2Triangle *pVertices;
104};
105
106//! This stores a skin name
107typedef char tMd2Skin[64];
108
109//! This is a MD2 Model class
110class MD2Model : public AbstractModel {
111
112public:
113  MD2Model();
114  virtual ~MD2Model();
115 
116  bool loadModel(const char* filename);
117  bool loadSkin(const char* filename);
118 
119  void drawModel(float time);
120  void drawFrame(int frame);
121  void draw();
122 
123  void setAnim(int type);
124  void scaleModel(float s);
125
126  void tick(float dtS);
127
128  void animate(/*float time*/);
129private:
130  void processLightning();
131  void interpolate(CVector3* vertlist);
132  void renderFrame();
133  float getCurrentTime(t3DModel *pModel, int nextFrame);
134
135  t3DModel* model;
136  float localTime;
137};
138
139//! A class that handles all of the loading code
140class MD2Loader : public BaseObject {
141
142public:
143  MD2Loader();
144  virtual ~MD2Loader();
145 
146  bool importMD2(t3DModel *pModel, char *fileName, char *texture = NULL);
147
148private:
149  void readMD2Data();
150  void parseAnimations(t3DModel *pModel);
151  void convertDataStructures(t3DModel *pModel);
152  void computeNormals(t3DModel *pModel);
153  void cleanUp();
154 
155  FILE *pFile; 
156  tMd2Header header;                          //!< The header data
157  tMd2Skin *pSkins;                           //!< The skin data
158  tMd2TexCoord *pTexCoords;                   //!< The texture coordinates
159  tMd2Face *pTriangles;                       //!< Face index information
160  tMd2Frame *pFrames;                         //!< The frames of animation (vertices)
161};
162
163
164#endif /* _MD2MODEL_H */
Note: See TracBrowser for help on using the repository browser.