Changeset 3327 for code/trunk/src/core/input/JoyStick.h
- Timestamp:
- Jul 19, 2009, 5:31:02 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core4 merged: 3269,3271-3275,3278,3285,3290-3294,3310
- Property svn:mergeinfo changed
-
code/trunk/src/core/input/JoyStick.h
r3270 r3327 27 27 */ 28 28 29 /** 30 @file 31 @brief 32 */ 29 #ifndef _Core_JoyStick_H__ 30 #define _Core_JoyStick_H__ 33 31 34 #ifndef _JoyStick_H__ 35 #define _JoyStick_H__ 36 37 #include "core/CorePrereqs.h" 32 #include "InputPrereqs.h" 38 33 39 34 #include <string> 40 35 #include <vector> 41 #include "Input Interfaces.h"36 #include "InputDevice.h" 42 37 43 38 namespace orxonox 44 39 { 45 class _CoreExport JoyStick : public OrxonoxClass, public OIS::JoyStickListener 40 //! Template parameter collection for the base class 41 struct JoyStickTraits 46 42 { 47 private: 48 struct JoyStickCalibration 49 { 50 }; 43 typedef JoyStick DeviceClass; 44 typedef OIS::JoyStick OISDeviceClass; 45 typedef JoyStickButtonCode::ByEnum ButtonType; 46 typedef JoyStickButtonCode::ByEnum ButtonTypeParam; 47 static const OIS::Type OISDeviceValue = OIS::OISJoyStick; 48 }; 49 50 /** 51 @brief 52 Wraps around an OIS::JoyStick and forwards the input events to 53 a list of input states. 54 55 The class also supports joy stick calibration and stores the values 56 in an ini-file. 57 */ 58 class _CoreExport JoyStick 59 : public OrxonoxClass 60 , public InputDeviceTemplated<JoyStickTraits> 61 , public OIS::JoyStickListener 62 { 63 friend class InputDeviceTemplated<JoyStickTraits>; 64 //! Super class alias 65 typedef InputDeviceTemplated<JoyStickTraits> super; 51 66 52 67 public: 53 JoyStick(const std::vector<InputState*>& states, unsigned int id);54 ~JoyStick();55 68 //! Assigns a generated ID string and loads the calibration (if present) 69 JoyStick(unsigned int id, OIS::InputManager* oisInputManager); 70 ~JoyStick() { } 56 71 void setConfigValues(); 57 72 58 OIS::JoyStick* getOISJoyStick() { return this->oisJoyStick_; } 59 const std::string& getIDString() const { return this->idString_; } 60 61 void startCalibration(); 62 void stopCalibration(); 63 64 void capture(); 65 void clearBuffer(); 73 //! Returns the name generated from the number of knobs and the device name 74 const std::string& getDeviceName() const { return this->deviceName_; } 66 75 67 76 private: 77 void calibrationStarted(); 78 void calibrationStopped(); 79 void evaluateCalibration(); 80 81 void clearBuffersImpl(); 68 82 void calibrationFileCallback(); 69 void evaluateCalibration();70 83 void fireAxis(int axis, int value); 71 84 72 bool buttonPressed (const OIS::JoyStickEvent &arg, int button); 73 bool buttonReleased(const OIS::JoyStickEvent &arg, int button); 85 //! OIS event handler 86 bool buttonPressed (const OIS::JoyStickEvent &arg, int button) 87 { 88 super::buttonPressed(static_cast<JoyStickButtonCode::ByEnum>(button)); 89 return true; 90 } 91 92 //! OIS event handler 93 bool buttonReleased(const OIS::JoyStickEvent &arg, int button) 94 { 95 super::buttonReleased(static_cast<JoyStickButtonCode::ByEnum>(button)); 96 return true; 97 } 98 74 99 bool axisMoved (const OIS::JoyStickEvent &arg, int axis); 75 100 bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 76 101 bool povMoved (const OIS::JoyStickEvent &arg, int id); 77 // don't remove that! Or else add OIS as dependency library to orxonox (it actually is..)102 //! OIS event handler (don't remove that because of OIS version issues!) 78 103 bool vector3Moved (const OIS::JoyStickEvent &arg, int id) { return true; } 79 104 80 static const unsigned int sliderAxes_s = 8; 105 //! Returns the class name as string 106 static std::string getClassNameImpl() { return "JoyStick"; } 81 107 82 OIS::JoyStick* oisJoyStick_;83 const unsigned int id_;84 std::string idString_;108 std::string deviceName_; //!< Name generated by the number of knobs and the device name 109 int povStates_[4]; //!< Internal states for the POVs 110 int sliderStates_[4][2]; //!< Internal states for the Sliders (each slider has X and Y!) 85 111 86 112 // calibration 87 bool bCalibrating_; 88 int zeroValues_[24]; 89 float positiveCoeffs_[24]; 90 float negativeCoeffs_[24]; 113 int zeroValues_[24]; //!< Axes values when the knob is in the middle 114 float positiveCoeffs_[24]; //!< Maps the negative part of an axis to a 0.0 to 1.0 floating range 115 float negativeCoeffs_[24]; //!< Maps the positive part of an axis to a 0.0 to 1.0 floating range 91 116 92 std::vector<int> configMinValues_; 93 std::vector<int> configMaxValues_; 94 std::vector<int> configZeroValues_; 95 96 int povStates_[4]; 97 int sliderStates_[4][2]; 98 std::vector<JoyStickButtonCode::ByEnum> pressedButtons_; 99 100 // InputState handling 101 const std::vector<InputState*>& inputStates_; 117 std::vector<int> configZeroValues_; //!< Config file stored axis values when the knob is in the middle 118 std::vector<int> configMinValues_; //!< Config file stored minimum axis values 119 std::vector<int> configMaxValues_; //!< Config file stored maximum axis values 102 120 103 121 // ConfigValues 104 std::string calibrationFilename_; //!< Joy stick calibration ini filename 122 std::string calibrationFilename_; //!< Joy stick calibration ini filename 123 124 //! Contains a list of all names to avoid duplicates 125 static std::vector<std::string> deviceNames_s; 126 127 //!< Maximum number of slider axes 128 static const unsigned int sliderAxes_s = 8; 105 129 }; 106 130 } 107 131 108 #endif /* _ JoyStick_H__ */132 #endif /* _Core_JoyStick_H__ */
Note: See TracChangeset
for help on using the changeset viewer.