Orxonox  0.0.5 Codename: Arcturus
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() : Component(OIS_POV), direction(0) {}
38 
39  static const int Centered = 0x00000000;
40  static const int North = 0x00000001;
41  static const int South = 0x00000010;
42  static const int East = 0x00000100;
43  static const int West = 0x00001000;
44  static const int NorthEast = 0x00000101;
45  static const int SouthEast = 0x00000110;
46  static const int NorthWest = 0x00001001;
47  static const int SouthWest = 0x00001010;
48 
49  int direction;
50  };
51 
53  class _OISExport Slider : public Component
54  {
55  public:
56  Slider() : Component(OIS_Slider), abX(0), abY(0) {};
58  int abX, abY;
59  };
60 
67  {
68  public:
70  JoyStickState() { clear(); }
71 
73  std::vector<bool> mButtons;
74 
76  std::vector<Axis> mAxes;
77 
79  Pov mPOV[4];
80 
82  Slider mSliders[4];
83 
85  std::vector<Vector3> mVectors;
86 
88  void clear()
89  {
90  for( std::vector<bool>::iterator i = mButtons.begin(), e = mButtons.end(); i != e; ++i )
91  {
92  (*i) = false;
93  }
94 
95  for( std::vector<Axis>::iterator i = mAxes.begin(), e = mAxes.end(); i != e; ++i )
96  {
97  i->absOnly = true; //Currently, joysticks only report Absolute values
98  i->clear();
99  }
100 
101  for( std::vector<Vector3>::iterator i = mVectors.begin(), e = mVectors.end(); i != e; ++i )
102  {
103  i->clear();
104  }
105 
106  for( int i = 0; i < 4; ++i )
107  {
108  mPOV[i].direction = Pov::Centered;
109  mSliders[i].abX = mSliders[i].abY = 0;
110  }
111  }
112  };
113 
116  {
117  public:
118  JoyStickEvent( Object* obj, const JoyStickState &st ) : EventArg(obj), state(st) {}
119  virtual ~JoyStickEvent() {}
120 
122  };
123 
132  {
133  public:
134  virtual ~JoyStickListener() {}
136  virtual bool buttonPressed( const JoyStickEvent &arg, int button ) = 0;
137 
139  virtual bool buttonReleased( const JoyStickEvent &arg, int button ) = 0;
140 
142  virtual bool axisMoved( const JoyStickEvent &arg, int axis ) = 0;
143 
144  //-- Not so common control events, so are not required --//
146  virtual bool sliderMoved( const JoyStickEvent &, int index) {return true;}
147 
149  virtual bool povMoved( const JoyStickEvent &arg, int index) {return true;}
150 
152  virtual bool vector3Moved( const JoyStickEvent &arg, int index) {return true;}
153  };
154 
159  class _OISExport JoyStick : public Object
160  {
161  public:
162  virtual ~JoyStick() {}
163 
170  int getNumberOfComponents(ComponentType cType) const;
171 
180  void setVector3Sensitivity(float degrees = OIS_JOYSTICK_VECTOR3_DEFAULT);
181 
186  float getVector3Sensitivity() const;
187 
195  virtual void setEventCallback( JoyStickListener *joyListener );
196 
198  JoyStickListener* getEventCallback() const;
199 
201  const JoyStickState& getJoyStickState() const { return mState; }
202 
204  static const int MIN_AXIS = -32768;
205 
207  static const int MAX_AXIS = 32767;
208 
209  protected:
210  JoyStick(const std::string &vendor, bool buffered, int devID, InputManager* creator);
211 
213  int mSliders;
214 
216  int mPOVs;
217 
220 
223 
226  };
227 }
228 #endif
JoyStickListener * mListener
The callback listener.
Definition: OISJoyStick.h:222
Base class of all events.
Definition: OISEvents.h:32
To recieve buffered joystick input, derive a class from this, and implement the methods here...
Definition: OISJoyStick.h:131
std::vector< Axis > mAxes
Represents all the single axes on the device.
Definition: OISJoyStick.h:76
std::vector< Vector3 > mVectors
Represents all Vector type controls the device exports.
Definition: OISJoyStick.h:85
constexpr float e
e
Definition: Math.h:81
Definition: OISPrereqs.h:160
#define _OISExport
Definition: OISPrereqs.h:40
Slider()
Definition: OISJoyStick.h:56
virtual bool povMoved(const JoyStickEvent &arg, int index)
Joystick Event, and povID.
Definition: OISJoyStick.h:149
virtual bool vector3Moved(const JoyStickEvent &arg, int index)
Joystick Event, and Vector3ID.
Definition: OISJoyStick.h:152
::std::string string
Definition: gtest-port.h:756
const JoyStickState & state
Definition: OISJoyStick.h:121
JoyStickEvent(Object *obj, const JoyStickState &st)
Definition: OISJoyStick.h:118
ComponentType
Base type for all device components (button, axis, etc)
Definition: OISPrereqs.h:154
std::vector< bool > mButtons
Represents all the buttons (uses a bitset)
Definition: OISJoyStick.h:73
void clear()
internal method to reset all variables to initial values
Definition: OISJoyStick.h:88
JoyStickState()
Constructor.
Definition: OISJoyStick.h:70
#define OIS_JOYSTICK_VECTOR3_DEFAULT
Definition: OISJoyStick.h:31
Specialised for joystick events.
Definition: OISJoyStick.h:115
virtual ~JoyStickListener()
Definition: OISJoyStick.h:134
float mVector3Sensitivity
Adjustment factor for orientation vector accuracy.
Definition: OISJoyStick.h:225
int abX
true if pushed, false otherwise
Definition: OISJoyStick.h:56
Definition: OISPrereqs.h:159
Base of all device components (button, axis, etc)
Definition: OISPrereqs.h:165
int mSliders
Number of sliders.
Definition: OISJoyStick.h:213
A sliding axis - only used in Win32 Right Now.
Definition: OISJoyStick.h:53
virtual ~JoyStick()
Definition: OISJoyStick.h:162
Represents the state of the joystick All members are valid for both buffered and non buffered mode St...
Definition: OISJoyStick.h:66
const JoyStickState & getJoyStickState() const
Definition: OISJoyStick.h:201
Joystick base class.
Definition: OISJoyStick.h:159
The base class of all input types.
Definition: OISObject.h:32
int direction
Definition: OISJoyStick.h:49
Base Manager class.
Definition: OISInputManager.h:38
virtual bool sliderMoved(const JoyStickEvent &, int index)
Joystick Event, and sliderID.
Definition: OISJoyStick.h:146
Definition: EventHelpers.h:31
Pov()
Definition: OISJoyStick.h:37
JoyStickState mState
The JoyStickState structure (contains all component values)
Definition: OISJoyStick.h:219
POV / HAT Joystick component.
Definition: OISJoyStick.h:34
virtual ~JoyStickEvent()
Definition: OISJoyStick.h:119
int mPOVs
Number of POVs.
Definition: OISJoyStick.h:216
static const int Centered
Definition: OISJoyStick.h:39
int abY
Definition: OISJoyStick.h:56