| [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 |  | 
|---|
| [3327] | 29 | #ifndef _Core_JoyStick_H__ | 
|---|
|  | 30 | #define _Core_JoyStick_H__ | 
|---|
| [3270] | 31 |  | 
|---|
| [3327] | 32 | #include "InputPrereqs.h" | 
|---|
| [3270] | 33 |  | 
|---|
|  | 34 | #include <string> | 
|---|
|  | 35 | #include <vector> | 
|---|
| [3327] | 36 | #include "InputDevice.h" | 
|---|
| [3270] | 37 |  | 
|---|
|  | 38 | namespace orxonox | 
|---|
|  | 39 | { | 
|---|
| [3327] | 40 | //! Template parameter collection for the base class | 
|---|
|  | 41 | struct JoyStickTraits | 
|---|
| [3270] | 42 | { | 
|---|
| [3327] | 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 | }; | 
|---|
| [3270] | 49 |  | 
|---|
| [3327] | 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 |  | 
|---|
| [3270] | 67 | public: | 
|---|
| [3327] | 68 | //! Assigns a generated ID string and loads the calibration (if present) | 
|---|
|  | 69 | JoyStick(unsigned int id, OIS::InputManager* oisInputManager); | 
|---|
|  | 70 | ~JoyStick() { } | 
|---|
| [3270] | 71 | void setConfigValues(); | 
|---|
|  | 72 |  | 
|---|
| [3327] | 73 | //! Returns the name generated from the number of knobs and the device name | 
|---|
|  | 74 | const std::string& getDeviceName() const { return this->deviceName_; } | 
|---|
| [3270] | 75 |  | 
|---|
| [3327] | 76 | private: | 
|---|
|  | 77 | void calibrationStarted(); | 
|---|
|  | 78 | void calibrationStopped(); | 
|---|
|  | 79 | void evaluateCalibration(); | 
|---|
| [3270] | 80 |  | 
|---|
| [3327] | 81 | void clearBuffersImpl(); | 
|---|
| [3270] | 82 | void calibrationFileCallback(); | 
|---|
|  | 83 | void fireAxis(int axis, int value); | 
|---|
|  | 84 |  | 
|---|
| [3327] | 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 |  | 
|---|
| [3270] | 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); | 
|---|
| [3327] | 102 | //! OIS event handler (don't remove that because of OIS version issues!) | 
|---|
| [3270] | 103 | bool vector3Moved  (const OIS::JoyStickEvent &arg, int id) { return true; } | 
|---|
|  | 104 |  | 
|---|
| [3327] | 105 | //! Returns the class name as string | 
|---|
|  | 106 | static std::string getClassNameImpl() { return "JoyStick"; } | 
|---|
| [3270] | 107 |  | 
|---|
| [3327] | 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!) | 
|---|
| [3270] | 111 |  | 
|---|
|  | 112 | // calibration | 
|---|
| [3327] | 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 | 
|---|
| [3270] | 116 |  | 
|---|
| [3327] | 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 | 
|---|
| [3270] | 120 |  | 
|---|
| [3327] | 121 | // ConfigValues | 
|---|
|  | 122 | std::string calibrationFilename_;     //!< Joy stick calibration ini filename | 
|---|
| [3270] | 123 |  | 
|---|
| [3327] | 124 | //! Contains a list of all names to avoid duplicates | 
|---|
|  | 125 | static std::vector<std::string> deviceNames_s; | 
|---|
| [3270] | 126 |  | 
|---|
| [3327] | 127 | //!< Maximum number of slider axes | 
|---|
|  | 128 | static const unsigned int sliderAxes_s = 8; | 
|---|
| [3270] | 129 | }; | 
|---|
|  | 130 | } | 
|---|
|  | 131 |  | 
|---|
| [3327] | 132 | #endif /* _Core_JoyStick_H__ */ | 
|---|