Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8595 was 8490, checked in by patrick, 18 years ago

merged the bsp branche back to trunk

File size: 7.7 KB
Line 
1/*!
2 * @file md2Model.h
3  *  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 "base_object.h"
22
23#include "interactive_model.h"
24#include "material.h"
25
26#include "md_model_structure.h"
27
28//! These are the needed defines for the max values when loading .MD2 files
29#define MD2_IDENT                       (('2'<<24) + ('P'<<16) + ('D'<<8) + 'I') //!< the md2 identifier tag in the bin file
30#define MD2_VERSION                     8                                        //!< the md2 version in the header
31#define MD2_MAX_TRIANGLES               4096                                     //!< maximal triangles count
32#define MD2_MAX_VERTICES                2048                                     //!< maximal vertices count
33#define MD2_MAX_TEXCOORDS               2048                                     //!< maximal tex coordinates
34#define MD2_MAX_FRAMES                  512                                      //!< maximal frames
35#define MD2_MAX_SKINS                   32                                       //!< maximal skins
36#define MD2_MAX_FRAMESIZE               (MD2_MAX_VERTICES * 4 + 128)             //!< maximal framesize
37
38#define NUM_VERTEX_NORMALS              162                                      //!< number of vertex normals
39#define SHADEDOT_QUANT                  16                                       //!< shade dot quantity - no idea what it is
40
41//! This stores the speed of the animation between each key frame - currently conflicting with the animation framework
42#define kAnimationSpeed                 12.0f                                    //!< animation speed
43
44//! This holds the header information that is read in at the beginning of the file: id software definition
45struct MD2Header
46{
47   int ident;                           //!< This is used to identify the file
48   int version;                         //!< The version number of the file (Must be 8)
49
50   int skinWidth;                       //!< The skin width in pixels
51   int skinHeight;                      //!< The skin height in pixels
52   int frameSize;                       //!< The size in bytes the frames are
53
54   int numSkins;                        //!< The number of skins associated with the model
55   int numVertices;                     //!< The number of vertices (constant for each frame)
56   int numTexCoords;                    //!< The number of texture coordinates
57   int numTriangles;                    //!< The number of faces (polygons)
58   int numGlCommands;                   //!< The number of gl commands
59   int numFrames;                       //!< The number of animation frames
60
61   int offsetSkins;                     //!< The offset in the file for the skin data
62   int offsetTexCoords;                 //!< The offset in the file for the texture data
63   int offsetTriangles;                 //!< The offset in the file for the face data
64   int offsetFrames;                    //!< The offset in the file for the frames data
65   int offsetGlCommands;                //!< The offset in the file for the gl commands data
66   int offsetEnd;                       //!< The end of the file offset
67};
68
69
70//! animation names enumeration
71typedef enum animType
72  {
73    STAND,                       //0
74    RUN,                         //1
75    ATTACK,                      //2
76    PAIN_A,                      //3
77    PAIN_B,                      //4
78    PAIN_C,          //5
79    JUMP,            //6
80    FLIP,            //7
81    SALUTE,          //8
82    FALLBACK,        //9
83    WAVE,            //10
84    POINT,           //11
85    CROUCH_STAND,
86    CROUCH_WALK,
87    CROUCH_ATTACK,
88    CROUCH_PAIN,
89    CROUCH_DEATH,
90    DEATH_FALLBACK,
91    DEATH_FALLFORWARD,
92    DEATH_FALLBACKSLOW,
93    BOOM,
94
95    MAX_ANIMATIONS
96  };
97
98
99typedef enum animPlayback
100{
101  MD2_ANIM_LOOP = 0,
102  MD2_ANIM_ONCE,
103
104  MD2_ANIM_NUM
105};
106
107
108
109/* forward definitions */
110class Material;
111
112
113
114//! class to store the md2 data in
115class MD2Data : public BaseObject
116{
117 public:
118   MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f);
119  virtual ~MD2Data();
120
121 private:
122   bool loadModel(const std::string& fileName);
123   bool loadSkin(const std::string& fileName = "");
124
125 public:
126  int                numFrames;             //!< number of frames
127  int                numVertices;           //!< number of vertices
128  int                numTriangles;          //!< number of triangles
129  int                numTexCoor;            //!< number of texture coordinates
130  int                numGLCommands;         //!< number of gl commands in the glList (tells how to draw)
131  std::string        fileName;              //!< file name of the model File
132  std::string        skinFileName;          //!< file name of the skin file
133  MD2Header*         header;                //!< the header file
134
135  sVec3D*            pVertices;             //!< pointer to the vertices data block
136  sTriangle*         pTriangles;            //!< pointer to the triangles data
137  sTexCoor*          pTexCoor;              //!< pointer to the texture coordinate data
138  int*               pGLCommands;           //!< pointer to the gllist data block
139  int*               pLightNormals;         //!< pointer to the light normals
140
141  Material           material;              //!< pointer to the material
142  float              scaleFactor;           //!< the scale factor of the model, (global)
143};
144
145
146
147
148//! This is a MD2 Model class
149class MD2Model : public InteractiveModel {
150
151public:
152  MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f);
153  virtual ~MD2Model();
154
155  virtual void draw() const;
156  void renderFrameTriangles() const;
157
158
159  virtual void setAnimation(int type, int animPlayback = MD2_ANIM_LOOP);
160  /**  returns the current animation @returns animation type */
161  inline int MD2Model::getAnim() { return this->animationState.type; }
162  /**  scales the current model @param scaleFactor: the factor [0..1] to use for scaling */
163  void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;}
164
165  virtual void tick(float dtS);
166  void debug();
167
168
169private:
170  void animate(float time);
171  void processLighting();
172  void interpolate(/*sVec3D* verticesList*/);
173  void renderFrame() const ;
174
175
176 public:
177  /* these variables are static, because they are all the same for every model */
178  static sVec3D       anorms[NUM_VERTEX_NORMALS];       //!< the anormals
179  static float        anormsDots[SHADEDOT_QUANT][256];  //!< the anormals dot products
180  static sAnim        animationList[21];                //!< the anomation list
181   //! again one of these strange id software parts
182  float*              shadeDots;
183
184  MD2Data*            data;                             //!< the md2 data pointer
185
186 private:
187  float               scaleFactor;                      //!< the scale factor (individual)
188  sAnimState          animationState;                   //!< animation state of the model
189  sVec3D              verticesList[MD2_MAX_VERTICES];   //!< place to temp sav the vert
190};
191
192
193
194
195
196#endif /* _MD2MODEL_H */
Note: See TracBrowser for help on using the repository browser.