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

  1. /* Definition for a generic 3-D pointing device interface */
  2. // This file before vr_api.h in files that create new pointer drivers
  3.  
  4. /* Written by Dave Stampe Aug. 92 */
  5.  
  6.  
  7. // pointers are a generic device interface, designed so YOUR
  8. // pointer code can be very simple.  Scaling, transforms and
  9. // so on are all done in REND386.
  10.  
  11.  
  12. /*
  13.  This code is part of the VR-386 project, created by Dave Stampe.
  14.  VR-386 is a desendent of REND386, created by Dave Stampe and
  15.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  16.  Stampre for VR-386.
  17.  
  18.  Copyright (c) 1994 by Dave Stampe:
  19.  May be freely used to write software for release into the public domain
  20.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  21.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  22.  this software or source code into their products!  Usually there is no
  23.  charge for under 50-100 items for low-cost or shareware products, and terms
  24.  are reasonable.  Any royalties are used for development, so equipment is
  25.  often acceptable payment.
  26.  
  27.  ATTRIBUTION:  If you use any part of this source code or the libraries
  28.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  29.  and any other authors in your documentation, source code, and at startup
  30.  of your program.  Let's keep the freeware ball rolling!
  31.  
  32.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  33.  REND386, improving programmer access by rewriting the code and supplying
  34.  a standard API.  If you write improvements, add new functions rather
  35.  than rewriting current functions.  This will make it possible to
  36.  include you improved code in the next API release.  YOU can help advance
  37.  VR-386.  Comments on the API are welcome.
  38.  
  39.  CONTACT: dstampe@psych.toronto.edu
  40. */
  41.  
  42.  
  43. #include "vr_ctypes.h"
  44.  
  45. #define PTRDEF 1
  46. #define PTRBDEF 1
  47.  
  48. /* configuration structure: part of driver */
  49. /* MUST corresp. to lefthand coord sys or negate scale! */
  50. /* for non- ht devices, the scaling may be adjusted as desired */
  51.  
  52.  typedef struct _pconfig {
  53.     long xres, yres, zres;     /* position res: mm/tick in <16.16>  */
  54.     long maxx, maxy, maxz;     /* numeric range             */
  55.     long minx, miny, minz;
  56.  
  57.     long xrres, yrres, zrres;  /* rotation res: deg/tick in <16.16  */
  58.     long maxxr, maxyr, maxzr;  /* numeric range                */
  59.     long minxr, minyr, minzr;  /* min, max: left-hand dir.     */
  60.  
  61.     int maxsx, maxsy;    /* limits on mouse-mode motion (writable) */
  62.  
  63.     int databits;     /* what data is available from device */
  64.     int commands;     /* what sort of control is available  */
  65.     int nullkey;      /* button code for null keypress      */
  66.     int flexnum;      /* number of flex parameters          */
  67.     int delay;        /* millisec. read delay               */
  68.     int idelay;       /* internal delay in ms               */
  69.     int rrate;        /* max. reads per second possible     */
  70.     int type;         /* suggested useage                   */
  71.     char id[80];      /* id or more data                    */
  72.     } pconfig;
  73.  
  74. /* databits: */
  75.  
  76. #define P_HASB1    0x0001   /* what buttons we can have  */
  77. #define P_HASB2    0x0002   /* also mask for button bits */
  78. #define P_HASB3    0x0004
  79. #define P_HASX     0x0008   /* which axes we can read */
  80. #define P_HASY     0x0010
  81. #define P_HASZ     0x0020
  82. #define P_HASRX    0x0040   /* what rotations are available */
  83. #define P_HASRY    0x0080
  84. #define P_HASRZ    0x0100
  85. #define P_HASGEST  0x0200   /* gestural interface   */
  86. #define P_HASFLEX  0x0400   /* fingers?             */
  87. #define P_HASKEYS  0x0800   /* do we have a keypad? */
  88. #define P_HASSCR   0x1000   /* capable of emulating XY mouse */
  89.  
  90.  
  91. /* commands to driver (modes): */
  92.  
  93. #define P_CENTER    1   /* recenter without reinitializing */
  94. #define P_SCREEN    2   /* screen mouse mode read     */
  95. #define P_POINTER   4   /* any extended pointing mode */
  96.  
  97. /* type: bits specifying suggested uses */
  98.  
  99. #define P_NOPOS 0   /* just a keypad or something */
  100. #define P_IS2D  1   /* 2D mouse, for example      */
  101. #define P_IS2DP 2   /* 2D, but Z mapped by button */
  102. #define P_IS3D  4   /* 3D mouse, for example      */
  103. #define P_IS6D  8   /* 6D mouse, for example      */
  104. #define P_IS3DG 16  /* 3D glove-- don't use rot   */
  105. #define P_IS6DG 32  /* 6D glove-- use rotation    */
  106. #define P_IS3RH 64  /* 3D (rotation) head tracker */
  107. #define P_IS3TH 128 /* 3D (position) head tracker */
  108. #define P_IS6H  256 /* full 6D head tracker       */
  109.  
  110. /* driver interface packet */
  111.  
  112. typedef struct _pt{
  113.     long x, y, z;          /* location in scaled coordinates     */
  114.     long dx, dy, dz;       /* position change from last read     */
  115.     long rx, ry, rz;       /* scaled orientation around x, y, z  */
  116.     long drx, dry, drz;    /* orientation change from last read  */
  117.     unsigned buttons;      /* 16 bits: raw mouse buttons         */
  118.     unsigned gesture;      /* glove gesture ID, or a mapping     */
  119.     unsigned keys;         /* keypad return value                */
  120.     int flex[16];          /* 16 words of flexion (i.e. fingers) */
  121.     int changed;
  122.     int wpos_valid;        /* set if world pos'n is valid        */
  123.     MATRIX wpos;           /* world position/rotation            */
  124.     } POINTER;
  125.  
  126. typedef struct _pb {
  127.      int   driver_type;            /* 0 = driver, 1 = internal */
  128.      pconfig *(*driver_pointer)(); /* address of driver entry  */
  129.      pconfig *pdata;
  130.      long xmult, ymult, zmult;    /* used to process reads    */
  131.      long xadd, yadd, zadd;
  132.      long xrmult, yrmult, zrmult;
  133.      long xradd, yradd, zradd;
  134.      int oldsx, oldsy;             /* mouse emulation */
  135.      POINTER oldp;
  136.      } pdrblock;
  137.  
  138.  
  139. typedef pdrblock PDRIVER ; /* points to driver data block */
  140.  
  141.                 /* loads driver, initializes   */
  142.                 /* return NULL if failure      */
  143.                 /* drfile is NULL for internal */
  144.                 /* type gives preferred mode   */
  145. extern PDRIVER *pointer_init(int type, char *drfile);
  146.  
  147.                 /* makes sure device is available, OK */
  148.                 /* returns *pconfig or NULL           */
  149. extern pconfig *pointer_check(PDRIVER *p);
  150.  
  151.                 /* reads pointer, scales data and        */
  152.                 /* returns bitwise OR of the following:  */
  153. extern int pointer_read(PDRIVER *p, POINTER *pointer);
  154.  
  155. #define PNEW_POS  1   /* raw xyz change           */
  156. #define PNEW_ROT  2   /* raw rot. change          */
  157. #define PNEW_BUT  4   /* button pressed/released  */
  158. #define PNEW_GEST 8   /* gesture change           */
  159. #define PNEW_KEY  16  /* new key pressed/released */
  160. #define PNEW_FLEX 32  /* new flexion              */
  161.  
  162.             /* recenters, recalibrates, etc */
  163. extern void pointer_reset(PDRIVER *p);
  164.  
  165.             /* disconnects driver */
  166. extern void pointer_quit(PDRIVER *p);
  167.  
  168.             /* changes device mode */
  169. extern pconfig *device_command(PDRIVER *p, int command);
  170.  
  171.             /* sets scaling (+/- given value) */
  172.  
  173. extern void pointer_tscale(PDRIVER *p, long x, long y, long z);
  174. extern void pointer_rscale(PDRIVER *p, long rx, long ry, long rz);
  175.  
  176.  
  177. extern void pointer_abscale(PDRIVER *p, long xs, long ys, long zs,
  178.     long rxs, long rys, long rzs);
  179.  
  180.             /* uses internal tick-resolution scaling for abs. devices */
  181. extern void init_pointer(POINTER *p); /* presets pointer structure */
  182.  
  183. extern int last_pointer(PDRIVER *d,POINTER *p); /* copy of last read value */
  184.  
  185.              /* mouse-emulation read: return change flags for button, pos'n */
  186. extern int mouse_read(PDRIVER *p, int *x, int *y, unsigned *b);
  187.  
  188.              /* mouse-emulation get last data: return change flags for button, pos'n */
  189. extern int mouse_last(PDRIVER *p, int *x, int *y, int *b);
  190.  
  191. extern void set_mouse_limits(PDRIVER *p, int maxx, int maxy);
  192.  
  193. /* driver call equates: call *driver_pointer with this code */
  194. /* all return *pconfig or integer */
  195.  
  196. #define DRIVER_INIT  0   /* rtns *pconfig, args = type    */
  197. #define DRIVER_RESET 1   /* no rtn, no args               */
  198. #define DRIVER_READ  2   /* rtns NULL if no data ready, else *pconfig */
  199.                         /* args = *pointer, mode */
  200. #define DRIVER_CMD   3   /* args = mode, rtns *pconfig    */
  201. #define DRIVER_CHECK 4   /* no args, rtns *pconfig        */
  202. #define DRIVER_QUIT  5   /* no args, no rtn               */
  203.  
  204. extern PDRIVER *mouseptr_init(char *name);
  205.  
  206.  
  207. #define SW_INIT        0        // commands to switch ptr driver
  208. #define SW_QUIT        1
  209. #define SW_ADV_SWITCH  2
  210. #define SW_SYNC_SWITCH 3
  211.  
  212. static void sdriver_quit();            // shutdown switch driver
  213.  
  214.   // setup whatever switch driver used, internal if "SEGA"
  215.   // starts frame timer lock: set rate previously with init_timer
  216.   // to give it a speed hint FOR THE INTERRUPT RATE
  217. void init_switch_driver(char *sdname);
  218.  
  219. /* End of pointer.h */
  220.  
  221.