OIS  1.5
Object-oriented Input System
OISJoyStick.h
Go to the documentation of this file.
1 /*
2 The zlib/libpng License
3 
4 Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
5 
6 This software is provided 'as-is', without any express or implied warranty. In no event will
7 the authors be held liable for any damages arising from the use of this software.
8 
9 Permission is granted to anyone to use this software for any purpose, including commercial
10 applications, and to alter it and redistribute it freely, subject to the following
11 restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not claim that
14  you wrote the original software. If you use this software in a product,
15  an acknowledgment in the product documentation would be appreciated but is
16  not required.
17 
18  2. Altered source versions must be plainly marked as such, and must not be
19  misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source distribution.
22 */
23 #ifndef OIS_Joystick_H
24 #define OIS_Joystick_H
25 #include "OISObject.h"
26 #include "OISEvents.h"
27 
28 namespace OIS
29 {
31 #define OIS_JOYSTICK_VECTOR3_DEFAULT 2.28f
32 
34  class _OISExport Pov : public Component
35  {
36  public:
37  Pov() :
38  Component(OIS_POV), direction(0) {}
39 
40  static const int Centered = 0x00000000;
41  static const int North = 0x00000001;
42  static const int South = 0x00000010;
43  static const int East = 0x00000100;
44  static const int West = 0x00001000;
45  static const int NorthEast = 0x00000101;
46  static const int SouthEast = 0x00000110;
47  static const int NorthWest = 0x00001001;
48  static const int SouthWest = 0x00001010;
49 
50  int direction;
51  };
52 
54  class _OISExport Slider : public Component
55  {
56  public:
57  Slider() :
58  Component(OIS_Slider), abX(0), abY(0){};
60  int abX, abY;
61  };
62 
69  {
70  public:
72  JoyStickState() { clear(); }
73 
75  std::vector<bool> mButtons;
76 
78  std::vector<Axis> mAxes;
79 
81  Pov mPOV[4];
82 
84  Slider mSliders[4];
85 
87  std::vector<Vector3> mVectors;
88 
90  void clear()
91  {
92  for(std::vector<bool>::iterator i = mButtons.begin(), e = mButtons.end(); i != e; ++i)
93  {
94  (*i) = false;
95  }
96 
97  for(std::vector<Axis>::iterator i = mAxes.begin(), e = mAxes.end(); i != e; ++i)
98  {
99  i->absOnly = true; //Currently, joysticks only report Absolute values
100  i->clear();
101  }
102 
103  for(std::vector<Vector3>::iterator i = mVectors.begin(), e = mVectors.end(); i != e; ++i)
104  {
105  i->clear();
106  }
107 
108  for(int i = 0; i < 4; ++i)
109  {
110  mPOV[i].direction = Pov::Centered;
111  mSliders[i].abX = mSliders[i].abY = 0;
112  }
113  }
114  };
115 
118  {
119  public:
120  JoyStickEvent(Object* obj, const JoyStickState& st) :
121  EventArg(obj), state(st) {}
122  virtual ~JoyStickEvent() {}
123 
125 
126  private:
127  // Prevent copying.
129  JoyStickEvent& operator=(JoyStickEvent);
130  };
131 
140  {
141  public:
142  virtual ~JoyStickListener() {}
144  virtual bool buttonPressed(const JoyStickEvent& arg, int button) = 0;
145 
147  virtual bool buttonReleased(const JoyStickEvent& arg, int button) = 0;
148 
150  virtual bool axisMoved(const JoyStickEvent& arg, int axis) = 0;
151 
152  //-- Not so common control events, so are not required --//
154  virtual bool sliderMoved(const JoyStickEvent& arg, int index)
155  {
156  OIS_UNUSED(arg);
157  OIS_UNUSED(index);
158  return true;
159  }
160 
162  virtual bool povMoved(const JoyStickEvent& arg, int index)
163  {
164  OIS_UNUSED(arg);
165  OIS_UNUSED(index);
166  return true;
167  }
168 
170  virtual bool vector3Moved(const JoyStickEvent& arg, int index)
171  {
172  OIS_UNUSED(arg);
173  OIS_UNUSED(index);
174  return true;
175  }
176  };
177 
182  class _OISExport JoyStick : public Object
183  {
184  public:
185  virtual ~JoyStick() {}
186 
193  int getNumberOfComponents(ComponentType cType) const;
194 
203  void setVector3Sensitivity(float degrees = OIS_JOYSTICK_VECTOR3_DEFAULT);
204 
209  float getVector3Sensitivity() const;
210 
218  virtual void setEventCallback(JoyStickListener* joyListener);
219 
221  JoyStickListener* getEventCallback() const;
222 
224  const JoyStickState& getJoyStickState() const { return mState; }
225 
227  static const int MIN_AXIS = -32768;
228 
230  static const int MAX_AXIS = 32767;
231 
232  protected:
233  JoyStick(const std::string& vendor, bool buffered, int devID, InputManager* creator);
234 
236  int mSliders;
237 
239  int mPOVs;
240 
243 
246 
249  };
250 }
251 #endif
JoyStickListener * mListener
The callback listener.
Definition: OISJoyStick.h:245
Definition: OISEvents.h:32
Definition: OISJoyStick.h:139
std::vector< Axis > mAxes
Represents all the single axes on the device.
Definition: OISJoyStick.h:78
std::vector< Vector3 > mVectors
Represents all Vector type controls the device exports.
Definition: OISJoyStick.h:87
Definition: OISPrereqs.h:181
#define _OISExport
Definition: OISPrereqs.h:40
Slider()
Definition: OISJoyStick.h:57
virtual bool povMoved(const JoyStickEvent &arg, int index)
Joystick Event, and povID.
Definition: OISJoyStick.h:162
virtual bool vector3Moved(const JoyStickEvent &arg, int index)
Joystick Event, and Vector3ID.
Definition: OISJoyStick.h:170
const JoyStickState & state
Definition: OISJoyStick.h:124
JoyStickEvent(Object *obj, const JoyStickState &st)
Definition: OISJoyStick.h:120
ComponentType
Base type for all device components (button, axis, etc)
Definition: OISPrereqs.h:175
std::vector< bool > mButtons
Represents all the buttons (uses a bitset)
Definition: OISJoyStick.h:75
void clear()
internal method to reset all variables to initial values
Definition: OISJoyStick.h:90
JoyStickState()
Constructor.
Definition: OISJoyStick.h:72
#define OIS_JOYSTICK_VECTOR3_DEFAULT
Definition: OISJoyStick.h:31
Definition: OISJoyStick.h:117
virtual ~JoyStickListener()
Definition: OISJoyStick.h:142
float mVector3Sensitivity
Adjustment factor for orientation vector accuracy.
Definition: OISJoyStick.h:248
int abX
true if pushed, false otherwise
Definition: OISJoyStick.h:58
Definition: OISPrereqs.h:180
Base of all device components (button, axis, etc)
Definition: OISPrereqs.h:186
int mSliders
Number of sliders.
Definition: OISJoyStick.h:236
A sliding axis - only used in Win32 Right Now.
Definition: OISJoyStick.h:54
virtual ~JoyStick()
Definition: OISJoyStick.h:185
Definition: OISJoyStick.h:68
Definition: OISJoyStick.h:182
Definition: OISObject.h:32
int direction
Definition: OISJoyStick.h:50
const JoyStickState & getJoyStickState() const
Definition: OISJoyStick.h:224
#define OIS_UNUSED(x)
Definition: OISPrereqs.h:117
Definition: OISInputManager.h:38
virtual bool sliderMoved(const JoyStickEvent &arg, int index)
Joystick Event, and sliderID.
Definition: OISJoyStick.h:154
Definition: OISEffect.h:28
Pov()
Definition: OISJoyStick.h:37
JoyStickState mState
The JoyStickState structure (contains all component values)
Definition: OISJoyStick.h:242
POV / HAT Joystick component.
Definition: OISJoyStick.h:34
virtual ~JoyStickEvent()
Definition: OISJoyStick.h:122
int mPOVs
Number of POVs.
Definition: OISJoyStick.h:239
static const int Centered
Definition: OISJoyStick.h:40
int abY
Definition: OISJoyStick.h:58