AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Joystick.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
20#include <agxSensor/export.h>
21#include <agx/HashVector.h>
23
25namespace OIS
26{
27 class JoyStickState;
28 class JoyStick;
29}
31
32
33namespace agxSensor
34{
35
41 {
42 public:
43
45
47 class State
48 {
49 public:
50
51 static const int NUM_AXES = 4;
52
54 enum Pov {
55 CENTERED = 0x00000000,
56 NORTH = 0x00000001,
57 SOUTH = 0x00000010,
58 EAST = 0x00000100,
59 WEST = 0x00001000,
60 NORTHEAST = 0x00000101,
61 SOUTHEAST = 0x00000110,
62 NORTHWEST = 0x00001001,
63 SOUTHWEST = 0x00001010
64 };
65
68
71
74
77
80
82 State( const OIS::JoyStickState& oisState );
83
84 protected:
86 };
87
94 virtual bool buttonChanged( const State &arg, int button, bool down ) =0;
95
101 virtual bool axisMoved( const State &arg, int axis ) =0;
102
108 virtual bool povMoved( const State &arg, int pov ) =0;
109
115 virtual bool sliderMoved( const State &arg, int index) =0;
116
121 bool init();
122
128 agx::Real normalize( int axisValue ) const;
129
131
132 protected:
133 virtual ~Joystick();
134 virtual void addNotification();
135 virtual void removeNotification();
136 virtual void pre(const agx::TimeStamp& );
137
138 private:
139 OIS::JoyStick* m_oisJoystick;
140 void *m_listener;
141 bool m_initialized;
142 bool m_forceFeedbackFound;
143 };
144
145
146 class JoystickManager;
147
152 {
153 public:
154
155 static int const NUM_AXES = Joystick::State::NUM_AXES;
156
158 enum Pov {
159 CENTERED = 0x00000000,
160 NORTH = 0x00000001,
161 SOUTH = 0x00000010,
162 EAST = 0x00000100,
163 WEST = 0x00001000,
164 NORTHEAST = 0x00000101,
165 SOUTHEAST = 0x00000110,
166 NORTHWEST = 0x00001001,
167 SOUTHWEST = 0x00001010
168 };
169
172
175
178
181
184
185
187 JoystickState( const OIS::JoyStickState& oisState );
188
189 protected:
191 };
192
193
199 {
200 public:
202 BUTTON = (1<<0),
203 AXIS = (1<<1),
204 POV = (1<<2),
205 SLIDER = (1<<3),
206 ALL = (
207 BUTTON
208 | AXIS
209 | POV
210 | SLIDER
211 ) };
212
217 : m_mask( ALL ), m_manager( nullptr ) {}
218
224 : m_mask( mask ), m_manager( nullptr ) {}
225
233 virtual bool buttonChanged( const agxSensor::JoystickState& state, int button, bool down);
234
242 virtual bool axisUpdate( const agxSensor::JoystickState& state, int axis);
243
250 virtual bool povMoved( const agxSensor::JoystickState& state, int pov );
251
258 virtual bool sliderMoved( const agxSensor::JoystickState& state, int slider);
259
263 virtual void addNotification() {}
264
268 virtual void removeNotification() {}
269
274 void setMask( int mask ) { m_mask = mask; }
275
279 int getMask() const { return m_mask; }
280
281 protected:
282 virtual ~JoystickListener() {}
283
287 JoystickManager* getManager() { return m_manager; }
288 const JoystickManager* getManager() const { return m_manager; }
289
290 private:
291 friend class JoystickManager;
292 void setManager( JoystickManager* manager )
293 {
294 m_manager = manager;
295 }
296
297 private:
298 int m_mask;
299 JoystickManager* m_manager;
300 };
301
304
305
310 {
311 public:
312 JoystickManager(intptr_t hwnd);
313
319 bool add( JoystickListener* listener );
320
326 bool remove( JoystickListener* listener );
327
331 bool valid() const { return m_initialized; }
332
336 bool inSimulation() const { return getSimulation() != nullptr; }
337
342
348 agx::Real normalize( int axisValue ) const;
349
354 virtual void buttonCallback( const agxSensor::JoystickState& state, int button, bool down );
355
360 virtual void povCallback( const agxSensor::JoystickState& state, int pov );
361
362 protected:
364
368 virtual void addNotification();
369
373 virtual void removeNotification();
374
378 virtual void pre( const agx::TimeStamp& );
379
380 private:
381 JoystickListenerContainer m_listeners;
382 JoystickListenerContainer m_listenersToBeRemoved;
383 OIS::JoyStick* m_oisJoystick;
384 bool m_initialized;
385 intptr_t m_hwnd;
386 };
387
389}
#define AGXSENSOR_EXPORT
Simulation * getSimulation()
Derive from this class to implement a listener for simulation step events.
Class that can be used to listen to events generated by a GamePad or Joystick.
Definition Joystick.h:199
JoystickListener()
Default constructor for a joystick listener.
Definition Joystick.h:216
virtual bool axisUpdate(const agxSensor::JoystickState &state, int axis)
Called when the manager has a new joystick state.
JoystickManager * getManager()
Definition Joystick.h:287
virtual bool buttonChanged(const agxSensor::JoystickState &state, int button, bool down)
Called when button button changed state.
virtual void removeNotification()
Called when this listener has been removed from a JoystickManager.
Definition Joystick.h:268
virtual bool sliderMoved(const agxSensor::JoystickState &state, int slider)
Called when slider slider has changed state.
virtual void addNotification()
Called when this listener has been added to a JoystickManager.
Definition Joystick.h:263
const JoystickManager * getManager() const
Definition Joystick.h:288
void setMask(int mask)
Assign new callback mask to this listener.
Definition Joystick.h:274
virtual bool povMoved(const agxSensor::JoystickState &state, int pov)
Called when POV button pov has changed state.
JoystickListener(int mask)
Create joystick listener given a callback mask (default ALL).
Definition Joystick.h:223
A Joystick/GamePad manager that initializes the connected devices and allows for adding listeners.
Definition Joystick.h:310
virtual void pre(const agx::TimeStamp &)
Makes a capture of the joystick and fires callbacks.
virtual void addNotification()
Creates the device if not already created.
bool inSimulation() const
Definition Joystick.h:336
virtual void povCallback(const agxSensor::JoystickState &state, int pov)
Internal method.
virtual void buttonCallback(const agxSensor::JoystickState &state, int button, bool down)
Internal method.
JoystickManager(intptr_t hwnd)
virtual void removeNotification()
Destroys the device and all listeners.
bool remove(JoystickListener *listener)
Remove joystick listener.
agx::Real normalize(int axisValue) const
Normalizes axis value [-1, 1].
JoystickState getState() const
bool add(JoystickListener *listener)
Add new joystick listener.
Store the current state of a Joystick/GamePad.
Definition Joystick.h:152
agx::Int32Vector slidersY
Contains the values for all sliders Y coordinate. Maximum of 4.
Definition Joystick.h:183
Pov
Bit masks indicating the state of the POV button.
Definition Joystick.h:158
agx::Int32Vector pov
Represents the value of POV button. Maximum of 4.
Definition Joystick.h:177
agx::Int32Vector axes
Contains the values for all axes.
Definition Joystick.h:174
agx::Int32Vector slidersX
Contains the values for all sliders X coordinate. Maximum of 4.
Definition Joystick.h:180
JoystickState(const OIS::JoyStickState &oisState)
Copies state from device driver.
agx::BoolVector buttons
Contains the state (in/out) of all buttons.
Definition Joystick.h:171
Class for storing a Joystick state.
Definition Joystick.h:48
agx::BoolVector buttons
Contains the state (in/out) of all buttons.
Definition Joystick.h:67
agx::Int32Vector pov
Represents the value of POV button. Maximum of 4.
Definition Joystick.h:73
agx::Int32Vector slidersX
Contains the values for all sliders X coordinate. Maximum of 4.
Definition Joystick.h:76
Pov
Bitmasks indicating the state of the POV button.
Definition Joystick.h:54
agx::Int32Vector slidersY
Contains the values for all sliders Y coordinate. Maximum of 4.
Definition Joystick.h:79
agx::Int32Vector axes
Contains the values for all axes.
Definition Joystick.h:70
State(const OIS::JoyStickState &oisState)
Copies state from device driver.
Alternative Joystick interface for gamepads etc.
Definition Joystick.h:41
agx::Real normalize(int axisValue) const
Normalizes axis value [-1, 1].
virtual bool povMoved(const State &arg, int pov)=0
Called whenever an POV button is moved.
State getState() const
virtual bool sliderMoved(const State &arg, int index)=0
Called whenever an slider is moved.
virtual void pre(const agx::TimeStamp &)
Called before a step is taken in the simulation Implement this method in the derived class to get cal...
virtual bool axisMoved(const State &arg, int axis)=0
Called whenever an axis control is moved.
virtual void addNotification()
Called when this listener is added to the simulation.
bool init()
Initializes the joystick.
virtual void removeNotification()
Called when this listener is removed from the simulation.
virtual bool buttonChanged(const State &arg, int button, bool down)=0
Called whenever a button is pressed or released on a Joystick.
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition HashVector.h:41
Base class providing referencing counted objects.
Definition Referenced.h:120
Vector containing 'raw' data.
Definition agx/Vector.h:246
Smart pointer for handling referenced counted objects.
Definition ref_ptr.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
The agxSensor namespace contains drivers for reading for devices such as Gamepad.
double Real
Definition Real.h:42
agx::Real TimeStamp
Definition TimeStamp.h:26