00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00057
00058
00059
00060 struct md2_header
00061 {
00062 int magic;
00063 int version;
00064 int skinWidth;
00065 int skinHeight;
00066 int frameSize;
00067 int num_skins;
00068 int num_vertices;
00069 int num_texCoords;
00070 int num_triangles;
00071 int num_glcmds;
00072 int num_frames;
00073 int offset_skins;
00074 int offset_texCoords;
00075 int offset_triangles;
00076 int offset_frames;
00077 int offset_glcmds;
00078 int offset_end;
00079
00080 };
00081
00082
00083 struct md2_rTriangle
00084 {
00085 byte vertex[3];
00086 byte lightNormalIndex;
00087 };
00088
00089
00090 struct md2_triangle
00091 {
00092 float vertex[3];
00093 float normal[3];
00094 };
00095
00096
00097 struct md2_face
00098 {
00099 short vertexIndices[3];
00100 short texCoordIndices[3];
00101 };
00102
00103
00104 struct md2_texCoord
00105 {
00106 short u;
00107 short v;
00108 };
00109
00110
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
00120 struct md2_frame
00121 {
00122 char name[16];
00123 md2_triangle *pVertices;
00124 };
00125
00126
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;
00166 bool m_bump;
00167
00168 };
00169
00170
00171 }
00172 #endif
00173