[4245] | 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 |
---|
[4279] | 43 | struct MD2Header |
---|
[4245] | 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 | |
---|
| 69 | typedef enum |
---|
| 70 | { |
---|
| 71 | STAND, |
---|
| 72 | RUN, |
---|
| 73 | ATTACK, |
---|
| 74 | PAIN_A, |
---|
| 75 | PAIN_B, |
---|
| 76 | PAIN_C, |
---|
| 77 | JUMP, |
---|
| 78 | FLIP, |
---|
| 79 | SALUTE, |
---|
| 80 | FALLBACK, |
---|
| 81 | WAVE, |
---|
[4279] | 82 | POINTT, |
---|
[4245] | 83 | CROUCH_STAND, |
---|
| 84 | CROUCH_WALK, |
---|
| 85 | CROUCH_ATTACK, |
---|
| 86 | CROUCH_PAIN, |
---|
| 87 | CROUCH_DEATH, |
---|
| 88 | DEATH_FALLBACK, |
---|
| 89 | DEATH_FALLFORWARD, |
---|
| 90 | DEATH_FALLBACKSLOW, |
---|
| 91 | BOOM, |
---|
| 92 | |
---|
| 93 | MAX_ANIMATIONS |
---|
| 94 | } animType; |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | /* forward definitions */ |
---|
| 99 | class Material; |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | |
---|
[4277] | 103 | //! class to store the md2 data in |
---|
| 104 | class MD2Data |
---|
| 105 | { |
---|
| 106 | public: |
---|
| 107 | MD2Data(); |
---|
| 108 | virtual ~MD2Data(); |
---|
[4245] | 109 | |
---|
[4277] | 110 | bool loadModel(const char* fileName); |
---|
| 111 | bool loadSkin(const char* fileName); |
---|
| 112 | |
---|
| 113 | int numFrames; |
---|
| 114 | int numVertices; |
---|
| 115 | int numTriangles; |
---|
| 116 | int numGLCommands; |
---|
| 117 | char* fileName; |
---|
| 118 | char* skinFileName; |
---|
[4279] | 119 | MD2Header* header; |
---|
[4277] | 120 | |
---|
| 121 | sVec3D* pVertices; |
---|
| 122 | int* pGLCommands; |
---|
| 123 | int* pLightNormals; |
---|
| 124 | glCommandVertex* pGLCommands2; |
---|
| 125 | |
---|
| 126 | Material* material; |
---|
| 127 | float scaleFactor; |
---|
| 128 | }; |
---|
| 129 | |
---|
| 130 | |
---|
[4245] | 131 | //! This is a MD2 Model class |
---|
[4276] | 132 | class MD2Model : public AbstractModel { |
---|
[4245] | 133 | |
---|
| 134 | public: |
---|
[4276] | 135 | MD2Model(); |
---|
| 136 | virtual ~MD2Model(); |
---|
[4245] | 137 | |
---|
| 138 | bool loadModel(const char* filename); |
---|
| 139 | bool loadSkin(const char* filename); |
---|
| 140 | |
---|
| 141 | void drawFrame(int frame); |
---|
| 142 | void draw(); |
---|
| 143 | void draw2(); |
---|
| 144 | |
---|
| 145 | void setAnim(int type); |
---|
| 146 | void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;} |
---|
| 147 | |
---|
| 148 | void tick(float dtS); |
---|
| 149 | void debug(); |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | private: |
---|
| 153 | void animate(); |
---|
| 154 | void processLighting(); |
---|
| 155 | void interpolate(sVec3D* verticesList); |
---|
| 156 | void renderFrame(); |
---|
| 157 | |
---|
| 158 | public: |
---|
| 159 | /* these variables are static, because they are all the same for every model */ |
---|
| 160 | static sVec3D anorms[NUM_VERTEX_NORMALS]; |
---|
| 161 | static float anormsDots[SHADEDOT_QUANT][256]; |
---|
| 162 | static sAnim animationList[21]; |
---|
| 163 | |
---|
| 164 | private: |
---|
[4277] | 165 | MD2Data* data; |
---|
[4245] | 166 | |
---|
[4282] | 167 | float scaleFactor; |
---|
[4245] | 168 | sAnimState animationState; |
---|
| 169 | }; |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | #endif /* _MD2MODEL_H */ |
---|