| 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 | /** | 
|---|
| 30 | @file | 
|---|
| 31 | @brief Different definitions of input processing. | 
|---|
| 32 | */ | 
|---|
| 33 |  | 
|---|
| 34 | #ifndef _KeyBinder_H__ | 
|---|
| 35 | #define _KeyBinder_H__ | 
|---|
| 36 |  | 
|---|
| 37 | #include "core/CorePrereqs.h" | 
|---|
| 38 |  | 
|---|
| 39 | #include <vector> | 
|---|
| 40 |  | 
|---|
| 41 | #include "core/OrxonoxClass.h" | 
|---|
| 42 | #include "InputInterfaces.h" | 
|---|
| 43 | #include "Button.h" | 
|---|
| 44 | #include "HalfAxis.h" | 
|---|
| 45 |  | 
|---|
| 46 | namespace orxonox | 
|---|
| 47 | { | 
|---|
| 48 | /** | 
|---|
| 49 | @brief Handles mouse, keyboard and joy stick input while in the actual game mode. | 
|---|
| 50 | Manages the key bindings. | 
|---|
| 51 | */ | 
|---|
| 52 | class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass | 
|---|
| 53 | { | 
|---|
| 54 | public: | 
|---|
| 55 | KeyBinder (); | 
|---|
| 56 | virtual ~KeyBinder(); | 
|---|
| 57 |  | 
|---|
| 58 | void loadBindings(); | 
|---|
| 59 | void clearBindings(); | 
|---|
| 60 | void setConfigValues(); | 
|---|
| 61 | void resetJoyStickAxes(); | 
|---|
| 62 |  | 
|---|
| 63 | protected: // functions | 
|---|
| 64 | void tickInput(float dt, const HandlerState& state); | 
|---|
| 65 |  | 
|---|
| 66 | virtual void readTrigger(Button& button); | 
|---|
| 67 |  | 
|---|
| 68 | void keyPressed (const KeyEvent& evt); | 
|---|
| 69 | void keyReleased(const KeyEvent& evt); | 
|---|
| 70 | void keyHeld    (const KeyEvent& evt); | 
|---|
| 71 |  | 
|---|
| 72 | void mouseButtonPressed (MouseButton::Enum id); | 
|---|
| 73 | void mouseButtonReleased(MouseButton::Enum id); | 
|---|
| 74 | void mouseButtonHeld    (MouseButton::Enum id); | 
|---|
| 75 | void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); | 
|---|
| 76 | void mouseScrolled      (int abs, int rel); | 
|---|
| 77 |  | 
|---|
| 78 | void joyStickButtonPressed (int joyStickID, int button); | 
|---|
| 79 | void joyStickButtonReleased(int joyStickID, int button); | 
|---|
| 80 | void joyStickButtonHeld    (int joyStickID, int button); | 
|---|
| 81 | void joyStickAxisMoved     (int joyStickID, int axis, float value); | 
|---|
| 82 |  | 
|---|
| 83 | protected: // variables | 
|---|
| 84 | //! denotes the number of different keys there are in OIS. | 
|---|
| 85 | static const unsigned int nKeys_s = 0xEE; | 
|---|
| 86 | //! Actual key bindings as bundle for Press, Hold and Release | 
|---|
| 87 | Button keys_ [nKeys_s]; | 
|---|
| 88 |  | 
|---|
| 89 | //! denotes the number of different mouse buttons there are in OIS. | 
|---|
| 90 | static const unsigned int nMouseButtons_s = 8 + 2*2; // 8 buttons and 2 scroll wheels | 
|---|
| 91 | //! Actual key bindings as bundle for Press, Hold and Release | 
|---|
| 92 | Button mouseButtons_ [nMouseButtons_s]; | 
|---|
| 93 |  | 
|---|
| 94 | //! denotes the number of different joy stick buttons there are in OIS. | 
|---|
| 95 | static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons | 
|---|
| 96 | //! Actual key bindings as bundle for Press, Hold and Release | 
|---|
| 97 | Button joyStickButtons_ [nJoyStickButtons_s]; | 
|---|
| 98 |  | 
|---|
| 99 | //! denotes the number of half axes (every axis twice) there can be. | 
|---|
| 100 | static const unsigned int nHalfAxes_s = 56; | 
|---|
| 101 | /** | 
|---|
| 102 | * Array with all the half axes for mouse and joy sticks. | 
|---|
| 103 | * Keep in mind that the positions are fixed and that the first entry is the | 
|---|
| 104 | * positive one and the second is negative. | 
|---|
| 105 | * Sequence is as follows: | 
|---|
| 106 | *  0 -  3: Mouse x and y | 
|---|
| 107 | *  4 -  7: empty | 
|---|
| 108 | *  8 - 23: joy stick slider axes 1 to 8 | 
|---|
| 109 | * 24 - 55: joy stick axes 1 - 16 | 
|---|
| 110 | */ | 
|---|
| 111 | HalfAxis halfAxes_[nHalfAxes_s]; | 
|---|
| 112 |  | 
|---|
| 113 | /** | 
|---|
| 114 | * Commands that have additional parameters (axes) are executed at the end of | 
|---|
| 115 | * the tick() so that all values can be buffered for single execution. | 
|---|
| 116 | */ | 
|---|
| 117 | std::vector<BufferedParamCommand*> paramCommandBuffer_; | 
|---|
| 118 |  | 
|---|
| 119 | //! Keeps track of the absolute mouse value (incl. scroll wheel) | 
|---|
| 120 | int mousePosition_[2]; | 
|---|
| 121 | //! Used to derive mouse input if requested | 
|---|
| 122 | int mouseRelative_[2]; | 
|---|
| 123 | float deriveTime_; | 
|---|
| 124 |  | 
|---|
| 125 | //##### ConfigValues ##### | 
|---|
| 126 | //! Threshold for analog triggers until which the state is 0. | 
|---|
| 127 | float analogThreshold_; | 
|---|
| 128 | //! Threshold for analog triggers until which the button is not pressed. | 
|---|
| 129 | float buttonThreshold_; | 
|---|
| 130 | //! Derive mouse input for absolute values? | 
|---|
| 131 | bool bDeriveMouseInput_; | 
|---|
| 132 | //! Accuracy of the mouse input deriver. The higher the more precise, but laggier. | 
|---|
| 133 | float derivePeriod_; | 
|---|
| 134 | //! mouse sensitivity | 
|---|
| 135 | float mouseSensitivity_; | 
|---|
| 136 | //! mouse sensitivity if mouse input is derived | 
|---|
| 137 | float mouseSensitivityDerived_; | 
|---|
| 138 | //! Whether or not to clip abslute mouse values to 1024 | 
|---|
| 139 | bool bClipMouse_; | 
|---|
| 140 | }; | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | #endif /* _KeyBinder_H__ */ | 
|---|