home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Issue 2 / Freelog_HS_3_Setp_Oct_Nov_2000_CD2.mdx / Arcade / Orbit / src / mouse.c < prev    next >
C/C++ Source or Header  |  1999-09-11  |  3KB  |  123 lines

  1. /*
  2.  
  3. ORBIT, a freeware space combat simulator
  4. Copyright (C) 1999  Steve Belczyk <steve1@genesis.nred.ma.us>
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20. */
  21.  
  22. #include "orbit.h"
  23.  
  24. /*
  25.  *  Handle the mouse
  26.  */
  27.  
  28. int oldx, oldy;
  29.  
  30. static void Mouse (int x, int y)
  31. /*
  32.  *  Mouse motion callback
  33.  */
  34. {
  35.     /* Don't bother if position hasn't changed */
  36.     if ( (x == oldx) && (y == oldy) ) return;
  37.  
  38.     mouse.x = x;
  39.     mouse.y = y;
  40. }
  41.  
  42. static void MouseActive (int x, int y)
  43. /*
  44.  *  Mouse motion callback
  45.  */
  46. {
  47.     PlayerFires();
  48.  
  49.     /* Don't bother if position hasn't changed */
  50.     if ( (x == oldx) && (y == oldy) ) return;
  51.  
  52.     mouse.x = x;
  53.     mouse.y = y;
  54. }
  55.  
  56. InitMouse()
  57. /*
  58.  *  Initialize the mouse
  59.  */
  60. {
  61.     glutPassiveMotionFunc (Mouse);
  62.     glutMotionFunc (MouseActive);
  63.  
  64.     if (mouse_control)
  65.     {
  66.         glutSetCursor (GLUT_CURSOR_NONE);
  67.         oldx = ScreenWidth / 2;
  68.         oldy = ScreenHeight/ 2;
  69.         glutWarpPointer (oldx, oldy);
  70.         mouse.x = oldx;
  71.         mouse.y = oldy;
  72.     }
  73. }
  74.  
  75. DoMouse()
  76. /*
  77.  *  Check for mouse movement
  78.  */
  79. {
  80.     /* Not if we're dead */
  81.     if ( (state == STATE_DEAD1) || (state == STATE_DEAD2) ) return;
  82.  
  83.     if (mouse.x > oldx) mouse.right = mouse.x - oldx;
  84.     if (mouse.x < oldx) mouse.left  = oldx - mouse.x;
  85.     if (mouse.y > oldy) mouse.up    = mouse.y - oldy;
  86.     if (mouse.y < oldy) mouse.down  = oldy - mouse.y;
  87.  
  88.     if (mouse.flipx)
  89.     {
  90.         if (mouse.left ) player.move_right = 0.1 * (double) mouse.left;
  91.         if (mouse.right) player.move_left  = 0.1 * (double) mouse.right;
  92.     }
  93.     else
  94.     {
  95.         if (mouse.left ) player.move_left  = 0.1 * (double) mouse.left;
  96.         if (mouse.right) player.move_right = 0.1 * (double) mouse.right;
  97.     }
  98.  
  99.     if (mouse.flipy)
  100.     {
  101.         if (mouse.up   ) player.move_down  = 0.1 * (double) mouse.up;
  102.         if (mouse.down ) player.move_up    = 0.1 * (double) mouse.down;
  103.     }
  104.     else
  105.     {
  106.         if (mouse.up   ) player.move_up    = 0.1 * (double) mouse.up;
  107.         if (mouse.down ) player.move_down  = 0.1 * (double) mouse.down;
  108.     }
  109.  
  110.     mouse.left  = 0;
  111.     mouse.right = 0;
  112.     mouse.up    = 0;
  113.     mouse.down  = 0;
  114.  
  115.     oldx = ScreenWidth / 2;
  116.     oldy = ScreenHeight/ 2;
  117.     glutWarpPointer (oldx, oldy);
  118.  
  119.     mouse.x = oldx;
  120.     mouse.y = oldy;
  121. }
  122.  
  123.