[3270] | 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 | |
---|
[3274] | 29 | #ifndef _Core_JoyStick_H__ |
---|
| 30 | #define _Core_JoyStick_H__ |
---|
[3270] | 31 | |
---|
[3274] | 32 | #include "InputPrereqs.h" |
---|
[3270] | 33 | |
---|
| 34 | #include <string> |
---|
| 35 | #include <vector> |
---|
[3274] | 36 | #include "InputDevice.h" |
---|
[3270] | 37 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
[3274] | 40 | /** |
---|
| 41 | @brief |
---|
| 42 | Wraps around an OIS::JoyStick and forwards the input events to |
---|
| 43 | a list of input states. |
---|
| 44 | |
---|
| 45 | The class also supports joy stick calibration and stores the values |
---|
| 46 | in an ini-file. |
---|
| 47 | */ |
---|
| 48 | class _CoreExport JoyStick |
---|
| 49 | : public OrxonoxClass |
---|
| 50 | , public InputDeviceTemplated<JoyStickTraits> |
---|
| 51 | , public OIS::JoyStickListener |
---|
[3270] | 52 | { |
---|
[3274] | 53 | friend class InputDeviceTemplated<JoyStickTraits>; |
---|
| 54 | //! Super class alias |
---|
| 55 | typedef InputDeviceTemplated<JoyStickTraits> super; |
---|
[3270] | 56 | |
---|
| 57 | public: |
---|
[3274] | 58 | //! Assigns a generated ID string and loads the calibration (if present) |
---|
| 59 | JoyStick(unsigned int id); |
---|
| 60 | ~JoyStick() { } |
---|
[3270] | 61 | void setConfigValues(); |
---|
| 62 | |
---|
[3274] | 63 | //! Returns the generated (from the number of knobs and the device name) ID string |
---|
[3270] | 64 | const std::string& getIDString() const { return this->idString_; } |
---|
| 65 | |
---|
[3274] | 66 | private: |
---|
| 67 | void calibrationStarted(); |
---|
| 68 | void calibrationStopped(); |
---|
| 69 | void evaluateCalibration(); |
---|
[3270] | 70 | |
---|
[3274] | 71 | void clearBuffersImpl(); |
---|
[3270] | 72 | void calibrationFileCallback(); |
---|
| 73 | void fireAxis(int axis, int value); |
---|
| 74 | |
---|
[3274] | 75 | //! OIS event handler |
---|
| 76 | bool buttonPressed (const OIS::JoyStickEvent &arg, int button) |
---|
| 77 | { |
---|
| 78 | super::buttonPressed(static_cast<JoyStickButtonCode::ByEnum>(button)); |
---|
| 79 | return true; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | //! OIS event handler |
---|
| 83 | bool buttonReleased(const OIS::JoyStickEvent &arg, int button) |
---|
| 84 | { |
---|
| 85 | super::buttonReleased(static_cast<JoyStickButtonCode::ByEnum>(button)); |
---|
| 86 | return true; |
---|
| 87 | } |
---|
| 88 | |
---|
[3270] | 89 | bool axisMoved (const OIS::JoyStickEvent &arg, int axis); |
---|
| 90 | bool sliderMoved (const OIS::JoyStickEvent &arg, int id); |
---|
| 91 | bool povMoved (const OIS::JoyStickEvent &arg, int id); |
---|
[3274] | 92 | //!< OIS event handler (don't remove that because of OIS version issues!) |
---|
[3270] | 93 | bool vector3Moved (const OIS::JoyStickEvent &arg, int id) { return true; } |
---|
| 94 | |
---|
[3274] | 95 | std::string idString_; //!< ID string generated by the number of knobs and the device name |
---|
| 96 | int povStates_[4]; //!< Internal states for the POVs |
---|
| 97 | int sliderStates_[4][2]; //!< Internal states for the Sliders (each slider has X and Y!) |
---|
[3270] | 98 | |
---|
| 99 | // calibration |
---|
[3274] | 100 | int zeroValues_[24]; //!< Axes values when the knob is in the middle |
---|
| 101 | float positiveCoeffs_[24]; //!< Maps the negative part of an axis to a 0.0 to 1.0 floating range |
---|
| 102 | float negativeCoeffs_[24]; //!< Maps the positive part of an axis to a 0.0 to 1.0 floating range |
---|
[3270] | 103 | |
---|
[3274] | 104 | std::vector<int> configZeroValues_; //!< Config file stored axis values when the knob is in the middle |
---|
| 105 | std::vector<int> configMinValues_; //!< Config file stored minimum axis values |
---|
| 106 | std::vector<int> configMaxValues_; //!< Config file stored maximum axis values |
---|
[3270] | 107 | |
---|
[3274] | 108 | // ConfigValues |
---|
| 109 | std::string calibrationFilename_; //!< Joy stick calibration ini filename |
---|
[3270] | 110 | |
---|
[3274] | 111 | //!< Maximum number of slider axes |
---|
| 112 | static const unsigned int sliderAxes_s = 8; |
---|
[3270] | 113 | }; |
---|
| 114 | } |
---|
| 115 | |
---|
[3274] | 116 | #endif /* _Core_JoyStick_H__ */ |
---|