Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/input/JoyStick.h @ 12123

Last change on this file since 12123 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 5.0 KB
Line 
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 <ois/OISJoyStick.h>
37#include "InputDevice.h"
38#include "core/config/Configurable.h"
39
40namespace orxonox
41{
42    //! %Template parameter collection for the base class
43    struct JoyStickTraits
44    {
45        typedef JoyStick DeviceClass;
46        typedef OIS::JoyStick OISDeviceClass;
47        typedef JoyStickButtonCode::ByEnum ButtonType;
48        typedef JoyStickButtonCode::ByEnum ButtonTypeParam;
49        static const OIS::Type OISDeviceValue = OIS::OISJoyStick;
50    };
51
52    /**
53    @brief
54        Wraps around an OIS::JoyStick and forwards the input events to
55        a list of input states.
56
57        The class also supports joy stick calibration and stores the values
58        in an ini-file.
59    */
60    class _CoreExport JoyStick
61        : public Configurable
62        , public InputDeviceTemplated<JoyStickTraits>
63        , public OIS::JoyStickListener
64    {
65        friend class InputDeviceTemplated<JoyStickTraits>;
66        //! Super class alias
67        typedef InputDeviceTemplated<JoyStickTraits> super;
68
69    public:
70        //! Assigns a generated ID string and loads the calibration (if present)
71        JoyStick(unsigned int id, OIS::InputManager* oisInputManager);
72        ~JoyStick() = default;
73        void setConfigValues();
74
75        //! Returns the name generated from the number of knobs and the device name
76        const std::string& getDeviceName() const { return this->deviceName_; }
77
78    private:
79        virtual void calibrationStarted() override;
80        virtual void calibrationStopped() override;
81        void evaluateCalibration();
82
83        void clearBuffersImpl();
84        void calibrationFileCallback();
85        void fireAxis(int axis, int value);
86
87        //! OIS event handler
88        virtual bool buttonPressed (const OIS::JoyStickEvent &arg, int button) override
89        {
90            super::buttonPressed(static_cast<JoyStickButtonCode::ByEnum>(button));
91            return true;
92        }
93
94        //! OIS event handler
95        virtual bool buttonReleased(const OIS::JoyStickEvent &arg, int button) override
96        {
97            super::buttonReleased(static_cast<JoyStickButtonCode::ByEnum>(button));
98            return true;
99        }
100
101        virtual bool axisMoved     (const OIS::JoyStickEvent &arg, int axis) override;
102        virtual bool sliderMoved   (const OIS::JoyStickEvent &arg, int id) override;
103        virtual bool povMoved      (const OIS::JoyStickEvent &arg, int id) override;
104        //! OIS event handler (don't remove that because of OIS version issues!)
105        virtual bool vector3Moved  (const OIS::JoyStickEvent &arg, int id) override { return true; }
106
107        //! Returns the class name as string
108        static std::string getClassNameImpl() { return "JoyStick"; }
109
110        std::string deviceName_;              //!< Name generated by the number of knobs and the device name
111        int povStates_[4];                    //!< Internal states for the POVs
112        int sliderStates_[4][2];              //!< Internal states for the Sliders (each slider has X and Y!)
113
114        // calibration
115        int zeroValues_[24];                  //!< Axes values when the knob is in the middle
116        float positiveCoeffs_[24];            //!< Maps the negative part of an axis to a 0.0 to 1.0 floating range
117        float negativeCoeffs_[24];            //!< Maps the positive part of an axis to a 0.0 to 1.0 floating range
118
119        std::vector<int> configZeroValues_;   //!< Config file stored axis values when the knob is in the middle
120        std::vector<int> configMinValues_;    //!< Config file stored minimum axis values
121        std::vector<int> configMaxValues_;    //!< Config file stored maximum axis values
122
123        // ConfigValues
124        std::string calibrationFilename_;     //!< Joy stick calibration ini filename
125
126        //! Contains a list of all names to avoid duplicates
127        static std::vector<std::string> deviceNames_s;
128
129        //!< Maximum number of slider axes
130        static const unsigned int sliderAxes_s = 8;
131    };
132}
133
134#endif /* _Core_JoyStick_H__ */
Note: See TracBrowser for help on using the repository browser.