t3dlib13.h
上传用户:husern
上传日期:2018-01-20
资源大小:42486k
文件大小:10k
源码类别:

游戏

开发平台:

Visual C++

  1. // T3DLIB13.H - header file for T3DLIB13.H
  2. // watch for multiple inclusions
  3. #ifndef T3DLIB13
  4. #define T3DLIB13
  5. // DEFINES //////////////////////////////////////////////////////////////////
  6. #define MD2_MAGIC_NUM       (('I') + ('D' << 8) + ('P' << 16) + ('2' << 24))
  7. #define MD2_VERSION         8 
  8. #define MD2_DEBUG           0  // 0 - minimal output when loading files
  9.                                // 1 - the farm
  10. // md2 animation defines
  11. #define NUM_MD2_ANIMATIONS  20 // total number of MD2 animations
  12. #define MD2_MAX_FRAMES     198 // total number of MD2 frames, but I have seen 199, and 200
  13. // md2 animation states
  14. #define MD2_ANIM_STATE_STANDING_IDLE      0  // model is standing and idling
  15. #define MD2_ANIM_STATE_RUN                1  // model is running
  16. #define MD2_ANIM_STATE_ATTACK             2  // model is firing weapon/attacking
  17. #define MD2_ANIM_STATE_PAIN_1             3  // model is being hit version 1
  18. #define MD2_ANIM_STATE_PAIN_2             4  // model is being hit version 2
  19. #define MD2_ANIM_STATE_PAIN_3             5  // model is being hit version 3
  20. #define MD2_ANIM_STATE_JUMP               6  // model is jumping
  21. #define MD2_ANIM_STATE_FLIP               7  // model is using hand gestures :)
  22. #define MD2_ANIM_STATE_SALUTE             8  // model is saluting
  23. #define MD2_ANIM_STATE_TAUNT              9  // model is taunting
  24. #define MD2_ANIM_STATE_WAVE               10 // model is waving at someone
  25. #define MD2_ANIM_STATE_POINT              11 // model is pointing at someone
  26. #define MD2_ANIM_STATE_CROUCH_STAND       12 // model is crouching and idling
  27. #define MD2_ANIM_STATE_CROUCH_WALK        13 // model is walking while crouching
  28. #define MD2_ANIM_STATE_CROUCH_ATTACK      14 // model is firing weapon/attacking with crouching
  29. #define MD2_ANIM_STATE_CROUCH_PAIN        15 // model is being hit while crouching
  30. #define MD2_ANIM_STATE_CROUCH_DEATH       16 // model is dying while crouching
  31. #define MD2_ANIM_STATE_DEATH_BACK         17 // model is dying while falling backward
  32. #define MD2_ANIM_STATE_DEATH_FORWARD      18 // model is dying while falling forward
  33. #define MD2_ANIM_STATE_DEATH_SLOW         19 // model is dying slowly (any direction)
  34. // modes to run animation
  35. #define MD2_ANIM_LOOP                        0 // play animation over and over
  36. #define MD2_ANIM_SINGLE_SHOT                 1 // single shot animation
  37. // note: the idle animations are sometimes used for other things like salutes, hand motions, etc.
  38. // TYPES ///////////////////////////////////////////////////////////////////
  39. // this if the header structure for a Quake II .MD2 file by id Software,
  40. // I have slightly annotated the field names to make them more readable 
  41. // and less cryptic :)
  42. typedef struct MD2_HEADER_TYP
  43. {
  44. int identifier;     // identifies the file type, should be "IDP2"
  45. int version;        // version number, should be 8
  46. int skin_width;     // width of texture map used for skinning
  47. int skin_height;    // height of texture map using for skinning
  48. int framesize;      // number of bytes in a single frame of animation
  49. int num_skins;      // total number of skins
  50.                     // listed by ASCII filename and are available 
  51.                     // for loading if files are found in full path
  52. int num_verts;      // number of vertices in each model frame, the 
  53.                     // number of vertices in each frame is always the
  54.                     // same
  55. int num_textcoords; // total number of texture coordinates in entire file 
  56.                     // may be larger than the number of vertices
  57. int num_polys;      // number of polygons per model, or per frame of 
  58.                     // animation if you will
  59. int num_openGLcmds; // number of openGL commands which can help with
  60.                     // rendering optimization
  61.                     // however, we won't be using them
  62. int num_frames;     // total number of animation frames
  63. // memory byte offsets to actual data for each item
  64. int offset_skins;      // offset in bytes from beginning of file to the 
  65.                        // skin array that holds the file name for each skin, 
  66.                        // each file name record is 64 bytes
  67. int offset_textcoords; // offset in bytes from the beginning of file to the  
  68.                        // texture coordinate array
  69. int offset_polys;      // offset in bytes from beginning of file to the 
  70.                        // polygon mesh
  71. int offset_frames;     // offset in bytes from beginning of file to the 
  72.                        // vertex data for each frame
  73. int offset_openGLcmds; // offset in bytes from beginning of file to the 
  74.                        // openGL commands
  75. int offset_end;        // offset in bytes from beginning of file to end of file
  76. } MD2_HEADER, *MD2_HEADER_PTR; 
  77. // this is a single point for the md2 model, contains an 8-bit scaled x,y,z 
  78. // and an index for the normal to the point that is encoded as an
  79. // index into a normal table supplied by id software
  80. typedef struct MD2_POINT_TYP
  81. {
  82. unsigned char v[3];          // vertex x,y,z in compressed byte format
  83. unsigned char normal_index;  // index into normal table from id Software (unused)
  84. } MD2_POINT, *MD2_POINT_PTR; 
  85. // this is a single u,v texture
  86. typedef struct MD2_TEXTCOORD_TYP
  87. {
  88. short u,v; 
  89. } MD2_TEXTCOORD, *MD2_TEXTCOORD_PTR;
  90. // this is a single frame for the md2 format, it has a small header portion 
  91. // which describes how to scale and translate the model vertices, but then
  92. // has an array to the actual data points which is variable, so the definition
  93. // uses a single unit array to allow the compiler to address up to n with
  94. // array syntax
  95. typedef struct MD2_FRAME_TYP
  96. {
  97. float scale[3];          // x,y,z scaling factors for the frame vertices
  98. float translate[3];      // x,y,z translation factors for the frame vertices
  99. char name[16];           // ASCII name of the model, "evil death lord" etc. :)
  100. MD2_POINT vlist[1];      // beginning of vertex storage array
  101. } MD2_FRAME, *MD2_FRAME_PTR;
  102. // this is a data structure for a single md2 polygon (triangle)
  103. // it's composed of 3 vertices and 3 texture coordinates, both
  104. // indices
  105. typedef struct MD2_POLY_TYP
  106. {
  107. unsigned short vindex[3];   // vertex indices 
  108. unsigned short tindex[3];   // texture indices
  109. } MD2_POLY, *MD2_POLY_PTR;
  110. // finally, we will create a container class to hold the md2 model and help
  111. // with animation etc. later, but this model will be converted on the fly
  112. // to one of our object models each frame, once the md2 model is loaded,
  113. // is is converted to the container format and the original md2 model is 
  114. // discarded..
  115. typedef struct MD2_CONTAINER_TYP
  116. {
  117. int state;          // state of the model
  118. int attr;           // attributes of the model
  119. int color;          // base color if no texture
  120. int num_frames;     // number of frames in the model
  121. int num_polys;      // number of polygons
  122. int num_verts;      // number of vertices 
  123. int num_textcoords; // number of texture coordinates
  124. BITMAP_IMAGE_PTR  skin;   // pointer to texture skin for model
  125. MD2_POLY_PTR polys; // pointer to polygon list
  126. VECTOR3D_PTR vlist; // pointer to vertex coordinate list
  127. VECTOR2D_PTR tlist; // pointer to texture coordinate list
  128. VECTOR4D world_pos; // position of object
  129. VECTOR4D vel;       // velocity of object
  130. int   ivars[8];     // integer variables
  131. float fvars[8];     // floating point variables
  132. int counters[8];    // general counters      
  133. int anim_state;     // state of animation
  134. int anim_counter;   // general animation counter
  135. int anim_mode;      // single shot, loop, etc.
  136. int anim_speed;     // smaller number, faster animation
  137. int anim_complete;  // flags if single shot animation is done
  138. float curr_frame;     // current frame in animation 
  139. } MD2_CONTAINER, *MD2_CONTAINER_PTR; 
  140. ///////////////////////////////////////////////////////////////////////////////
  141. // holds a simple animation start-end plus interpolation rate
  142. typedef struct MD2_ANIMATION_TYP
  143. {
  144. int   start_frame;  // starting and ending frame
  145. int   end_frame;  
  146. float irate;        // interpolation rate
  147. int   anim_speed;   // animation rate 
  148. } MD2_ANIMATION, *MD2_ANIMATION_PTR;
  149. // CLASSES /////////////////////////////////////////////////////////////////
  150. // EXTERNALS ///////////////////////////////////////////////////////////////
  151. extern HWND main_window_handle; // save the window handle
  152. extern HINSTANCE main_instance; // save the instance
  153. extern MD2_ANIMATION md2_animations[NUM_MD2_ANIMATIONS];
  154. extern char *md2_anim_strings[];
  155. // MACROS //////////////////////////////////////////////////////////////////
  156. // PROTOTYPES //////////////////////////////////////////////////////////////
  157. int Load_Object_MD2(MD2_CONTAINER_PTR obj_md2, // the loaded md2 file placed in container
  158.                     char *modelfile,    // the filename of the .MD2 model
  159.                     VECTOR4D_PTR scale, // initial scaling factors
  160.                     VECTOR4D_PTR pos,   // initial position
  161.                     VECTOR4D_PTR rot,   // initial rotations
  162.                     char *texturefile,  // the texture filename for the model
  163.                     int attr,           // the lighting/model attributes for the model
  164.                     int color,          // base color if no texturing
  165.                     int vertex_flags);  // control ordering etc.
  166. int Prepare_OBJECT4DV2_For_MD2(OBJECT4DV2_PTR obj,        // pointer to destination object
  167.                                MD2_CONTAINER_PTR obj_md2); // md2 object to extract frame from
  168. int Extract_MD2_Frame(OBJECT4DV2_PTR obj,        // pointer to destination object
  169.                       MD2_CONTAINER_PTR obj_md2); // md2 object to extract frame from
  170. int Set_Animation_MD2(MD2_CONTAINER_PTR md2_obj, 
  171.                       int anim_state,
  172.                       int anim_mode);
  173. int Animate_MD2(MD2_CONTAINER_PTR md2_obj);
  174. // timer functions
  175. void Start_Fast_Timer(void);
  176. void Wait_Fast_Timer(int delay);
  177. #endif