Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields

Md2.h

00001 #ifndef _MD2_H
00002 #define _MD2_H
00003 
00004 #include "constants.h"
00005 
00017 using namespace std;
00018 
00022 // These are the needed defines for the max values when loading .MD2 files
00023 #define MD2_MAX_TRIANGLES       4096
00024 #define MD2_MAX_VERTICES        2048
00025 #define MD2_MAX_TEXCOORDS       2048
00026 #define MD2_MAX_FRAMES          512
00027 #define MD2_MAX_SKINS           32
00028 #define MD2_MAX_FRAMESIZE       (MD2_MAX_VERTICES * 4 + 128)
00029 
00030 // TODO :  Load different skins
00031 
00032 // Md2 header information 
00033 struct tMd2Header
00034 { 
00035    int magic;                   // This is used to identify the file
00036    int version;                 // The version number of the file (Must be 8)
00037    int skinWidth;               // The skin width in pixels
00038    int skinHeight;              // The skin height in pixels
00039    int frameSize;               // The size in bytes of a frame (constant for each)
00040    int numSkins;                // The number of skins associated with the model
00041    int numVertices;             // The number of vertices (constant for each frame)
00042    int numTexCoords;            // The number of texture coordinates
00043    int numTriangles;            // The number of faces (polygons)
00044    int numGlCommands;           // The number of gl commands
00045    int numFrames;               // The number of animation frames
00046    int offsetSkins;             // The offset in the file for the skin data
00047    int offsetTexCoords;         // The offset in the file for the texture data
00048    int offsetTriangles;         // The offset in the file for the face data
00049    int offsetFrames;            // The offset in the file for the frames data
00050    int offsetGlCommands;        // The offset in the file for the gl commands data
00051    int offsetEnd;               // The end of the file offset
00052 };
00053 
00054 
00055 // This is used to store the vertices that are read in for the current frame
00056 struct tMd2AliasTriangle
00057 {
00058    byte vertex[3];
00059    byte lightNormalIndex;
00060 };
00061 
00062 // This stores the animation scale, translation and name information for a frame, plus verts
00063 struct tMd2AliasFrame
00064 {
00065    float scale[3];
00066    float translate[3];
00067    char name[16];
00068    tMd2AliasTriangle aliasVertices[1];
00069 };
00070 
00071 
00072 // This stores a skin or a frame name 
00073 typedef char tMd2String[64];
00074 
00075 // different actions possible in a md2 file
00076 enum md2_action{
00077     MD2_STAND,
00078     MD2_RUN,
00079     MD2_ATTACK,
00080     MD2_PAIN1,
00081     MD2_PAIN2,
00082     MD2_PAIN3,
00083     MD2_JUMP,
00084     MD2_FLIP,
00085     MD2_SALUTE,    
00086     MD2_TAUNT,
00087     MD2_WAVE,
00088     MD2_POINT,
00089     MD2_CRSTAND,
00090     MD2_CRWALK,
00091     MD2_CRATTACK,
00092     MD2_CRPAIN,
00093     MD2_CRDEATH,    
00094     MD2_DEATH1,
00095     MD2_DEATH2,
00096     MD2_DEATH3,
00097     
00098     // Must be last   
00099     MD2_CREATURE_ACTION_COUNT
00100 };
00101 
00102 
00103 class CLoadMD2
00104 {
00105  
00106 public:
00107     CLoadMD2();                                
00108     bool ImportMD2(t3DModel *pModel, char *strFileName);    
00109         void DeleteMD2( t3DModel *pModel );
00110 
00111 private:        
00112         
00113     void ReadMD2Data(t3DModel *pModel);        
00114     void ParseAnimations(t3DModel *pModel);    
00115     void ComputeMinMaxValues(t3DModel *pModel);
00116     void CleanUp();
00117         
00118     FILE *m_FilePointer;   
00119 
00120     tMd2Header              m_Header;           // The header data
00121     tMd2String              *m_pSkins;          // The skin data        
00122     tMd2String              *m_pFrames;         // The name of the frames
00123 };
00124 
00125 
00126 #endif
00127 
00128 
00130 // 
00131 // Ben Humphrey (DigiBen)
00132 // Game Programmer
00133 // DigiBen@GameTutorials.com
00134 // Co-Web Host of www.GameTutorials.com
00135 //
00136 // The Quake2 .Md2 file format is owned by ID Software.  This tutorial is being used 
00137 // as a teaching tool to help understand model loading and animation.  This should
00138 // not be sold or used under any way for commercial use with out written conset
00139 // from ID Software.
00140 //
00141 // Quake and Quake2 are trademarks of id Software.
00142 // All trademarks used are properties of their respective owners. 
00143 //
00144 //
00145 

Generated on Thu Jun 16 21:50:43 2005 for scourge by  doxygen 1.4.0