Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Joystick.h
Go to the documentation of this file.
1 /* Project nGen
2  John DiCamillo
3  Copyright © 1997-2002. All Rights Reserved.
4 
5  SUBSYSTEM: nGen.lib
6  FILE: Joystick.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Joystick Input class
13 */
14 
15 #ifndef Joystick_h
16 #define Joystick_h
17 
18 #include "MotionController.h"
19 
20 // +--------------------------------------------------------------------+
21 
22 class Joystick : public MotionController
23 {
24 public:
25  static const char* TYPENAME() { return "Joystick"; }
26 
27  Joystick();
28  virtual ~Joystick();
29 
30  // setup
31  virtual void MapKeys(KeyMapEntry* mapping, int nkeys);
32 
33  // sample the physical device
34  virtual void Acquire();
35 
36  // translations
37  virtual double X() { return x; }
38  virtual double Y() { return y; }
39  virtual double Z() { return z; }
40 
41  // rotations
42  virtual double Pitch() { return p; }
43  virtual double Roll() { return r; }
44  virtual double Yaw() { return w; }
45  virtual int Center() { return 0; }
46 
47  // throttle
48  virtual double Throttle() { return t; }
49  virtual void SetThrottle(double throttle) { t = throttle; }
50 
51  // actions
52  virtual int Action(int n) { return action[n]; }
53  virtual int ActionMap(int n) { return KeyDownMap(n); }
54 
55  static bool KeyDown(int key);
56  static bool KeyDownMap(int key);
57 
58  static Joystick* GetInstance();
59  static void EnumerateDevices();
60  static int NumDevices();
61  static const char* GetDeviceName(int i);
62 
63  static int ReadRawAxis(int axis);
64  static int GetAxisMap(int n);
65  static int GetAxisInv(int n);
66 
67 protected:
68  double ReadAxisDI(int axis);
69  double ReadAxisMM(int axis);
70  void ProcessAxes(double joy_x, double joy_y, double joy_r, double joy_t);
71  void ProcessHat(int i, DWORD joy_pov);
72 
73  double x,y,z,p,r,w,t;
75  bool hat[4][4];
77  int map_axis[4];
78  bool inv_axis[4];
79 };
80 
81 #endif Joystick_h
82