Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9231 was 8729, checked in by rgrieder, 13 years ago

Merged unity_build branch back to trunk.

Features:

  • Implemented fully automatic build units to speed up compilation if requested
  • Added DOUT macro for quick debug output
  • Activated text colouring in the POSIX IOConsole
  • DeclareToluaInterface is not necessary anymore

Improvements:

  • Output levels now change appropriately when switch back and forth from dev mode
  • Log level for the file output is now also correct during startup
  • Removed some header file dependencies in core and tools to speed up compilation

no more file for command line options

  • Improved util::tribool by adapting some concepts from boost::tribool

Regressions:

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