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

游戏

开发平台:

Visual C++

  1. // T3DLIB11.H - header file for T3DLIB11.H
  2. // watch for multiple inclusions
  3. #ifndef T3DLIB11
  4. #define T3DLIB11
  5. // DEFINES //////////////////////////////////////////////////////////////////
  6. // new rendering context defines
  7. // use a Z buffer, but with write thru, no compare
  8. #define RENDER_ATTR_WRITETHRUZBUFFER   0x00000008  
  9. #define WALL_SPLIT_ID                  4096   // used to tag walls that are split
  10. // defines for BHV system
  11. #define MAX_OBJECTS_PER_BHV_CELL    64   // maximum objects that will fit in one BHV cell
  12.                                          // note: this is DIFFERENT than a node
  13. #define MIN_OBJECTS_PER_BHV_CELL    2    // recursion stops if a cell has less that this 
  14.                                          // number of objects
  15. #define MAX_BHV_CELL_DIVISIONS      8    // maximum number of cells in one axis that
  16.                                          // space can be divided into 
  17. #define MAX_OBJECTS_PER_BHV_NODE    512  // maximum objects a node can handle
  18. #define MAX_BHV_PER_NODE            32   // maximum children per node
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // TYPES ///////////////////////////////////////////////////////////////////
  21. // a self contained quad polygon used for the render list version 2 //////
  22. // we need this to represent the walls since they are quads
  23. typedef struct POLYF4DV2Q_TYP
  24. {
  25. int      state;           // state information
  26. int      attr;            // physical attributes of polygon
  27. int      color;           // color of polygon
  28. int      lit_color[4];    // holds colors after lighting, 0 for flat shading
  29.                           // 0,1,2 for vertex colors after vertex lighting
  30. BITMAP_IMAGE_PTR texture; // pointer to the texture information for simple texture mapping
  31. int      mati;          // material index (-1) for no material
  32. float    nlength;       // length of the polygon normal if not normalized 
  33. VECTOR4D normal;        // the general polygon normal
  34. float    avg_z;         // average z of vertices, used for simple sorting
  35. VERTEX4DTV1 vlist[4];   // the vertices of this quad
  36. VERTEX4DTV1 tvlist[4];  // the vertices after transformation if needed 
  37. POLYF4DV2Q_TYP *next;   // pointer to next polygon in list??
  38. POLYF4DV2Q_TYP *prev;   // pointer to previous polygon in list??
  39. } POLYF4DV2Q, *POLYF4DV2Q_PTR;
  40. // a general bsp node, all bsp trees are built from this
  41. // struct, and the root of a bsp is also this struct
  42. typedef struct BSPNODEV1_TYP
  43. {
  44. int        id;     // id tage for debugging
  45. POLYF4DV2Q  wall;  // the actual wall quad
  46. struct BSPNODEV1_TYP *link;  // pointer to next wall
  47. struct BSPNODEV1_TYP *front; // pointer to walls in front
  48. struct BSPNODEV1_TYP *back;  // pointer to walls behind
  49. } BSPNODEV1, *BSPNODEV1_PTR;
  50. // object container to hold any object
  51. typedef struct OBJ_CONTAINERV1_TYP
  52.         {
  53.         int state;          // state of container object
  54.         int attr;           // attributes of container object
  55.         POINT4D pos;        // position of container object
  56.         VECTOR4D vel;       // velocity of object container
  57.         VECTOR4D rot;       // rotational rate of object container
  58.         int auxi[8];        // aux array of 8 ints
  59.         int auxf[8];        // aux array of 8 floats
  60.         void *aux_ptr;      // aux pointer
  61.         void *obj;          // pointer to master object
  62.         } OBJ_CONTAINERV1, *OBJ_CONTAINERV1_PTR;
  63. // a bounding heirarchical volume node
  64. typedef struct BHV_NODEV1_TYP
  65.         {
  66.         int state;         // state of this node
  67.         int attr;          // attributes of this node
  68.         POINT4D pos;       // center of node
  69.         VECTOR4D radius;   // x,y,z radius of node
  70.         int num_objects;   // number of objects contained in node
  71.         OBJ_CONTAINERV1 *objects[MAX_OBJECTS_PER_BHV_NODE]; // objects
  72.         int num_children;  // number of children nodes
  73.         BHV_NODEV1_TYP *links[MAX_BHV_PER_NODE]; // links to children
  74.         } BHV_NODEV1, *BHV_NODEV1_PTR;
  75. // internally used for the 3D array sorting algorithm
  76. typedef struct BHV_CELL_TYP
  77. {
  78. int num_objects;                                     // number of objects in this cell
  79. OBJ_CONTAINERV1 *obj_list[MAX_OBJECTS_PER_BHV_CELL]; // storage for object pointers
  80. } BHV_CELL, *BHV_CELL_PTR;
  81. // CLASSES /////////////////////////////////////////////////////////////////
  82. // M A C R O S ///////////////////////////////////////////////////////////////
  83. // tests if two 3-d points are equal
  84. #define VECTOR4D_Equal(v1,v2) (FCMP((v1)->x,(v2)->x) && FCMP((v1)->y,(v2)->y) && FCMP((v1)->z,(v2)->z))
  85. #define VECTOR3D_Equal(v1,v2) (FCMP((v1)->x,(v2)->x) && FCMP((v1)->y,(v2)->y) && FCMP((v1)->z,(v2)->z))
  86. // this macro assumes the lookup has 360 elements, where
  87. // each element is in .5 degree increments roughly
  88. // x must be in the range [-1,1]
  89. #define FAST_INV_COS(x) (dp_inverse_cos[(int)(((float)x+1)*(float)180)])
  90. // EXTERNALS ///////////////////////////////////////////////////////////////
  91. extern HWND main_window_handle; // save the window handle
  92. extern HINSTANCE main_instance; // save the instance
  93. // dot product look up table
  94. extern float dp_inverse_cos[360+2]; // 0 to 180 in .5 degree steps
  95.                                     // the +2 for padding
  96. extern int bhv_nodes_visited;       // used to track how many nodes where visited
  97. // MACROS ////////////////////////////////////////////////
  98. // PROTOTYPES //////////////////////////////////////////////////////////////
  99. void Build_Inverse_Cos_Table(float *invcos,      // storage for table
  100.                              int   range_scale); // range for table to span
  101.                              
  102. void Draw_RENDERLIST4DV2_RENDERCONTEXTV1_16_2(RENDERCONTEXTV1_PTR rc);
  103. void Draw_Gouraud_TriangleWTZB2_16(POLYF4DV2_PTR face,  // ptr to face
  104.                               UCHAR *_dest_buffer,      // pointer to video buffer
  105.                               int mem_pitch,            // bytes per line, 320, 640 etc.
  106.                               UCHAR *_zbuffer,          // pointer to z-buffer
  107.                               int zpitch);              // bytes per line of zbuffer
  108. void Draw_Triangle_2DWTZB_16(POLYF4DV2_PTR face,        // ptr to face
  109.                            UCHAR *_dest_buffer,         // pointer to video buffer
  110.                            int mem_pitch,               // bytes per line, 320, 640 etc.
  111.                            UCHAR *_zbuffer,             // pointer to z-buffer
  112.                            int zpitch);                 // bytes per line of zbuffer
  113. void Draw_Textured_TriangleGSWTZB_16(POLYF4DV2_PTR face, // ptr to face
  114.                                  UCHAR *_dest_buffer,    // pointer to video buffer
  115.                                  int mem_pitch,          // bytes per line, 320, 640 etc.
  116.                                  UCHAR *_zbuffer,        // pointer to z-buffer
  117.                                  int zpitch);            // bytes per line of zbuffer
  118. void Draw_Textured_TriangleFSWTZB2_16(POLYF4DV2_PTR face, // ptr to face
  119.                                  UCHAR *_dest_buffer,     // pointer to video buffer
  120.                                  int mem_pitch,           // bytes per line, 320, 640 etc.
  121.                                  UCHAR *_zbuffer,         // pointer to z-buffer
  122.                                  int zpitch);             // bytes per line of zbuffer
  123. void Draw_Textured_TriangleWTZB2_16(POLYF4DV2_PTR face,  // ptr to face
  124.                               UCHAR *_dest_buffer,       // pointer to video buffer
  125.                               int mem_pitch,             // bytes per line, 320, 640 etc.
  126.                               UCHAR *_zbuffer,           // pointer to z-buffer
  127.                               int zpitch);               // bytes per line of zbuffer
  128. // BSP PROTOTYPES///////////////////////////////////////////////////////
  129. void Bsp_Translate(BSPNODEV1_PTR root, VECTOR4D_PTR trans);
  130. void Bsp_Delete(BSPNODEV1_PTR root);
  131. void Bsp_Print(BSPNODEV1_PTR root);
  132. void Bsp_Build_Tree(BSPNODEV1_PTR root);
  133. void Bsp_Transform(BSPNODEV1_PTR root,  // root of bsp tree
  134.                    MATRIX4X4_PTR mt,    // transformation matrix
  135.                    int coord_select);   // selects coords to transform)
  136. void Intersect_Lines(float x0,float y0,float x1,float y1,
  137.                      float x2,float y2,float x3,float y3,
  138.                      float *xi,float *yi);
  139. void Bsp_Insertion_Traversal_RENDERLIST4DV2(RENDERLIST4DV2_PTR rend_list, 
  140.                                             BSPNODEV1_PTR root,
  141.                                             CAM4DV1_PTR cam,
  142.                                             int insert_local);
  143. void Bsp_Insertion_Traversal_RemoveBF_RENDERLIST4DV2(RENDERLIST4DV2_PTR rend_list, 
  144.                                                              BSPNODEV1_PTR root,
  145.                                                              CAM4DV1_PTR cam,
  146.                                                              int insert_local);
  147. void Bsp_Insertion_Traversal_FrustrumCull_RENDERLIST4DV2(RENDERLIST4DV2_PTR rend_list, 
  148.                                                          BSPNODEV1_PTR root,
  149.                                                          CAM4DV1_PTR cam,
  150.                                                          int insert_local);
  151. // BHV prototypes //////////////////////////////////////////////////////////
  152. void BHV_Build_Tree(BHV_NODEV1_PTR bhv_tree,         // tree to build
  153.                     OBJ_CONTAINERV1_PTR bhv_objects, // ptr to all objects in intial scene
  154.                     int num_objects,                 // number of objects in initial scene
  155.                     int level,                       // recursion level
  156.                     int num_divisions,               // number of division per level
  157.                     int universe_radius);            // initial size of universe to enclose
  158. int BHV_FrustrumCull(BHV_NODEV1_PTR bhv_tree, // the root of the BHV  
  159.                      CAM4DV1_PTR cam,         // camera to cull relative to
  160.                      int cull_flags);         // clipping planes to consider
  161. void BHV_Reset_Tree(BHV_NODEV1_PTR bhv_tree);
  162. #endif