Hauptseite   Klassenhierarchie   Übersicht   Auflistung der Dateien   Datenstruktur-Elemente   Datei-Elemente  

sw_MD2.h

00001 #ifndef sw_MD2_H
00002 #define sw_MD2_H
00003 
00004 #include <windows.h>            //Windows header file
00005 #include <stdio.h> 
00006 #include <stdlib.h>
00007 #include <string.h>
00008 #include <io.h>
00009 #include "il.h"
00010 
00011 #include "glew.h"                       //OpenGL header file
00012 //include <glu.h>                       //The OpenGL Glu header file
00013 #include "glut.h"
00014 
00015 #pragma comment(lib, "OpenGL32.lib")//Search for the OpenGL32 library at compile time
00016 #pragma comment(lib, "Glu32.lib")       //Search for the Glu32 library at compile time
00017 
00018 /* MD2 constants */
00019 #define MAX_TRIANGLES 4096
00020 #define MAX_VERTICES  2048
00021 #define MAX_TEXCOORDS 2048
00022 #define MAX_FRAMES    512
00023 // number of precalculated normals
00024 #define NUMVERTEXNORMALS                162
00025 
00026 #define CHUNK1 0
00027 #define CHUNK2 1
00028 #define CHUNK3 2
00029 #define CHUNK4 3
00030 
00031 /* MD2 state constants */
00032 #define ANIMATE_CURRENT -100
00033 
00034 #define IDLE1                           0
00035 #define RUN                                     1
00036 #define SHOT_STAND                      2
00037 #define SHOT_SHOULDER           3
00038 #define JUMP                            4
00039 #define IDLE2                           5
00040 #define SHOT_FALLDOWN           6
00041 #define IDLE3                           7
00042 #define IDLE4                           8
00043 #define CROUCH                          9
00044 #define CROUCH_CRAWL            10
00045 #define CROUCH_IDLE                     11
00046 #define CROUCH_DEATH            12
00047 #define DEATH_FALLBACK          13
00048 #define DEATH_FALLFORWARD       14
00049 #define DEATH_FALLBACKSLOW      15
00050 
00051 #define IDLE1_START                                     0
00052 #define IDLE1_END                                       39
00053 #define RUN_START                                       40
00054 #define RUN_END                                         45
00055 #define SHOT_STAND_START                        46
00056 #define SHOT_STAND_END                          60
00057 #define SHOT_SHOULDER_START                     61
00058 #define SHOT_SHOULDER_END                       66
00059 #define JUMP_START                                      67
00060 #define JUMP_END                                        73
00061 #define IDLE2_START                                     74
00062 #define IDLE2_END                                       95
00063 #define SHOT_FALLDOWN_START                     96
00064 #define SHOT_FALLDOWN_END                       112
00065 #define IDLE3_START                                     113
00066 #define IDLE3_END                                       122
00067 #define IDLE4_START                                     123
00068 #define IDLE4_END                                       135
00069 #define CROUCH_START                            136
00070 #define CROUCH_END                                      154
00071 #define CROUCH_CRAWL_START                      155
00072 #define CROUCH_CRAWL_END                        161
00073 #define CROUCH_IDLE_START                       162
00074 #define CROUCH_IDLE_END                         169
00075 #define CROUCH_DEATH_START                      170
00076 #define CROUCH_DEATH_END                        177
00077 #define DEATH_FALLBACK_START            178
00078 #define DEATH_FALLBACK_END                      185
00079 #define DEATH_FALLFORWARD_START         186
00080 #define DEATH_FALLFORWARD_END           190
00081 #define DEATH_FALLBACKSLOW_START        191
00082 #define DEATH_FALLBACKSLOW_END          198
00083 
00084 // MD2 STRUCTURES
00085 //for normals
00086 typedef float vec3_t[3];
00087 
00088 typedef struct MD2_HEADER_TYP
00089         {
00090         int magic;                              //The 'magic' number (always 844121161)
00091         int version;                    //The version number of the file (always 8)
00092         int skinWidth;                  //The width of the model's skin
00093         int skinHeight;                 //The height of the model's skin
00094         int frameSize;                  //The size of each frame (in BYTEs)
00095         int numSkins;                   //The model's number of skins
00096         int numVertices;                //The model's number of vertices
00097         int numTexcoords;               //The model's number of texture coordinates (most likely, its not the same number as the vertices)
00098         int numTriangles;               //The number of triangles that make up the model
00099         int numGlCommands;              //The number of DWORDs (4 bytes) in the GLcommand list (which decide to render the model with tri strips, or fans)
00100         int numFrames;                  //The number of frames (of animation) that the model has
00101         int offsetSkins;                //Offset in the file of the model, to where the skin information is
00102         int offsetTexcoords;    //Offset in the file of the model, to where the texture coordinate information is
00103         int offsetTriangles;    //Offset in the file of the model, to where the traingle information is
00104         int offsetFrames;               //Offset in the file of the model, to where the first frame information is given
00105         int offsetGlCommands;   //Offset in the file of the model, to where the GLcommand information is
00106         int offsetEnd;                  //Offset in the file of the model, to where the end of it is
00107         } MD2_HEADER, *MD2_HEADER_PTR;
00108 
00109 typedef struct MD2_VERTEX_TYP
00110         {
00111         unsigned char vertex[3];                //Scaled version of the model's 'real' vertex coordinate
00112         unsigned char lightNormalIndex; //An index into the table of normals, kept by Quake 2
00113         } MD2_VERTEX, *MD2_VERTEX_PTR;
00114 
00115 typedef struct MD2_FRAME_TYP
00116         {
00117         float      scale[3];            //The scale used by the model's 'fake' vertex structure
00118         float      translate[3];        //The translation used by the model's 'fake' vertex structure
00119         char       name[16];            //The name for the frame
00120         MD2_VERTEX vertices[1];         //An array of MD2_VERTEX structures
00121         } MD2_FRAME, *MD2_FRAME_PTR;
00122 
00123 typedef struct MD2_MODELVERTEX_TYP
00124         {
00125         float x,y,z;                            //The (x,y,z) location of the vertex
00126         float u,v;                                      //The (u,v) location of the texture coordinate
00127         float normalx;                          //Normalvector
00128         float normaly;
00129         float normalz;
00130         } MD2_MODELVERTEX, *MD2_MODELVERTEX_PTR;
00131 
00132 
00133 //CLASSES
00134 
00135 class MD2
00136         {
00137         private:        
00138                 int numGlCommands;
00139                 long* glCommands;
00140 
00141                 int numTriangles;
00142                 GLuint texName[1];
00143 
00144         public:
00145                 int stateStart;
00146                 int stateEnd;
00147 
00148                 int frameSize;
00149                 int numFrames;
00150                 char* frames;
00151 
00152                 int currentFrame;
00153                 int nextFrame;
00154                 int endFrame;
00155                 int startFrame;
00156                 float interpolation;
00157                 
00158                 GLfloat VertexArray[2048*3]; // vertex array
00159         GLfloat NormalArray[2048*3]; // normal array
00160                 GLfloat TexCoordArray[2048*2]; // array for all texture coordinates     
00161         
00162         static vec3_t   anorms[ NUMVERTEXNORMALS ];
00163         bool LoadTexture(char* filename);
00164         bool Load(char* filename);
00165         void Render(int numFrame1, int numFrame2, int mode);
00166         void Animate(int startFrame, int EndFrame, float Interpolation, int mode);
00167         void SetState(int state);
00168 
00169         MD2() : stateStart(IDLE1_START), stateEnd(IDLE1_END),
00170                         numGlCommands(0), frameSize(0), numFrames(0), 
00171                         currentFrame(IDLE1_START), nextFrame(currentFrame+1),
00172                         endFrame(IDLE1_END), interpolation(0.0f)
00173                 {       }
00174 
00175         ~MD2()
00176                 {       
00177                 if(glCommands)
00178                         delete [] glCommands;
00179                 if(frames)
00180                         delete [] frames;
00181                 glDisableClientState(GL_VERTEX_ARRAY);
00182                 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
00183                 glDisableClientState(GL_NORMAL_ARRAY);
00184                 }
00185         };
00186 
00187 #endif  //sw_MD2.h

Erzeugt am Thu Jun 19 22:50:44 2003 für Schneeweiß von doxygen1.3