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

  1. /* Keyboard routines and menus for VRC release */
  2.  
  3. /* Original simple keyboard was written by Bernie Roehl, July 1992 */
  4.  
  5. // MASSIVELY rewritten, along with entire menu and navigation
  6. // system, by Dave Stampe for Release 5 (VRC), Nov. 92.
  7.  
  8. // some changes made to support horizon and key monitor, 12/24/93
  9.  
  10. // Completely rearranged, substantial mods, ported to VR-386 API 9/1/94
  11.  
  12.  
  13. // THIS IS A TINY VERSION FOR MINI DEMO
  14.  
  15. /*
  16.  This code is part of the VR-386 project, created by Dave Stampe.
  17.  VR-386 is a desendent of REND386, created by Dave Stampe and
  18.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  19.  Stampre for VR-386.
  20.  
  21.  Copyright (c) 1994 by Dave Stampe:
  22.  May be freely used to write software for release into the public domain
  23.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  24.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  25.  this software or source code into their products!  Usually there is no
  26.  charge for under 50-100 items for low-cost or shareware products, and terms
  27.  are reasonable.  Any royalties are used for development, so equipment is
  28.  often acceptable payment.
  29.  
  30.  ATTRIBUTION:  If you use any part of this source code or the libraries
  31.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  32.  and any other authors in your documentation, source code, and at startup
  33.  of your program.  Let's keep the freeware ball rolling!
  34.  
  35.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  36.  REND386, improving programmer access by rewriting the code and supplying
  37.  a standard API.  If you write improvements, add new functions rather
  38.  than rewriting current functions.  This will make it possible to
  39.  include you improved code in the next API release.  YOU can help advance
  40.  VR-386.  Comments on the API are welcome.
  41.  
  42.  CONTACT: dstampe@psych.toronto.edu
  43. */
  44.  
  45. #include <stdio.h>
  46. #include <stdlib.h>  /* for atol(), only for debugging! */
  47. #include <dos.h>
  48. #include <time.h>    /* time(), ctime() */
  49. #include <string.h>
  50. #include <math.h>
  51. #include <alloc.h>
  52.  
  53. #include "config.h"
  54. #include "pointer.h"
  55. #include "vr_api.h"
  56. #include "intmath.h"
  57. #include "segment.h"
  58. #include "splits.h"
  59. #include "pcdevice.h"    // last_render_time()
  60. #include "vrconst.h"
  61.  
  62. extern char *fix_fname(char *fname);
  63.  
  64. extern manip_2D_avail;
  65.  
  66. extern void set_horizon(int ncolors, int colors[16], int bandsize);
  67.  
  68. extern int do_screen_clear, do_horizon;
  69. extern int show_location, show_compass, show_framerate;
  70.  
  71. extern LIGHT *amb_light, *light1, *light2;
  72.  
  73. static int sstepsize = 10;    /* speed multipliers */
  74. static int astepsize = 2;
  75.  
  76. long anglestep = 160000L;
  77. long spacestep = 10L;
  78.  
  79. int spinmode = 0;
  80. extern int flymode;
  81.  
  82. /******************* MENU TEXT **************/
  83.  
  84. static char *mainmenu[] = {
  85.     "Help",
  86.     "Information",
  87.     "View menu",
  88.     "Paint menu",
  89.     "Display menu",
  90.     "Object menu",
  91.     "Figure menu",
  92.     "Mouse menu",
  93.     "Quit",
  94.     NULL
  95. };
  96.  
  97.  
  98. /********************** KEY INTERPERTER *****************/
  99.  
  100.  
  101. extern BOOL process_motion_keys(unsigned key);
  102.  
  103. BOOL process_display_keys(unsigned c)    // processes and display setup keys
  104. {
  105.   int i, j;
  106.  
  107.   switch (c)
  108.     {
  109.     case CTRLLEFT:
  110.         i = +1;
  111.         goto set_shift;
  112.     case CTRLRIGHT:
  113.         i = -1;
  114.       set_shift:
  115.         if (current_camera->stereo->window[LEFT_EYE].orientation&XFLIP)
  116.            current_camera->stereo->window[LEFT_EYE].xoff += i;
  117.         else
  118.            current_camera->stereo->window[LEFT_EYE].xoff -= i;
  119.  
  120.         if (current_camera->stereo->window[RIGHT_EYE].orientation&XFLIP)
  121.            current_camera->stereo->window[RIGHT_EYE].xoff -= i;
  122.         else
  123.            current_camera->stereo->window[RIGHT_EYE].xoff += i;
  124.  
  125.         compute_camera_factors(current_camera);
  126.         display_changed++;
  127.         break;
  128.     case '+':
  129.         if (stereo_type == MONOSCOPIC)
  130.           {
  131.             SCALE z = get_camera_zoom(current_camera);
  132.             z *= 1.1;
  133.             if(z<65536L*0.5) z = 65536L*0.5;
  134.             if(z>65536L*16.0) z = 65536L*16.0;
  135.             set_camera_zoom(current_camera,z);
  136.           }
  137.         else
  138.           {
  139.             if(current_camera->stereo->phys_screen_dist>30)
  140.             current_camera->stereo->phys_screen_dist *= 1.05;
  141.             else current_camera->stereo->phys_screen_dist *= 1.25;
  142.           }
  143.         compute_camera_factors(current_camera);
  144.         display_changed++;
  145.         break;
  146.     case '-':
  147.         if (stereo_type == MONOSCOPIC)
  148.           {
  149.             SCALE z = get_camera_zoom(current_camera);
  150.             z /= 1.1;
  151.             if(z<65536L*0.5) z = 65536L*0.5;
  152.             if(z>65536L*16.0) z = 65536L*16.0;
  153.             set_camera_zoom(current_camera,z);
  154.             compute_camera_factors(current_camera);
  155.             display_changed++;
  156.             break;
  157.           }
  158.         else
  159.           {
  160.             current_camera->stereo->phys_screen_dist /= 1.05;
  161.             if(current_camera->stereo->phys_screen_dist<5)
  162.                current_camera->stereo->phys_screen_dist = 5;
  163.           }
  164.          compute_camera_factors(current_camera);
  165.          display_changed++;
  166.          break;
  167.     case '@':
  168.         if (stereo_type != MONOSCOPIC)
  169.           {
  170.             current_camera->stereo->phys_eye_spacing /= 1.05;
  171.             if(current_camera->stereo->phys_eye_spacing<5)
  172.             current_camera->stereo->phys_eye_spacing = 5;
  173.             compute_camera_factors(current_camera);
  174.             display_changed++;
  175.           }
  176.         break;
  177.     case '!':
  178.         if (stereo_type != MONOSCOPIC)
  179.           {
  180.             if(current_camera->stereo->phys_eye_spacing>30)
  181.                current_camera->stereo->phys_eye_spacing *= 1.05;
  182.             else
  183.                current_camera->stereo->phys_eye_spacing *= 1.25;
  184.             compute_camera_factors(current_camera);
  185.             display_changed++;
  186.           }
  187.         break;
  188.     default:
  189.         return FALSE;
  190.     }
  191.  return TRUE;
  192. }
  193.  
  194.  
  195. BOOL process_system_keys(unsigned c)    // processes quit, etc
  196. {
  197.   int i, j;
  198.  
  199.   switch (c)
  200.     {
  201.     case 'Q':
  202.     case ESC:
  203.         popmsg("Really quit?");
  204.         i = get_response(1);
  205.         if (toupper(i)=='Y') running = 0;
  206.         else restore_screen();
  207.         break;
  208.     default:
  209.         return FALSE;
  210.     }
  211.   return TRUE;
  212. }
  213.  
  214. extern int mouse_nav;
  215.  
  216. static int movemults[] = { 1,2,3,5,7,10,13,17,22,28};  // speed, angles
  217. static int angmults[] =  { 1,1,1,1,2,2,2,3,4,5};       // 0-9 scale factors
  218.  
  219.  
  220. BOOL process_extmove_keys(unsigned c)    // processes daata-display keys
  221. {
  222.   int i, j;
  223.  
  224.   switch (c)
  225.     {
  226.  
  227.     case '*':   /* level view */
  228.         body_pose->rx = body_pose->rz = 0;
  229.         display_changed++;
  230.         break;
  231.  
  232.     case 'U':
  233.         body_pose->ry += 180*65536L;
  234.         position_changed++;
  235.         break;
  236.  
  237.     case '0':
  238.         sstepsize = movemults[9];
  239.         astepsize = angmults[9];
  240.         break;
  241.     case '1':
  242.     case '2':
  243.     case '3':
  244.     case '4':
  245.     case '5':
  246.     case '6':
  247.     case '7':
  248.     case '8':
  249.     case '9':
  250.         sstepsize = movemults[c - '1'];
  251.         astepsize = angmults[c - '1'];
  252.         break;
  253.  
  254.     case 'J':
  255.         mouse_nav = !mouse_nav;     // toggle mouse joy
  256.         if(manip_2D_avail)
  257.           cursor_enable(!mouse_nav);  // cursor on/off
  258.         break;
  259.  
  260.  
  261.     default:
  262.         return FALSE;
  263.     }
  264.   return TRUE;
  265. }
  266.  
  267.  
  268. /************ API KEY HANDLER **************/
  269.  
  270. void process_a_key(unsigned c)    // processes key <c>
  271. {
  272.   int i, j;
  273.  
  274.   if(c<0x7f)
  275.      if(isalpha(c))
  276.     c = toupper(c);
  277.  
  278.   if(process_motion_keys(c)) return;
  279.   if(process_display_keys(c)) return;
  280.   if(process_system_keys(c)) return;
  281.   if(process_extmove_keys(c)) return;
  282.  
  283.   if(process_minidemo_keys(c)) return;
  284. }
  285.  
  286.  
  287. void key_process()    // reads, processes keys
  288. {
  289.   unsigned c;
  290.  
  291.   if (!bioskey(1)) return;
  292.   c = getkey();            // read a key
  293.   while(bioskey(1)) getkey();   // dump others
  294.  
  295.   process_a_key(c);
  296. }
  297.  
  298.  
  299. /************ API JOYSTICK HANDLER **************/
  300.  
  301.  
  302. void joystick_process()
  303. {
  304.   if(do_joy_navigate(body_pose,
  305.         spinmode, spacestep*sstepsize, astepsize*anglestep, flymode))
  306.       position_changed ++;
  307.  
  308. // NO SPIN MODE FOR MINI DEMO
  309. //
  310. // if (position_changed && spinmode)         // SPECIAL: spin mode move xlat
  311. //            spin_mode_compute();
  312. }
  313.  
  314.