Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6188 was 6022, checked in by bensch, 19 years ago

orxonox/trunk: merged the NewModel branche back to the trunk.
merged with command
svn merge branches/newModel/ trunk/ -r 6016:HEAD
no conflicts

File size: 6.8 KB
RevLine 
[4615]1/*!
[5039]2 * @file md2Model.h
[4836]3  *  Definition of an MD2 Model, a model format invented by ID Software.
[4615]4
[4245]5    We are deeply thankfull for all the wunderfull things id software made for us gamers!
[4615]6
[4245]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).
[4615]10
11    A typical model has about 200 frames, the maximum frame count is fixed by MD2_MAX_FRAMES to currently
[4245]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...
[4615]14
[4245]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
[6022]21#include "model.h"
[4245]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
[4459]27#define MD2_IDENT                       (('2'<<24) + ('P'<<16) + ('D'<<8) + 'I') //!< the md2 identifier tag in the bin file
28#define MD2_VERSION                     8                                        //!< the md2 version in the header
[4615]29#define MD2_MAX_TRIANGLES               4096                                     //!< maximal triangles count
30#define MD2_MAX_VERTICES                2048                                     //!< maximal vertices count
31#define MD2_MAX_TEXCOORDS               2048                                     //!< maximal tex coordinates
32#define MD2_MAX_FRAMES                  512                                      //!< maximal frames
33#define MD2_MAX_SKINS                   32                                       //!< maximal skins
34#define MD2_MAX_FRAMESIZE               (MD2_MAX_VERTICES * 4 + 128)             //!< maximal framesize
[4245]35
[4461]36#define NUM_VERTEX_NORMALS              162                                      //!< number of vertex normals
37#define SHADEDOT_QUANT                  16                                       //!< shade dot quantity - no idea what it is
[4245]38
39//! This stores the speed of the animation between each key frame - currently conflicting with the animation framework
[4615]40#define kAnimationSpeed                 12.0f                                    //!< animation speed
[4245]41
42//! This holds the header information that is read in at the beginning of the file: id software definition
[4279]43struct MD2Header
[4615]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
[4245]65};
66
67
[5085]68
[4459]69//! animation names enumeration
[4488]70typedef enum animType
[4245]71  {
72    STAND,
73    RUN,
74    ATTACK,
75    PAIN_A,
76    PAIN_B,
77    PAIN_C,
78    JUMP,
79    FLIP,
80    SALUTE,
81    FALLBACK,
82    WAVE,
[4279]83    POINTT,
[4245]84    CROUCH_STAND,
85    CROUCH_WALK,
86    CROUCH_ATTACK,
87    CROUCH_PAIN,
[4615]88    CROUCH_DEATH,
[4245]89    DEATH_FALLBACK,
90    DEATH_FALLFORWARD,
91    DEATH_FALLBACKSLOW,
92    BOOM,
[4615]93
[4245]94    MAX_ANIMATIONS
[4488]95  };
[4245]96
97
98
99/* forward definitions */
100class Material;
101
102
103
[4277]104//! class to store the md2 data in
[5304]105class MD2Data : public BaseObject
[4277]106{
107 public:
[4459]108  MD2Data(const char* modelFileName, const char* skinFileName);
[4277]109  virtual ~MD2Data();
[4245]110
[4459]111 private:
[4277]112  bool loadModel(const char* fileName);
[4459]113  bool loadSkin(const char* fileName = NULL);
[4277]114
[4459]115 public:
[4615]116  int                numFrames;             //!< number of frames
[4461]117  int                numVertices;           //!< number of vertices
118  int                numTriangles;          //!< number of triangles
[5085]119  int                numTexCoor;            //!< number of texture coordinates
[4461]120  int                numGLCommands;         //!< number of gl commands in the glList (tells how to draw)
121  char*              fileName;              //!< file name of the model File
122  char*              skinFileName;          //!< file name of the skin file
123  MD2Header*         header;                //!< the header file
[4277]124
[4461]125  sVec3D*            pVertices;             //!< pointer to the vertices data block
[4787]126  sTriangle*         pTriangles;            //!< pointer to the triangles data
[5085]127  sTexCoor*          pTexCoor;              //!< pointer to the texture coordinate data
[4461]128  int*               pGLCommands;           //!< pointer to the gllist data block
129  int*               pLightNormals;         //!< pointer to the light normals
[4277]130
[4615]131  Material*          material;              //!< pointer to the material
[4461]132  float              scaleFactor;           //!< the scale factor of the model, (global)
[4277]133};
134
135
[5085]136
137
[4245]138//! This is a MD2 Model class
[6022]139class MD2Model : public Model {
[4245]140
141public:
[4459]142  MD2Model(const char* modelFileName, const char* skinFileName = NULL);
[4276]143  virtual ~MD2Model();
[4615]144
[4245]145  void draw();
[4615]146
[4245]147  void setAnim(int type);
[4461]148  /**
[4836]149   *  scales the current model
150   * @param scaleFactor: the factor [0..1] to use for scaling
[4461]151  */
[4245]152  void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;}
153
154  void tick(float dtS);
155  void debug();
156
157
158private:
[4615]159  void animate();
[4245]160  void processLighting();
161  void interpolate(sVec3D* verticesList);
[5087]162  void renderFrame();
[4245]163
[5087]164
[4245]165 public:
166  /* these variables are static, because they are all the same for every model */
[4461]167  static sVec3D       anorms[NUM_VERTEX_NORMALS];       //!< the anormals
168  static float        anormsDots[SHADEDOT_QUANT][256];  //!< the anormals dot products
169  static sAnim        animationList[21];                //!< the anomation list
[4245]170
[4461]171  MD2Data*            data;                             //!< the md2 data pointer
[4245]172
[4615]173 private:
[4461]174  float               scaleFactor;                      //!< the scale factor (individual)
175  sAnimState          animationState;                   //!< animation state of the model
[4245]176};
177
178
179
180
181
182#endif /* _MD2MODEL_H */
Note: See TracBrowser for help on using the repository browser.