home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / MacWT 0.04 / wt / linux-mouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-31  |  3.3 KB  |  127 lines  |  [TEXT/MMCC]

  1. /*
  2. **  wt -- a 3d game engine
  3. **
  4. **  Copyright (C) 1994 by Chris Laurel
  5. **  email:  claurel@mr.net
  6. **  snail mail:  Chris Laurel, 5700 W Lake St #208,  St. Louis Park, MN  55416
  7. **
  8. **  This program is free software; you can redistribute it and/or modify
  9. **  it under the terms of the GNU General Public License as published by
  10. **  the Free Software Foundation; either version 2 of the License, or
  11. **  (at your option) any later version.
  12. **
  13. **  This program is distributed in the hope that it will be useful,
  14. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. **  GNU General Public License for more details.
  17. **
  18. **  You should have received a copy of the GNU General Public License
  19. **  along with this program; if not, write to the Free Software
  20. **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22.  
  23. /* Linux mouse code by Pekka Pietik{inen <pp@lyseo.otol.fi>, tweaked
  24. **   by Chris Laurel
  25. */
  26.  
  27. #include <math.h>
  28. #include <vgamouse.h>
  29. #include "wt.h"
  30. #include "error.h"
  31. #include "input.h"
  32.  
  33.  
  34. #define MOUSE_XRANGE 320
  35. #define MOUSE_YRANGE 200
  36.  
  37.  
  38. static void add_special(Intent *intent, int special);
  39.  
  40. /*
  41. static Boolean rotating_cw = False;
  42. static Boolean rotating_ccw = False;
  43. static Boolean moving_forward = False;
  44. static Boolean moving_backward = False;
  45. */
  46. static Boolean running = False;
  47. static Boolean strafing = False;
  48.  
  49.  
  50. void init_input_devices(void)
  51. {
  52.      mouse_init("/dev/mouse", MOUSE_MICROSOFT, MOUSE_DEFAULTSAMPLERATE);
  53.      mouse_setxrange(0, MOUSE_XRANGE - 1);
  54.      mouse_setyrange(0, MOUSE_YRANGE - 1);
  55.      mouse_setwrap(MOUSE_NOWRAP);
  56.      mouse_setposition(MOUSE_XRANGE / 2, MOUSE_YRANGE / 2);
  57. }
  58.  
  59.  
  60. void end_input_devices(void)
  61. {
  62.      mouse_close();
  63. }
  64.  
  65.  
  66. Intent *read_input_devices(void)
  67. {
  68.      static Intent intent;
  69.      int mouse_x, mouse_y, mouse_button;
  70.  
  71.  
  72.      intent.n_special = 0;
  73.      intent.force_y = 0.0;
  74.      intent.force_x = 0.0;
  75.      intent.force_rotate = 0.0;
  76.  
  77.      mouse_update();
  78.      mouse_x = mouse_getx();
  79.      mouse_y = mouse_gety();
  80.      mouse_button = mouse_getbutton();
  81.      if (mouse_button & MOUSE_LEFTBUTTON)
  82.       add_special(&intent, INTENT_JUMP);
  83.      if (mouse_button & MOUSE_RIGHTBUTTON)
  84.       strafing=True;
  85.      else
  86.       strafing=False;  
  87.  
  88.      if (strafing)
  89.       intent.force_y += (double) (2 * (MOUSE_XRANGE / 2 - mouse_x)) /
  90.            (double) MOUSE_XRANGE;
  91.      else
  92.       intent.force_rotate += (double) (2 * (MOUSE_XRANGE / 2 - mouse_x)) /
  93.            (double) MOUSE_XRANGE;
  94.      intent.force_x += (double) (2 * (MOUSE_YRANGE / 2 - mouse_y)) /
  95.       (double) MOUSE_YRANGE;
  96.      
  97.      intent.force_x *= fabs(intent.force_x);
  98.      intent.force_y *= fabs(intent.force_y);
  99.      intent.force_rotate *= intent.force_rotate * intent.force_rotate;;
  100.  
  101.      if (fabs(intent.force_x) < 0.1)
  102.       intent.force_x = 0.0;
  103.      if (fabs(intent.force_y) < 0.1)
  104.       intent.force_y = 0.0;
  105.      if (fabs(intent.force_rotate) < 0.1)
  106.       intent.force_rotate = 0.0;
  107.  
  108.      if (running) {
  109.           intent.force_x *= 2.0;
  110.           intent.force_y *= 2.0;
  111.           intent.force_z *= 2.0;
  112.  
  113.           intent.force_rotate *= 2.0;
  114.      }
  115.  
  116.      return &intent;
  117. }
  118.  
  119.  
  120. void add_special(Intent *intent, int special)
  121. {
  122.      if (intent->n_special < MAX_SPECIAL_INTENTIONS) {
  123.       intent->special[intent->n_special] = special;
  124.       intent->n_special++;
  125.      }
  126. }
  127.