home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / vr386 / vr_types.h < prev    next >
C/C++ Source or Header  |  1996-03-19  |  8KB  |  268 lines

  1. // redefineable REND386 types
  2. // for API, also for compiler portability
  3. // Dave Stampe, 29/12/93
  4.  
  5. /*
  6.  This code is part of the VR-386 project, created by Dave Stampe.
  7.  VR-386 is a desendent of REND386, created by Dave Stampe and
  8.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  9.  Stampre for VR-386.
  10.  
  11.  Copyright (c) 1994 by Dave Stampe:
  12.  May be freely used to write software for release into the public domain
  13.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  14.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  15.  this software or source code into their products!  Usually there is no
  16.  charge for under 50-100 items for low-cost or shareware products, and terms
  17.  are reasonable.  Any royalties are used for development, so equipment is
  18.  often acceptable payment.
  19.  
  20.  ATTRIBUTION:  If you use any part of this source code or the libraries
  21.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  22.  and any other authors in your documentation, source code, and at startup
  23.  of your program.  Let's keep the freeware ball rolling!
  24.  
  25.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  26.  REND386, improving programmer access by rewriting the code and supplying
  27.  a standard API.  If you write improvements, add new functions rather
  28.  than rewriting current functions.  This will make it possible to
  29.  include you improved code in the next API release.  YOU can help advance
  30.  VR-386.  Comments on the API are welcome.
  31.  
  32.  CONTACT: dstampe@psych.toronto.edu
  33. */
  34.  
  35.  
  36.  
  37. /// THESE TYPES ARE FOR COMPILER PORTABILITY
  38.  
  39. typedef unsigned char BYTE;   // types for compiler portability
  40. typedef unsigned int WORD;
  41. typedef signed char SBYTE;
  42. typedef signed int SWORD;
  43. typedef long DWORD;
  44.  
  45. typedef signed char BOOL;
  46. #define TRUE  1
  47. #define FALSE 0
  48.  
  49. typedef DWORD COORD;     // <32.0>  for position
  50. typedef DWORD ANGLE;     // <16.16> for angle
  51. typedef DWORD MATVAL;    // <3.29> for trig
  52. typedef DWORD SCALE;     // <16.16> for scaling
  53.  
  54.  
  55. //// THESE TYPES ARE ALSO IN 3DSTRUCT.H WHICH MAY BE INCLUDED FOR DEBUGGING
  56.  
  57. #ifndef SCRIDEF
  58. #define SCRIDEF 1
  59. struct Screeninfo {
  60.     WORD xmin, ymin, xmax, ymax, xcent, ycent, colors, pages, bw;
  61.     SCALE aspect;
  62.     char id[80];
  63.     };
  64. #endif
  65.  
  66. #ifndef MATRIXDEF
  67. typedef MATVAL MATRIX[4][3];  /* 3x3 rotate plus 3 translate para's */
  68. #define MATRIXDEF 1           /* rotate matrix is <3.29>, translate is <32.0> */
  69. #endif
  70.  
  71.  
  72. #ifndef VIEWDEF
  73. #define VIEWDEF 1
  74. typedef struct {
  75.     SCALE zoom;              /* <16.16> 1/tan(H FOV/2) 0.5 to 16     */
  76.  
  77.     DWORD left,right;        /* <25.0> clipping planes */
  78.     DWORD top, bottom;
  79.     DWORD hither, yon;       /* <25.0> near and far clipping planes   */
  80.     SCALE aspect;            /* <16.16> x:y fixup factor (magnify Y by...) */
  81.  
  82.     WORD flags;         /* 16 bits of flags */
  83.  
  84.     DWORD x_offset, y_offset;   /* amount to move screen center in pixels */
  85.     WORD  orientation;      /* used to mirror screen image */
  86. #define NOFLIP 0x0000      /* bits used in orientation field */
  87. #define XFLIP  0x0001
  88. #define YFLIP  0x0002
  89.  
  90.     MATRIX eye_xform;
  91.  
  92.     DWORD spare[17];   // PRIVATE view data caching
  93.     } VIEW;
  94. #endif
  95.  
  96. #ifndef POLYDEF
  97. #define POLYDEF 1
  98. typedef void POLY;
  99. #endif
  100.  
  101. #ifndef REPDEF
  102. #define REPDEF 1
  103. typedef void REP;
  104. #endif
  105.  
  106. #ifndef OBJDEF
  107. #define OBJDEF 1
  108. typedef WORD *OBJECT;    // for now (generic name for SEGMENT and OBJECT)
  109.             // this just accesses the flags field for type checks
  110. typedef void *VISOBJ;    // special case of OBJECT
  111. #endif
  112.  
  113. #ifndef OBJLDEF
  114. #define OBJLDEF 1
  115. typedef void *OBJLIST;
  116. #endif
  117.  
  118. #ifndef SEGDEF
  119. #define SEGDEF 1
  120. typedef void SEGMENT;
  121. #endif
  122.  
  123. #ifndef SPLDEF
  124. #define SPLDEF 1
  125. typedef void SPLIT;
  126. #endif
  127.  
  128. /// THESE ARE TYPE-CONVERSION MACROS
  129.  
  130. #define XFFP 536870912.0
  131.  
  132. #define float2coord(p)  ((COORD)p)
  133. #define coord2float(p)  ((float)p)
  134. #define float2scale(p)  ((SCALE)(p*65536.0))
  135. #define scale2float(p)  (p/65536.0)
  136. #define float2angle(p)  ((ANGLE)(p*65536.0))
  137. #define angle2float(p)  (p/65536.0)
  138. #define float2matval(p) ((MATVAL)(p*XFFP))
  139. #define matval2float(p) (p/XFFP)
  140.  
  141.  
  142. /// THESE TYPES ARE FOR API AND INTERNAL USE
  143.  
  144. typedef unsigned SURFACE;    // surface type: may be long later
  145. typedef struct     {               // pair for surface remapping
  146.         SURFACE old;
  147.         SURFACE new;
  148.         } SURFACEPAIR;
  149.  
  150. typedef struct { COORD x, y, z; } POINT3D;  // 3D point
  151. typedef struct { ANGLE rx, ry, rz; } ROT3D;  // 3D rotation
  152.  
  153. #define DONTCARE 0x80000000L  // when used, does not affect old value
  154.  
  155. // pose: used to set/return object etc. pose (position and angle)
  156.  
  157. typedef struct  { COORD x,y,z;  ANGLE rx,ry,rz; } POSE;
  158.  
  159. // example of use:
  160. // POSE p = DONTCARE_POSE;
  161.  
  162. #define DONTCARE_POSE { DONTCARE,DONTCARE,DONTCARE,DONTCARE,DONTCARE,DONTCARE }
  163. #define ZERO_POSE { 0,0,0,0,0,0 }
  164.  
  165. typedef struct  {               // light source
  166.           void *seg;
  167.           unsigned type;
  168.           unsigned intensity;
  169.         } LIGHT;
  170.  
  171. #define AMBIENT_LIGHT 0   // types of lights
  172. #define POINT_LIGHT   1   // a "positioned" light: only light location used
  173. #define SPOT_LIGHT    2      // an "angled" light: only LIGHT angle used
  174.  
  175.     // a stereo view window: two in each STEREO
  176. typedef struct {
  177.           WORD  l,t,r,b;    // the window bounds
  178.           ANGLE rx,ry,rz;       // rotations of window
  179.           SWORD xoff, yoff;    // offset of window
  180.           WORD    orientation;    // mirroring of window
  181.           MATRIX mat;
  182.            } STWINDOW;
  183.  
  184.  
  185. typedef struct {       /* stereoscopic view factors */
  186.     DWORD phys_screen_dist;  /* eye-to-screen distance (mm); keep < 32000  */
  187.     DWORD phys_screen_width; /* viewport width on screen (mm)              */
  188.     DWORD pixel_width;       /* width of viewport in pixels                */
  189.     DWORD phys_eye_spacing;  /* spacing of eyes (mm) [usually 63]          */
  190.     DWORD phys_convergence;  /* convergence dist. (usually screen) (mm)    */
  191.     SCALE world_scaling;     /* world units per physical mm                */
  192.     STWINDOW window[2];    /* the windows for display               */
  193.     } STEREO ;
  194.  
  195. #define MONOSCOPIC 0         /* stereo types */
  196. #define SWITCHED   1
  197. #define SPLITLR    3
  198. #define SEPARATE   5
  199.  
  200. #define LEFT_EYE   0
  201. #define RIGHT_EYE  1
  202.  
  203. typedef struct {
  204.           VIEW *mono;        // central/mono view
  205.           VIEW *left;           // left eye view
  206.           VIEW *right;          // right eye view
  207.           BOOL is_stereo;       // stereo view?
  208.           STEREO *stereo;       // data to create stereo views
  209.           SEGMENT *seg;        // segment to move camera
  210.         } CAMERA;
  211.  
  212.  
  213. typedef struct { BYTE r, g, b; } RGBCOLOR;  // RGB color
  214.  
  215. #define structtype(p) (*((WORD *)(p))    // retrives structure type label
  216.  
  217. //other uses of flags: for segments and object:
  218.  
  219. #define IS_VISOBJ     0x8000
  220. #define IS_SEGMENT    0x0080
  221. #define IS_MOVEABLE   0x0010
  222.  
  223. #define SYSTEM_OWNED  0x0040    // segment flags
  224. #define HAS_OBJECT    0x0020
  225. #define SEG_MODIFIED  1
  226.  
  227. typedef struct {                          // more later
  228.         CAMERA  *current_camera;
  229.         POSE    initial_body_pose;
  230.         POSE    *body_pose;
  231.         POSE    *home_pose;
  232.         SPLIT   *world_root;
  233.         OBJLIST *inactive_objects;
  234.            } WORLD;
  235.  
  236. typedef struct {
  237.         POSE current_pose;
  238.         OBJECT *vehicle;
  239.         char * vehicle_name;    // in case reloading needed
  240.         WORLD *world;
  241.            } TELEPORT;
  242.  
  243.  
  244. // memory alloc/dealloc lists: not yet tested
  245.  
  246. #ifndef DEFMB
  247. struct _mb_ {
  248.           struct _mb_ *prev;    // header of memory
  249.           struct _mb_ *next;
  250.       } ;
  251.  
  252. typedef struct _mb_ MEMBLOCK;
  253.  
  254. typedef struct {                    // head of memory list
  255.          MEMBLOCK *prev;    // USUALLY STATIC MEMORY
  256.          MEMBLOCK *next;
  257.            } MEMLIST;
  258. #endif
  259. #define DEFMB 1
  260.  
  261. #define INIT_MEMLIST { NULL,NULL }    // store in new memlist header
  262. // example:
  263. // MEMLIST env_memlist = INIT_MEMLIST;
  264.  
  265. #define ptr2memblock(p) MK_FP(FP_SEG(p),FP_OFF(p)-(2*sizeof(MEMBLOCK *)))
  266. #define memblock2ptr(p) MK_FP(FP_SEG(p),FP_OFF(p)+(2*sizeof(MEMBLOCK *)))
  267.  
  268.