home *** CD-ROM | disk | FTP | other *** search
/ Game Developers Magazine 3 / GDM003.ZIP / I3DKIT.H < prev    next >
C/C++ Source or Header  |  1993-08-04  |  6KB  |  182 lines

  1. //***************************************************************************
  2. //*                                                                         *
  3. //* Interactive 3D Kit                                                      *
  4. //*                                                                         *
  5. //* I3D API                                                                 *
  6. //*                                                                         *
  7. //* (c) 1993 Jim O'Keane                                                    *
  8. //* All Rights Reserved Worldwide                                           *
  9. //*                                                                         *
  10. //***************************************************************************
  11.  
  12. #ifndef _I3DKIT_H
  13.  
  14. #define _I3DKIT_H 1
  15.  
  16. // Simple macros to facilitate global vars in .h files
  17. // Define MAIN in only one file before #includes.
  18. #ifndef MAIN
  19. #define GLOBAL extern
  20. #else
  21. #define GLOBAL
  22. #endif
  23.  
  24. // MS Windows-like types
  25. #ifndef TRUE
  26. typedef unsigned char     BYTE;
  27. typedef unsigned short    WORD;
  28. typedef unsigned long     DWORD;
  29. typedef short            BOOL;
  30. #define FALSE            0
  31. #define TRUE            1
  32. #endif
  33.  
  34. #ifndef FAR
  35. #define FAR far
  36. #endif
  37.  
  38. #ifndef PASCAL
  39. #define PASCAL pascal
  40. #endif
  41.  
  42. #ifdef __FLAT__
  43. // If 32 bit compiler, dump the "far" and the "pascal"
  44.  
  45. #undef  FAR
  46. #define FAR  
  47.  
  48. #undef  PASCAL
  49. #define PASCAL
  50.  
  51. #endif
  52.  
  53. // pointer to the 3D Window buffer, alloc'd by your code
  54. GLOBAL BYTE FAR *winBuf;
  55.  
  56. // Maps are always 128 by 128 blocks. (128 x 128 x 2 = 32K Bytes)
  57. // If you need a smaller map, just don't use whole array.
  58. // The map contains indexes into the block definition array.
  59. #define MAP_WIDTH  128
  60. #define MAP_HEIGHT 128
  61.  
  62. // Map array type
  63. typedef short MAPTYPE[MAP_WIDTH][MAP_HEIGHT];
  64.  
  65. // size of map blocks (high byte of coords is map coord)
  66. #define BLOCK_SIZE     256
  67. // mask is used to find position inside a block
  68. #define BLOCK_MASK     255
  69. // shift is used to find the map coords
  70. #define BLOCK_SHIFT    8
  71.  
  72.  
  73. // Block shape types 
  74. #define BLOCK_EMPTY    0  // block is empty (just floor & ceiling)
  75. #define BLOCK_CUBE     1  // block is a cube
  76. #define BLOCK_HORZ     2  // block is a horizontal (EW) divider
  77. #define BLOCK_VERT     3  // block is a vertical (NS) divider
  78. #define BLOCK_ACTOR    4  // block is an actor or prop (a thing)
  79.  
  80. // Bit flags
  81. #define BLOCK_TRANS    1   // block is transparent
  82. #define BLOCK_WALL     2   // block is an impassable
  83.  
  84. // definition of a block
  85. typedef struct tag_block
  86. {
  87.   short ns_wall;   // wall panel to show (-1 = none)
  88.   short ew_wall;   // wall panel to show (-1 = none)
  89.   short ceil;      // ceiling panel to show
  90.   short floor;     // floor panel to show
  91.   short shape;     // type of shape
  92.   short flags;     // bit flags
  93.   short x_offset;  // positional offset (+/- 1/2 BLOCK_SIZE)
  94.   short y_offset;  // used to animate blocks and things
  95.   short user1;
  96.   short user2;     // free for user defined uses
  97.   short user3;
  98.   short user4;
  99. } BLOCK;
  100.  
  101. // if a block is an actor or prop, cast the block struct to this:
  102. typedef struct tag_thing 
  103. {
  104.   short panel;     // base panel to show (-1 = none)
  105.   short block;     // what background block is at this location
  106.   short views;     // how many directions give different views?
  107.   short heading;   // direction facing
  108.   short shape;     // type of shape
  109.   short flags;     // bit flags
  110.   short x_offset;  // positional offset +/- 1/2 BLOCK_SIZE
  111.   short y_offset;  // used to animate blocks and things
  112.   short user1;
  113.   short user2;     // free for user defined uses
  114.   short user3;
  115.   short user4;
  116. } THING;
  117.  
  118. // standard image operator macros
  119. #define IMAGE_SIZE256(w,h) ((unsigned short)((long)(w)*(h)))
  120. #define PIXPOS(x,y,w) (((y)*(w))+(x))
  121.  
  122. // handy macros
  123. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  124. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  125. #define SIGN(x)  (((x) < 0) ? -1 : (((x) > 0) ? 1 : 0))
  126. #define ABS(x) ((x)<0 ? -(x):(x))
  127.  
  128. // Prototypes ////////////////////////////////////////////////////
  129.  
  130. // Quicky integer math functions. High speed, low accuracy.
  131. short FAR q_sin( short angle );
  132. short FAR q_cos( short angle );
  133. void  FAR rotate(short *x, short *y, short cx, short cy, short angle);
  134.  
  135. // I3D functions ////////////////////////////
  136.  
  137. // Tell the I3D engine what map to use. I3D keeps a copy of
  138. // this pointer, so you can change the map on the fly.
  139.  
  140. BOOL  FAR i3d_set_map(MAPTYPE FAR *map_ptr);
  141.  
  142. // Tell the I3D engine about the texture map panels. I3D keeps a copy of
  143. // the pointer to the panel list, so you can change the texture maps on
  144. // the fly.
  145.  
  146. BOOL  FAR i3d_set_panels(short num_panels, BYTE FAR **panel_list,
  147.                          short size,short shift);
  148.  
  149. // Tell the I3D engine about you block definition list. I3D keeps a copy
  150. // of the pointer to the block list, so you can change the block definitions
  151. // on the fly.
  152.                       
  153. BOOL  FAR i3d_set_blocks(short num_blocks, BLOCK FAR *block_list);
  154.  
  155. // Tell the I3D engine to use a solid color for floors and ceilings. If set
  156. // to zero, uses texture mapped floors and ceilings. 
  157.  
  158. BOOL  FAR i3d_set_floor_ceil(short floor_col, short ceil_col);
  159.  
  160. // Tell the I3D engine the dimensions of the window buffer it uses, and
  161. // the width of a line in bytes.
  162.  
  163. BOOL  FAR i3d_set_window_buffer(short width, short height,
  164.                                 short line_width, BOOL invert,
  165.                                 short scale, BYTE FAR *buf);
  166.  
  167. // Ask I3D to create a frame in the window buffer.
  168.  
  169. void FAR i3d_view_scan256(short viewer_x, short viewer_y,
  170.                           short eye_angle,
  171.                           short viewer_heading);
  172.  
  173. // Ask I3D to tell you what is hit at a particular point in the window buffer.
  174.  
  175. void FAR i3d_hit_scan256(short viewer_x, short viewer_y,
  176.                          short eye_angle,
  177.                          short viewer_heading,
  178.                          short click_x, short click_y,
  179.                          short FAR *h_x, short FAR *h_y, short FAR *h_z,
  180.                          short FAR *block_id, short FAR *panel_u, short FAR *panel_v);
  181. #endif
  182.