00001 /************************************************************************/ 00002 /* Ex Nihlo Engine by Hermanns Christophe */ 00003 /************************************************************************/ 00004 /* This program is free software; you can redistribute it and/or */ 00005 /* modify it under the terms of the GNU General Public License */ 00006 /* as published by the Free Software Foundation; either version 2 */ 00007 /* of the License, or (at your option) any later version. */ 00008 /* */ 00009 /* This program is distributed in the hope that it will be useful, */ 00010 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 00011 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ 00012 /* */ 00013 /* See the GNU General Public License for more details. */ 00014 /* */ 00015 /* You should have received a copy of the GNU General Public License */ 00016 /* along with this program; if not, write to the Free Software */ 00017 /* Foundation, Inc., 59 Temple Place - Suite 330, */ 00018 /* Boston, MA 02111-1307, USA. */ 00019 /* */ 00020 /* If you use a important part of this code please send me a mail */ 00021 /* I just want to see where my code go thks :) */ 00022 /************************************************************************/ 00023 00024 /************************************************************************/ 00025 /* Contact */ 00026 /************************************************************************/ 00027 /* ExNihilo Website :www.ploksoftware.org */ 00028 /* */ 00029 /* Hermanns Christophe ExNihilo creator and main programmer */ 00030 /* */ 00031 /* Mail : Data@ploksoftware.org */ 00032 /* ICQ : 8030901 */ 00033 /* MSN Messenger : Data_7@hotmail.com */ 00034 /* */ 00035 /* */ 00036 /************************************************************************/ 00037 00038 /************************************************************************/ 00039 /* File Description */ 00040 /************************************************************************/ 00041 /* File Name :ExCModelMD2.h */ 00042 /* */ 00043 /* Start Date :06/20/2003 */ 00044 /* */ 00045 /* Last Update :06/20/2003 */ 00046 /* */ 00047 /* File Description : */ 00048 /* */ 00049 /* For update of this file check : www.ploksoftware.org */ 00050 /************************************************************************/ 00051 00052 #ifndef __EXCMODELMD2_H__ 00053 #define __EXCMODELMD2_H__ 00054 //------------------------------------------------------------------------ 00055 //Includes 00056 //------------------------------------------------------------------------ 00057 #include "ExDefine.h" 00058 //------------------------------------------------------------------------ 00059 #include "Math/ExMath.h" 00060 //------------------------------------------------------------------------ 00061 #include "Object/Object3D/Model/ExCModelMD.h" 00062 //------------------------------------------------------------------------ 00063 #include "Tools/ExCImageLoader.h" 00064 #include "Object/Object3D/Gizmo/ExCGizmoSphere.h" 00065 #include "Math/ExCFrustum.h" 00066 //-------------------------------- 00067 // These are the needed defines for the max values when loading .MD2 files 00068 #define MD2_MAX_TRIANGLES 4096 00069 #define MD2_MAX_VERTICES 2048 00070 #define MD2_MAX_TEXCOORDS 2048 00071 #define MD2_MAX_FRAMES 512 00072 #define MD2_MAX_SKINS 32 00073 #define MD2_MAX_FRAMESIZE (MD2_MAX_VERTICES * 4 + 128) 00074 00075 // This holds the header information that is read in at the beginning of the file 00076 typedef struct 00077 { 00078 int ident; // identifies as MD2 file "IDP2" 00079 int version; // mine is 8 00080 int skinwidth; // width of texture 00081 int skinheight; // height of texture 00082 int framesize; // number of bytes per frame 00083 int numSkins; // number of textures 00084 int numXYZ; // number of points 00085 int numST; // number of texture 00086 int numTris; // number of triangles 00087 int numGLcmds; 00088 int numFrames; // total number of frames 00089 int offsetSkins; // offset to skin names (64 bytes each) 00090 int offsetST; // offset of texture s-t values 00091 int offsetTris; // offset of triangle mesh 00092 int offsetFrames; // offset of frame data (points) 00093 int offsetGLcmds; // type of OpenGL commands to use 00094 int offsetEnd; // end of file 00095 } modelHeader_t; 00096 // This stores the frames vertices after they have been transformed 00097 // info for a single frame point 00098 typedef struct 00099 { 00100 short s; 00101 short t; 00102 } stIndex_t; 00103 00104 typedef struct 00105 { 00106 unsigned char v[3]; 00107 unsigned char normalIndex; // not used 00108 } framePoint_t; 00109 00110 // information for a single frame 00111 typedef struct 00112 { 00113 float scale[3]; 00114 float translate[3]; 00115 char name[16]; 00116 framePoint_t fp[1]; 00117 } frame_t; 00118 // data for a single triangle 00119 typedef struct 00120 { 00121 unsigned short meshIndex[3]; // vertex indices 00122 unsigned short stIndex[3]; // texture coordinate indices 00123 } mesh_t; 00124 //-------------------------------- 00125 class ExCModelMD2 : public ExCModelMD 00126 { 00127 protected: 00128 int m_magic; // This is used to identify the file 00129 int m_version; // The version number of the file (Must be 8) 00130 int m_skinWidth; // The skin width in pixels 00131 int m_skinHeight; // The skin height in pixels 00132 int m_frameSize; // The size in bytes the frames are 00133 int m_numSkins; // The number of skins associated with the model 00134 int m_numVertices; // The number of vertices (constant for each frame) 00135 int m_numTexCoords; // The number of texture coordinates 00136 int m_numTriangles; // The number of faces (polygons) 00137 int m_numGlCommands; // The number of gl commands 00138 //int m_numFrames; // The number of animation frames 00139 int m_offsetSkins; // The offset in the file for the skin data 00140 int m_offsetTexCoords; // The offset in the file for the texture data 00141 int m_offsetTriangles; // The offset in the file for the face data 00142 int m_offsetFrames; // The offset in the file for the frames data 00143 int m_offsetGlCommands; // The offset in the file for the gl commands data 00144 int m_offsetEnd; // The end of the file offset 00145 00146 float *TabVertices; 00147 float *TabTextures; 00148 00149 int count; 00150 00151 std::string m_LastAction; 00152 00153 bool m_ShowCollisionSphere; 00154 double m_LastTime; 00155 //-------------------------------- 00156 // Variable 00157 //-------------------------------- 00158 std::vector<std::string> m_VecSkin; 00159 00160 std::vector< std::pair<ExCVec3D , ExCVec3D > > m_VecTriangle; 00161 std::vector<ExCVec3D> m_VecVertex; 00162 std::string m_Skin; 00163 00164 std::vector<std::string> m_VecAction; 00165 std::vector<std::string>::iterator m_IVecAction; 00166 //-------------------------------- 00167 // Methode 00168 //-------------------------------- 00169 void BuildSphere(void); 00170 public: 00171 ExCGizmoSphere m_CollisionSphere; 00172 //-------------------------------- 00173 // Constructor // Destructor 00174 //-------------------------------- 00175 ExCModelMD2(void); 00176 //ExCModelMD2(const ExCModelMD2& copy); 00177 ~ExCModelMD2(void); 00178 //-------------------------------- 00179 // Methode 00180 //-------------------------------- 00181 void Draw(void); 00182 bool Load(std::string FileName); 00183 void StartAction(std::string Action); 00184 void StopAction(std::string Action); 00185 void Process(std::string Action); 00186 void ProcessAllAction(void); 00187 ExCAction InputAction(ExCAction Action); 00188 bool IsAction(std::string Action); 00189 void ShowInfo(void); 00190 }; 00191 #endif //__EXCMODELMD2_H__ 00192