1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Reto Grieder |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef _Core_JoyStick_H__ |
---|
30 | #define _Core_JoyStick_H__ |
---|
31 | |
---|
32 | #include "InputPrereqs.h" |
---|
33 | |
---|
34 | #include <string> |
---|
35 | #include <vector> |
---|
36 | #include "InputDevice.h" |
---|
37 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | //! %Template parameter collection for the base class |
---|
41 | struct JoyStickTraits |
---|
42 | { |
---|
43 | typedef JoyStick DeviceClass; |
---|
44 | typedef OIS::JoyStick OISDeviceClass; |
---|
45 | typedef JoyStickButtonCode::ByEnum ButtonType; |
---|
46 | typedef JoyStickButtonCode::ByEnum ButtonTypeParam; |
---|
47 | static const OIS::Type OISDeviceValue = OIS::OISJoyStick; |
---|
48 | }; |
---|
49 | |
---|
50 | /** |
---|
51 | @brief |
---|
52 | Wraps around an OIS::JoyStick and forwards the input events to |
---|
53 | a list of input states. |
---|
54 | |
---|
55 | The class also supports joy stick calibration and stores the values |
---|
56 | in an ini-file. |
---|
57 | */ |
---|
58 | class _CoreExport JoyStick |
---|
59 | : public OrxonoxClass |
---|
60 | , public InputDeviceTemplated<JoyStickTraits> |
---|
61 | , public OIS::JoyStickListener |
---|
62 | { |
---|
63 | friend class InputDeviceTemplated<JoyStickTraits>; |
---|
64 | //! Super class alias |
---|
65 | typedef InputDeviceTemplated<JoyStickTraits> super; |
---|
66 | |
---|
67 | public: |
---|
68 | //! Assigns a generated ID string and loads the calibration (if present) |
---|
69 | JoyStick(unsigned int id, OIS::InputManager* oisInputManager); |
---|
70 | ~JoyStick() { } |
---|
71 | void setConfigValues(); |
---|
72 | |
---|
73 | //! Returns the name generated from the number of knobs and the device name |
---|
74 | const std::string& getDeviceName() const { return this->deviceName_; } |
---|
75 | |
---|
76 | private: |
---|
77 | void calibrationStarted(); |
---|
78 | void calibrationStopped(); |
---|
79 | void evaluateCalibration(); |
---|
80 | |
---|
81 | void clearBuffersImpl(); |
---|
82 | void calibrationFileCallback(); |
---|
83 | void fireAxis(int axis, int value); |
---|
84 | |
---|
85 | //! OIS event handler |
---|
86 | bool buttonPressed (const OIS::JoyStickEvent &arg, int button) |
---|
87 | { |
---|
88 | super::buttonPressed(static_cast<JoyStickButtonCode::ByEnum>(button)); |
---|
89 | return true; |
---|
90 | } |
---|
91 | |
---|
92 | //! OIS event handler |
---|
93 | bool buttonReleased(const OIS::JoyStickEvent &arg, int button) |
---|
94 | { |
---|
95 | super::buttonReleased(static_cast<JoyStickButtonCode::ByEnum>(button)); |
---|
96 | return true; |
---|
97 | } |
---|
98 | |
---|
99 | bool axisMoved (const OIS::JoyStickEvent &arg, int axis); |
---|
100 | bool sliderMoved (const OIS::JoyStickEvent &arg, int id); |
---|
101 | bool povMoved (const OIS::JoyStickEvent &arg, int id); |
---|
102 | //! OIS event handler (don't remove that because of OIS version issues!) |
---|
103 | bool vector3Moved (const OIS::JoyStickEvent &arg, int id) { return true; } |
---|
104 | |
---|
105 | //! Returns the class name as string |
---|
106 | static std::string getClassNameImpl() { return "JoyStick"; } |
---|
107 | |
---|
108 | std::string deviceName_; //!< Name generated by the number of knobs and the device name |
---|
109 | int povStates_[4]; //!< Internal states for the POVs |
---|
110 | int sliderStates_[4][2]; //!< Internal states for the Sliders (each slider has X and Y!) |
---|
111 | |
---|
112 | // calibration |
---|
113 | int zeroValues_[24]; //!< Axes values when the knob is in the middle |
---|
114 | float positiveCoeffs_[24]; //!< Maps the negative part of an axis to a 0.0 to 1.0 floating range |
---|
115 | float negativeCoeffs_[24]; //!< Maps the positive part of an axis to a 0.0 to 1.0 floating range |
---|
116 | |
---|
117 | std::vector<int> configZeroValues_; //!< Config file stored axis values when the knob is in the middle |
---|
118 | std::vector<int> configMinValues_; //!< Config file stored minimum axis values |
---|
119 | std::vector<int> configMaxValues_; //!< Config file stored maximum axis values |
---|
120 | |
---|
121 | // ConfigValues |
---|
122 | std::string calibrationFilename_; //!< Joy stick calibration ini filename |
---|
123 | |
---|
124 | //! Contains a list of all names to avoid duplicates |
---|
125 | static std::vector<std::string> deviceNames_s; |
---|
126 | |
---|
127 | //!< Maximum number of slider axes |
---|
128 | static const unsigned int sliderAxes_s = 8; |
---|
129 | }; |
---|
130 | } |
---|
131 | |
---|
132 | #endif /* _Core_JoyStick_H__ */ |
---|