Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10458 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 4.8 KB
RevLine 
[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>
[8729]36#include <ois/OISJoyStick.h>
[3327]37#include "InputDevice.h"
[9667]38#include "core/config/Configurable.h"
[3270]39
40namespace orxonox
41{
[7809]42    //! %Template parameter collection for the base class
[3327]43    struct JoyStickTraits
[3270]44    {
[3327]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    };
[3270]51
[3327]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
[9667]61        : public Configurable
[3327]62        , public InputDeviceTemplated<JoyStickTraits>
63        , public OIS::JoyStickListener
64    {
65        friend class InputDeviceTemplated<JoyStickTraits>;
66        //! Super class alias
67        typedef InputDeviceTemplated<JoyStickTraits> super;
68
[3270]69    public:
[3327]70        //! Assigns a generated ID string and loads the calibration (if present)
71        JoyStick(unsigned int id, OIS::InputManager* oisInputManager);
72        ~JoyStick() { }
[3270]73        void setConfigValues();
74
[3327]75        //! Returns the name generated from the number of knobs and the device name
76        const std::string& getDeviceName() const { return this->deviceName_; }
[3270]77
[3327]78    private:
79        void calibrationStarted();
80        void calibrationStopped();
81        void evaluateCalibration();
[3270]82
[3327]83        void clearBuffersImpl();
[3270]84        void calibrationFileCallback();
85        void fireAxis(int axis, int value);
86
[3327]87        //! OIS event handler
88        bool buttonPressed (const OIS::JoyStickEvent &arg, int button)
89        {
90            super::buttonPressed(static_cast<JoyStickButtonCode::ByEnum>(button));
91            return true;
92        }
93
94        //! OIS event handler
95        bool buttonReleased(const OIS::JoyStickEvent &arg, int button)
96        {
97            super::buttonReleased(static_cast<JoyStickButtonCode::ByEnum>(button));
98            return true;
99        }
100
[3270]101        bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
102        bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
103        bool povMoved      (const OIS::JoyStickEvent &arg, int id);
[3327]104        //! OIS event handler (don't remove that because of OIS version issues!)
[3270]105        bool vector3Moved  (const OIS::JoyStickEvent &arg, int id) { return true; }
106
[3327]107        //! Returns the class name as string
108        static std::string getClassNameImpl() { return "JoyStick"; }
[3270]109
[3327]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!)
[3270]113
114        // calibration
[3327]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
[3270]118
[3327]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
[3270]122
[3327]123        // ConfigValues
124        std::string calibrationFilename_;     //!< Joy stick calibration ini filename
[3270]125
[3327]126        //! Contains a list of all names to avoid duplicates
127        static std::vector<std::string> deviceNames_s;
[3270]128
[3327]129        //!< Maximum number of slider axes
130        static const unsigned int sliderAxes_s = 8;
[3270]131    };
132}
133
[3327]134#endif /* _Core_JoyStick_H__ */
Note: See TracBrowser for help on using the repository browser.