Page principale | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de classe

C:/Projects/ngn/include/models_md2.h

00001 /***************************************************************************
00002  *            models_md2.h
00003  *
00004  *  Sat Apr  3 13:00:38 2004
00005  *  Copyright  2004  tite
00006  *  thierry.schartz@skynet.be
00007  ****************************************************************************/
00008 /*
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU Library General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023  
00024 #ifndef MODELS_MD2_H
00025 #define MODELS_MD2_H
00026 
00027 #ifdef WIN32
00028 #include <windows.h>
00029 #endif
00030 
00031 
00032 #include <fstream>
00033 #include <string>
00034 #include "models.h"
00035 #include "texture.h"
00036 #include "shader.h"
00037 
00038 
00039 
00040 #define MD2_MAGIC_NUMBER  844121161 //"IDP2"
00041 #define MD2_VERSION_NUMBER 8
00042 #define MD2_MAX_TRIANGLES               4096
00043 #define MD2_MAX_VERTICES                2048
00044 #define MD2_MAX_TEXCOORDS      2048
00045 #define MD2_MAX_FRAMES                  512
00046 #define MD2_MAX_SKINS                           32
00047 #define MD2_MAX_FRAMESIZE               (MD2_MAX_VERTICES * 4 + 128)
00048 
00049 #define NUM_VERTEX_NORMALS 162
00050 #define SHADEDOT_QUANT 16
00051 
00052 namespace ngn {
00053 
00054 
00055 
00056                 /* .md2 file format description */
00057                 /********************************/
00058 
00059                 // header
00060                 struct md2_header
00061                 {
00062                         int     magic;              // magic number. must be equal to "IPD2"
00063                         int     version;            // md2 version. must be equal to 8
00064                         int     skinWidth;          // width of the texture
00065                         int     skinHeight;         // height of the texture
00066                         int     frameSize;          // size of one frame in bytes
00067                         int     num_skins;          // number of textures
00068                         int     num_vertices;            // number of vertices
00069                         int     num_texCoords;             // number of texture coordinates
00070                         int     num_triangles;           // number of triangles
00071                         int     num_glcmds;         // number of opengl commands
00072                         int     num_frames;         // total number of frames
00073                         int     offset_skins;          // offset to skin names (64 bytes each)
00074                         int     offset_texCoords;             // offset to s-t texture coordinates
00075                         int     offset_triangles;           // offset to triangles
00076                         int     offset_frames;         // offset to frame data
00077                         int     offset_glcmds;         // offset to opengl commands
00078                         int     offset_end;            // offset to end of file
00079 
00080                 };
00081 
00082                 // stores vertices read in for the current frame        
00083                 struct md2_rTriangle
00084                 {
00085                         byte vertex[3];
00086                         byte lightNormalIndex;
00087                 };
00088 
00089                 // stores vertices and normals for the frames
00090                 struct md2_triangle
00091                 {
00092                         float vertex[3];
00093                         float normal[3];
00094                 };
00095 
00096                 // stores indices into vertex and texcoords arrays
00097                 struct md2_face
00098                 {
00099                         short vertexIndices[3];
00100                         short texCoordIndices[3];
00101                 };
00102 
00103                 // stores UV texture coordinates
00104                 struct md2_texCoord
00105                 {
00106                         short u;
00107                         short v;
00108                 };
00109 
00110                 // stores animation vertex transformations
00111                 struct md2_rFrame
00112                 {
00113                         float scale[3];
00114                         float translate[3];
00115                         char name[16];
00116                         md2_rTriangle rVertices[1];
00117                 };
00118 
00119                 // stores frames after transformations
00120                 struct md2_frame
00121                 {
00122                         char name[16];
00123                         md2_triangle *pVertices;
00124                 };
00125 
00126                 // stores skin name
00127                 typedef char md2_skin[64];
00128 
00129 
00130 
00134                 class NGN_API Md2Model : public Model
00135                 {
00136                 public:
00137                                 Md2Model();
00138                                 virtual ~Md2Model();
00139                                 
00141                                 virtual void renderModel( const Camera& cam );
00143                                 virtual bool loadModel( std::string model_file, std::string skin_file );
00144 
00145                                 
00146                                 
00147                 private:
00148                         void readData();
00149                         void convertData();
00150                         void readAnimations();
00151                         void clean();
00152                         virtual void calculateBBox();
00153                         float getCurrentTime( int nextFrame );
00154 
00155                         md2_header m_header;
00156                         md2_skin        *m_pSkins;
00157                         md2_texCoord *m_pTexCoords;
00158                         md2_face *m_pFaces;
00159                         md2_frame *m_pFrames;
00160                         md2_triangle *m_pTriangles;
00161                         std::ifstream m_file;
00162                         core::Texture m_texture0;
00163                         core::Texture m_texture1;
00164                         unsigned int m_texid[2];
00165                         gl::ShaderProgram m_shader;     // bump mapping shader
00166                         bool m_bump;
00167                         
00168                 };
00169 
00170 
00171 }//ngn
00172 #endif /* MODELS_MD2_H */
00173 

Généré le Fri Nov 19 14:20:29 2004 pour NGN par  doxygen 1.3.9.1