PowerVR Software Development Kit |
00001 /*!*************************************************************************** 00002 @File PVRTModelMD2.h 00003 00004 @Brief Header to load MD2 files. 00005 00006 @Author PowerVR 00007 00008 @Date January 2005 00009 00010 @Copyright Copyright 2003-2004 by Imagination Technologies Limited. 00011 All rights reserved. No part of this software, either 00012 material or conceptual may be copied or distributed, 00013 transmitted, transcribed, stored in a retrieval system 00014 or translated into any human or computer language in any 00015 form by any means, electronic, mechanical, manual or 00016 other-wise, or disclosed to third parties without the 00017 express written permission of Imagination Technologies 00018 Limited, Unit 8, HomePark Industrial Estate, 00019 King's Langley, Hertfordshire, WD4 8LZ, U.K. 00020 00021 @Platform ANSI compatible 00022 00023 @Description Header to load MD2 files. 00024 Based on MD2 Tutorial by David Henry - tfc_duke@hotmail.com 00025 Converted, fixes and some optimisations for usage with OGLES 00026 00027 $Revision: 1.9 $ 00028 *****************************************************************************/ 00029 #ifndef __MD2_H 00030 #define __MD2_H 00031 00032 /**************************************************************************** 00033 ** Defines 00034 ****************************************************************************/ 00035 00036 // number of precalculated normals 00037 #define NUMVERTEXNORMALS 162 00038 00039 // precalculated normal vectors 00040 #define SHADEDOT_QUANT 16 00041 00042 // magic number "IDP2" or 844121161 00043 #define MD2_IDENT (('2'<<24) + ('P'<<16) + ('D'<<8) + 'I') 00044 00045 // model version 00046 #define MD2_VERSION 8 00047 00048 // maximum number of vertices for a MD2 model 00049 #define MAX_MD2_VERTS 2048 00050 00051 typedef float vec3_t[3]; 00052 00053 /**************************************************************************** 00054 ** Structures 00055 ****************************************************************************/ 00056 00057 /*!*************************************************************************** 00058 md2 header 00059 *****************************************************************************/ 00060 typedef struct 00061 { 00062 int ident; 00063 int version; 00065 int skinwidth; 00066 int skinheight; 00067 int framesize; 00069 int num_skins; 00070 int num_xyz; 00071 int num_st; 00072 int num_tris; 00073 int num_glcmds; 00074 int num_frames; 00076 int ofs_skins; 00077 int ofs_st; 00078 int ofs_tris; 00079 int ofs_frames; 00080 int ofs_glcmds; 00081 int ofs_end; 00083 } md2_t; 00084 00085 /*!*************************************************************************** 00086 vertex 00087 *****************************************************************************/ 00088 typedef struct 00089 { 00090 unsigned char v[3]; 00091 unsigned char lightnormalindex; 00093 } vertex_t; 00094 00095 /*!*************************************************************************** 00096 frame 00097 *****************************************************************************/ 00098 typedef struct 00099 { 00100 float scale[3]; 00101 float translate[3]; 00102 char name[16]; 00103 vertex_t verts[1]; 00105 } frame_t; 00106 00107 /*!*************************************************************************** 00108 animation 00109 *****************************************************************************/ 00110 typedef struct 00111 { 00112 int first_frame; 00113 int last_frame; 00114 int fps; 00116 } anim_t; 00117 00118 /*!*************************************************************************** 00119 status animation 00120 *****************************************************************************/ 00121 typedef struct 00122 { 00123 int startframe; 00124 int endframe; 00125 int fps; 00127 float curr_time; 00128 float old_time; 00129 float interpol; 00131 int type; 00133 int curr_frame; 00134 int next_frame; 00136 } animState_t; 00137 00138 /*!*************************************************************************** 00139 Main Data Storage for Float Case 00140 *****************************************************************************/ 00141 typedef struct 00142 { 00143 unsigned char *pColorArray; 00144 float *pTexCoordArray; 00145 float *pNormalArray; 00146 float *pPositionArray; 00147 int NumberOfFans; 00148 int NumberOfStrips; 00149 int Offset2Strips; 00150 int *pFanLengths; 00151 int *pStripLengths; 00152 } MyFloatDrawArray; 00153 00154 /*!*************************************************************************** 00155 Main Data Storage for Fixed Point Case 00156 *****************************************************************************/ 00157 typedef struct 00158 { 00159 unsigned char *pColorArray; 00160 int *pTexCoordArray; 00161 int *pNormalArray; 00162 int *pPositionArray; 00163 int NumberOfFans; 00164 int NumberOfStrips; 00165 int Offset2Strips; 00166 int *pFanLengths; 00167 int *pStripLengths; 00168 } MyFixedDrawArray; 00169 00170 /**************************************************************************** 00171 ** Enumeration 00172 ****************************************************************************/ 00173 00174 /*!*************************************************************************** 00175 animation list 00176 *****************************************************************************/ 00177 typedef enum { 00178 STAND, 00179 RUN, 00180 ATTACK, 00181 PAIN_A, 00182 PAIN_B, 00183 PAIN_C, 00184 JUMP, 00185 FLIP, 00186 SALUTE, 00187 FALLBACK, 00188 WAVE, 00189 POINTING, 00190 CROUCH_STAND, 00191 CROUCH_WALK, 00192 CROUCH_ATTACK, 00193 CROUCH_PAIN, 00194 CROUCH_DEATH, 00195 DEATH_FALLBACK, 00196 DEATH_FALLFORWARD, 00197 DEATH_FALLBACKSLOW, 00198 BOOM, 00199 00200 MAX_ANIMATIONS 00201 00202 } animType_t; 00203 00204 /*!*************************************************************************** 00205 CMD2Model - MD2 model class object. 00206 *****************************************************************************/ 00207 class CMD2Model 00208 { 00209 public: 00210 /*!*********************************************************************** 00211 @Function Constructor 00212 @Description Init all Class Data 00213 *************************************************************************/ 00214 CMD2Model( void ); 00215 /*!*********************************************************************** 00216 @Function Destructor 00217 @Description Free all allocated Resources 00218 *************************************************************************/ 00219 ~CMD2Model( void ); 00220 00221 // functions 00222 /*!*********************************************************************** 00223 @Function LoadModelFloatFromFile 00224 @Input filename File to load from 00225 @Return True if OK, False if there was a problem 00226 @Description Loads the specified ".MD2" file from disk into Float Format 00227 *************************************************************************/ 00228 bool LoadModelFloatFromFile( const char *filename ); 00229 00230 /*!*********************************************************************** 00231 @Function LoadModelFixedFromFile 00232 @Input filename File to load from 00233 @Return True if OK, False if there was a problem 00234 @Description Loads the specified ".MD2" file from disk into Fixed Format 00235 *************************************************************************/ 00236 bool LoadModelFixedFromFile( const char *filename ); 00237 00238 /*!*********************************************************************** 00239 @Function LoadModelFloatFromHeader 00240 @Input headername Header to load the model from 00241 @Return True if OK, False if there was a problem 00242 @Description Loads the specified ".MD2" file from disk into Float Format 00243 *************************************************************************/ 00244 bool LoadModelFloatFromHeader( const char *headername ); 00245 00246 /*!*********************************************************************** 00247 @Function LoadModelFixedFromHeader 00248 @Input headername Header to load the model from 00249 @Return True if OK, False if there was a problem 00250 @Description Loads the specified ".MD2" file from disk into Fixed Format 00251 *************************************************************************/ 00252 bool LoadModelFixedFromHeader( const char *headername ); 00253 00254 /*!*********************************************************************** 00255 @Function SetAnim 00256 @Input type One of the animType_t Enumerations 00257 @Description Selects the current Animation to playback. 00258 *************************************************************************/ 00259 void SetAnim( int type ); 00260 00261 /*!*********************************************************************** 00262 @Function ScaleModel 00263 @Input s Scale to apply 00264 @Description Sets the scale used when generating the Model Data. 00265 *************************************************************************/ 00266 void ScaleModel( float s ); 00267 00268 /*!*********************************************************************** 00269 @Function GetNumberOfVertices 00270 @Return Number of actual vertices 00271 @Description Returns number of vertices in buffer. 00272 *************************************************************************/ 00273 int GetNumberOfVertices(); 00274 00275 /*!*********************************************************************** 00276 @Function GetModelDataPntrsFloat 00277 @Output pPosition Vertex array 00278 @Output pTexCoord Texture coordinates array 00279 @Output pNormal Normal array 00280 @Output pColor Color array 00281 @Output NumberOfFans Number of fans 00282 @Output NumberOfStrips Number of strips 00283 @Output Offset2Strips Offset in bytes to strips 00284 @Output pFanLengths Lengths of the fans 00285 @Output pStripLengths Lengths of the strips 00286 @Input time Time in the animation to get the mesh at 00287 @Description Outputs a Vertex Position Array and optionally Normal, 00288 TexCoord and Color Arrays which can be used to render 00289 the MD2 Model. In addition the number of Fans and Strips 00290 and their respective lengths (Array) are reported. Also 00291 provide is the offset to locate the Strips. In the Arrays 00292 Fans are stored first and Strips are stored after them. 00293 This is the Float Format version. Do not use on objects 00294 loaded in Fixed Format ! 00295 *************************************************************************/ 00296 void GetModelDataPntrsFloat(float time, float **pPosition, float **pTexCoord, float **pNormal, unsigned char **pColor, int *NumberOfFans, int *NumberOfStrips, int *Offset2Strips, int **pFanLengths, int **pStripLengths); 00297 00298 /*!*********************************************************************** 00299 @Function GetModelDataPntrsFixed 00300 @Output pPosition Vertex array 00301 @Output pTexCoord Texture coordinates array 00302 @Output pNormal Normal array 00303 @Output pColor Color array 00304 @Output NumberOfFans Number of fans 00305 @Output NumberOfStrips Number of strips 00306 @Output Offset2Strips Offset in bytes to strips 00307 @Output pFanLengths Lengths of the fans 00308 @Output pStripLengths Lengths of the strips 00309 @Input time Time in the animation to get the mesh at 00310 @Description Outputs a Vertex Position Array and optionally Normal, 00311 TexCoord and Color Arrays which can be used to render 00312 the MD2 Model. In addition the number of Fans and Strips 00313 and their respective lengths (Array) are reported. Also 00314 provide is the offset to locate the Strips. In the Arrays 00315 Fans are stored first and Strips are stored after them. 00316 This is the Fixed Format version. Do not use on objects 00317 loaded in Float Format ! 00318 *************************************************************************/ 00319 void GetModelDataPntrsFixed(float time, int **pPosition, int **pTexCoord, int **pNormal, unsigned char **pColor, int *NumberOfFans, int *NumberOfStrips, int *Offset2Strips, int **pFanLengths, int **pStripLengths); 00320 00321 /*!*********************************************************************** 00322 @Function GenerateTriangleList 00323 @Return Index List 00324 @Description Outputs a triangle index list to allow for single 00325 draw call to draw the whole object. Unsigned Short data format returned. 00326 *************************************************************************/ 00327 unsigned short* GenerateTriangleList( void ); 00328 00329 private: // These are tool functions used by the Public Functions 00330 void Animate( float time ); 00331 void ProcessLighting( void ); 00332 void InterpolatePosition( vec3_t *vertlist); 00333 void InterpolateNormal( vec3_t *normlist ); 00334 bool InitMyArraysFloat( void ); 00335 bool InitMyArraysFixed( void ); 00336 void DestroyMyArrays( void ); 00338 public: 00339 // member variables - these are Look-up Tables 00340 static vec3_t anorms[ NUMVERTEXNORMALS ]; 00341 static float anorms_dots[ SHADEDOT_QUANT ][256]; 00342 00343 static anim_t animlist[21]; 00344 int TriangleCount; 00345 00346 00347 private: 00348 // some private class variables 00349 int num_frames; 00350 int num_xyz; 00351 int num_glcmds; 00353 vec3_t *m_vertices; 00354 int *m_glcmds; 00355 int *m_lightnormals; 00357 unsigned int m_texid; 00358 animState_t m_anim; 00359 float m_scale; 00361 MyFloatDrawArray MyFloatFansAndStrips; 00362 MyFixedDrawArray MyFixedFansAndStrips; 00363 unsigned short* Indices; 00365 float oldtime; 00367 bool ObjectIsFloat; 00369 int MyVertexCount; 00370 }; 00371 00372 00373 #endif // __MD2_H
Copyright © 1999-2006, PowerVR Technologies and partners. PowerVR Technologies is a division of Imagination Technologies Ltd.