Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/graphics/importer/md2Model.h @ 4276

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

orxonox/trunk: cleaned out the md2 model class, there is now only one model again

File size: 5.2 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_IDENT                       (('2'<<24) + ('P'<<16) + ('D'<<8) + 'I')
28#define MD2_VERSION                     8
29#define MD2_MAX_TRIANGLES               4096
30#define MD2_MAX_VERTICES                2048
31#define MD2_MAX_TEXCOORDS               2048
32#define MD2_MAX_FRAMES                  512
33#define MD2_MAX_SKINS                   32
34#define MD2_MAX_FRAMESIZE               (MD2_MAX_VERTICES * 4 + 128)
35
36#define NUM_VERTEX_NORMALS              162
37#define SHADEDOT_QUANT                  16
38
39//! This stores the speed of the animation between each key frame - currently conflicting with the animation framework
40#define kAnimationSpeed                 12.0f
41
42//! This holds the header information that is read in at the beginning of the file: id software definition
43struct tMd2Header
44{ 
45   int ident;                           //!< This is used to identify the file
46   int version;                         //!< The version number of the file (Must be 8)
47   
48   int skinWidth;                       //!< The skin width in pixels
49   int skinHeight;                      //!< The skin height in pixels
50   int frameSize;                       //!< The size in bytes the frames are
51   
52   int numSkins;                        //!< The number of skins associated with the model
53   int numVertices;                     //!< The number of vertices (constant for each frame)
54   int numTexCoords;                    //!< The number of texture coordinates
55   int numTriangles;                    //!< The number of faces (polygons)
56   int numGlCommands;                   //!< The number of gl commands
57   int numFrames;                       //!< The number of animation frames
58   
59   int offsetSkins;                     //!< The offset in the file for the skin data
60   int offsetTexCoords;                 //!< The offset in the file for the texture data
61   int offsetTriangles;                 //!< The offset in the file for the face data
62   int offsetFrames;                    //!< The offset in the file for the frames data
63   int offsetGlCommands;                //!< The offset in the file for the gl commands data
64   int offsetEnd;                       //!< The end of the file offset
65};
66
67
68//! This is used to store the vertices that are read in for the current frame directly from the file (compressed)
69struct tMd2AliasTriangle
70{
71   byte vertex[3];
72   byte lightNormalIndex;
73};
74
75//! This stores the normals and vertices for the frames (uncompressed)
76struct tMd2Triangle
77{
78   float vertex[3];
79   float normal[3];
80};
81
82//! This stores the indices into the vertex and texture coordinate arrays
83struct tMd2Face
84{
85   short vertexIndices[3];
86   short textureIndices[3];
87};
88
89//! This stores UV coordinates
90struct tMd2TexCoord
91{
92   short u, v;
93};
94
95//! This stores the animation scale, translation and name information for a frame, plus verts
96struct tMd2AliasFrame
97{
98   float scale[3];
99   float translate[3];
100   char name[16];
101   tMd2AliasTriangle aliasVertices[1];
102};
103
104//! This stores the frames vertices after they have been transformed
105struct tMd2Frame
106{
107   char strName[16];
108   tMd2Triangle *pVertices;
109};
110
111//! This stores a skin name
112typedef char tMd2Skin[64];
113
114typedef enum 
115  {
116    STAND,
117    RUN,
118    ATTACK,
119    PAIN_A,
120    PAIN_B,
121    PAIN_C,
122    JUMP,
123    FLIP,
124    SALUTE,
125    FALLBACK,
126    WAVE,
127    POINT,
128    CROUCH_STAND,
129    CROUCH_WALK,
130    CROUCH_ATTACK,
131    CROUCH_PAIN,
132    CROUCH_DEATH, 
133    DEATH_FALLBACK,
134    DEATH_FALLFORWARD,
135    DEATH_FALLBACKSLOW,
136    BOOM,
137 
138    MAX_ANIMATIONS
139  } animType;
140
141
142
143/* forward definitions */
144class Material;
145
146
147
148
149//! This is a MD2 Model class
150class MD2Model : public AbstractModel {
151
152public:
153  MD2Model();
154  virtual ~MD2Model();
155 
156  bool loadModel(const char* filename);
157  bool loadSkin(const char* filename);
158 
159  void drawFrame(int frame);
160  void draw();
161  void draw2();
162 
163  void setAnim(int type);
164  void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;}
165
166  void tick(float dtS);
167  void debug();
168
169
170private:
171  void animate(); 
172  void processLighting();
173  void interpolate(sVec3D* verticesList);
174  void renderFrame();
175
176 public:
177  /* these variables are static, because they are all the same for every model */
178  static sVec3D anorms[NUM_VERTEX_NORMALS];
179  static float anormsDots[SHADEDOT_QUANT][256];
180  static sAnim animationList[21];
181
182 private:
183  int numFrames;
184  int numVertices;
185  int numTriangles;
186  int numGLCommands;
187  char* fileName;
188  char* skinFileName;
189  tMd2Header* header;
190
191  sVec3D* pVertices;
192  int* pGLCommands;
193  int* pLightNormals;
194  glCommandVertex* pGLCommands2;
195
196  unsigned int textureID;
197  Material* material;
198  sAnimState animationState;
199  float scaleFactor;
200};
201
202
203
204
205
206#endif /* _MD2MODEL_H */
Note: See TracBrowser for help on using the repository browser.