Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core4/src/core/input/JoyStick.h @ 3285

Last change on this file since 3285 was 3285, checked in by rgrieder, 15 years ago

Shoved some code around to reduce contents of 'global' InputPrereqs.h

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