Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Added a few more generic parts to the input library:

  • Created Mouse and Keyboard to join JoyStick and provided them with a templated base class (InputDeviceTemplated) that does most of the work (reduces quite some redundancy)
  • Created InputPrereqs.h from InputInterfaces.h and destroyed the latter
  • Exported InputHandler to its own file and replaced KeyHandler, MouseHandler and JoyStickHandler with the single InputHandler.
  • Deleted the SimpleInputState: There is only one class now which fulfills all our needs.

In general there is now less code and the code itself has more 'pluses'. However I haven't really thrown away any feature at all.

  • Property svn:eol-style set to native
File size: 4.2 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    /**
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
52    {
53        friend class InputDeviceTemplated<JoyStickTraits>;
54        //! Super class alias
55        typedef InputDeviceTemplated<JoyStickTraits> super;
56
57    public:
58        //! Assigns a generated ID string and loads the calibration (if present)
59        JoyStick(unsigned int id);
60        ~JoyStick() { }
61        void setConfigValues();
62
63        //! Returns the generated (from the number of knobs and the device name) ID string
64        const std::string& getIDString() const { return this->idString_; }
65
66    private:
67        void calibrationStarted();
68        void calibrationStopped();
69        void evaluateCalibration();
70
71        void clearBuffersImpl();
72        void calibrationFileCallback();
73        void fireAxis(int axis, int value);
74
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
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);
92        //!< OIS event handler (don't remove that because of OIS version issues!)
93        bool vector3Moved  (const OIS::JoyStickEvent &arg, int id) { return true; }
94
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!)
98
99        // calibration
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
103
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
107
108        // ConfigValues
109        std::string calibrationFilename_;     //!< Joy stick calibration ini filename
110
111        //!< Maximum number of slider axes
112        static const unsigned int sliderAxes_s = 8;
113    };
114}
115
116#endif /* _Core_JoyStick_H__ */
Note: See TracBrowser for help on using the repository browser.