Changeset 2662 for code/trunk/src/core/input
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/core/input/Button.cc
r2103 r2662 59 59 nCommands_[1]=0; 60 60 nCommands_[2]=0; 61 this->configContainer_ = 0; 61 62 clear(); 63 } 64 65 Button::~Button() 66 { 67 this->clear(); 68 69 if (this->configContainer_) 70 delete this->configContainer_; 62 71 } 63 72 -
code/trunk/src/core/input/Button.h
r2103 r2662 49 49 public: 50 50 Button(); 51 virtual ~Button() { clear(); }51 virtual ~Button(); 52 52 virtual void clear(); 53 53 virtual bool addParamCommand(ParamCommand* command) { return false; } -
code/trunk/src/core/input/InputBuffer.cc
r1755 r2662 73 73 } 74 74 75 InputBuffer::~InputBuffer() 76 { 77 for (std::list<BaseInputBufferListenerTuple*>::const_iterator it = this->listeners_.begin(); 78 it != this->listeners_.end(); ++it) 79 delete *it; 80 } 81 75 82 void InputBuffer::setConfigValues() 76 83 { -
code/trunk/src/core/input/InputBuffer.h
r1887 r2662 79 79 public: 80 80 InputBuffer(); 81 ~InputBuffer(); 81 82 InputBuffer(const std::string allowedChars); 82 83 -
code/trunk/src/core/input/InputInterfaces.h
r1887 r2662 378 378 const char* const ByString[] = 379 379 { 380 "Button0 ", "Button1", "Button2", "Button3",381 "Button 4", "Button5", "Button6", "Button7",382 "Button 8", "Button9","Button10", "Button11",380 "Button00", "Button01", "Button02", "Button03", 381 "Button04", "Button05", "Button06", "Button07", 382 "Button08", "Button09", "Button10", "Button11", 383 383 "Button12", "Button13", "Button14", "Button15", 384 384 "Button16", "Button17", "Button18", "Button19", … … 416 416 "Slider0", "Slider1", "Slider2", "Slider3", 417 417 "Slider4", "Slider5", "Slider6", "Slider7", 418 "Axis0 ", "Axis1", "Axis2", "Axis3",419 "Axis 4", "Axis5", "Axis6", "Axis7",420 "Axis 8", "Axis9","Axis10", "Axis11",418 "Axis00", "Axis01", "Axis02", "Axis03", 419 "Axis04", "Axis05", "Axis06", "Axis07", 420 "Axis08", "Axis09", "Axis10", "Axis11", 421 421 "Axis12", "Axis13", "Axis14", "Axis15" 422 422 }; -
code/trunk/src/core/input/InputManager.cc
r2103 r2662 65 65 SetCommandLineSwitch(keyboard_no_grab); 66 66 67 std::string InputManager::bindingCommmandString_s = "";68 67 EmptyHandler InputManager::EMPTY_HANDLER; 69 68 InputManager* InputManager::singletonRef_s = 0; … … 112 111 , keyDetector_(0) 113 112 , calibratorCallbackBuffer_(0) 114 , bCalibrating_(false)115 113 , keyboardModifiers_(0) 116 114 { … … 119 117 assert(singletonRef_s == 0); 120 118 singletonRef_s = this; 119 120 setConfigValues(); 121 } 122 123 /** 124 @brief 125 Sets the configurable values. 126 */ 127 void InputManager::setConfigValues() 128 { 129 SetConfigValue(calibrationFilename_, "joystick_calibration.ini") 130 .description("Ini filename for the the joy stick calibration data.") 131 .callback(this, &InputManager::_calibrationFileCallback); 132 } 133 134 /** 135 @brief 136 Callback for the joy stick calibration config file. @see setConfigValues. 137 */ 138 void InputManager::_calibrationFileCallback() 139 { 140 ConfigFileManager::getInstance().setFilename(ConfigFileType::JoyStickCalibration, calibrationFilename_); 121 141 } 122 142 … … 174 194 if (joyStickSupport) 175 195 _initialiseJoySticks(); 176 // Do this anyway to also inform every one ifa joystick was detached.177 _configure NumberOfJoySticks();196 // Do this anyway to also inform everything when a joystick was detached. 197 _configureJoySticks(); 178 198 179 199 // Set mouse/joystick region … … 183 203 // clear all buffers 184 204 _clearBuffers(); 185 186 // load joy stick calibration187 setConfigValues();188 205 189 206 internalState_ |= OISReady; … … 335 352 /** 336 353 @brief 354 Helper function that loads the config value vector of one coefficient 355 */ 356 void loadCalibration(std::vector<int>& list, const std::string& sectionName, const std::string& valueName, size_t size, int defaultValue) 357 { 358 list.resize(size); 359 unsigned int configValueVectorSize = ConfigFileManager::getInstance().getVectorSize(ConfigFileType::JoyStickCalibration, sectionName, valueName); 360 if (configValueVectorSize > size) 361 configValueVectorSize = size; 362 363 for (unsigned int i = 0; i < configValueVectorSize; ++i) 364 { 365 list[i] = omni_cast<int>(ConfigFileManager::getInstance().getValue( 366 ConfigFileType::JoyStickCalibration, sectionName, valueName, i, omni_cast<std::string>(defaultValue), false)); 367 } 368 369 // fill the rest with default values 370 for (unsigned int i = configValueVectorSize; i < size; ++i) 371 { 372 list[i] = defaultValue; 373 } 374 } 375 376 /** 377 @brief 337 378 Sets the size of all the different lists that are dependent on the number 338 of joy stick devices created .379 of joy stick devices created and loads the joy stick calibration. 339 380 @remarks 340 381 No matter whether there are a mouse and/or keyboard, they will always 341 382 occupy 2 places in the device number dependent lists. 342 383 */ 343 void InputManager::_configure NumberOfJoySticks()384 void InputManager::_configureJoySticks() 344 385 { 345 386 joySticksSize_ = joySticks_.size(); 346 devicesNum_ = 2 + joySticksSize_; 387 devicesNum_ = 2 + joySticksSize_; 388 joyStickIDs_ .resize(joySticksSize_); 347 389 joyStickButtonsDown_ .resize(joySticksSize_); 348 390 povStates_ .resize(joySticksSize_); 349 391 sliderStates_ .resize(joySticksSize_); 350 joySticksCalibration_.resize(joySticksSize_); 392 joyStickMinValues_ .resize(joySticksSize_); 393 joyStickMaxValues_ .resize(joySticksSize_); 394 joyStickMiddleValues_.resize(joySticksSize_); 395 joyStickCalibrations_.resize(joySticksSize_); 351 396 352 397 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 353 398 { 354 // reset the calibration with default values 355 for (unsigned int i = 0; i < 24; i++) 356 { 357 joySticksCalibration_[iJoyStick].negativeCoeff[i] = 1.0f/32767.0f; 358 joySticksCalibration_[iJoyStick].positiveCoeff[i] = 1.0f/32768.0f; 359 joySticksCalibration_[iJoyStick].zeroStates[i] = 0; 360 } 361 } 399 // Generate some sort of execution unique id per joy stick 400 std::string id = "JoyStick_"; 401 id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Button)) + "_"; 402 id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Axis)) + "_"; 403 id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Slider)) + "_"; 404 id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_POV)) + "_"; 405 id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Vector3)) + "_"; 406 id += joySticks_[iJoyStick]->vendor(); 407 for (unsigned int i = 0; i < iJoyStick; ++i) 408 { 409 if (id == joyStickIDs_[i]) 410 { 411 // Two joysticks are probably equal --> add the index as well 412 id += "_" + omni_cast<std::string>(iJoyStick); 413 } 414 } 415 joyStickIDs_[iJoyStick] = id; 416 417 size_t axes = sliderAxes + (size_t)this->joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Axis); 418 loadCalibration(joyStickMinValues_[iJoyStick], id, "MinValue", axes, -32768); 419 loadCalibration(joyStickMaxValues_[iJoyStick], id, "MaxValue", axes, 32768); 420 loadCalibration(joyStickMiddleValues_[iJoyStick], id, "MiddleValue", axes, 0); 421 } 422 423 _evaluateCalibration(); 362 424 363 425 // state management … … 380 442 } 381 443 382 /** 383 @brief 384 Sets the configurable values. 385 This mainly concerns joy stick calibrations. 386 */ 387 void InputManager::setConfigValues() 388 { 389 if (joySticksSize_ > 0) 390 { 391 std::vector<double> coeffPos; 392 std::vector<double> coeffNeg; 393 std::vector<int> zero; 394 coeffPos.resize(24); 395 coeffNeg.resize(24); 396 zero.resize(24); 397 for (unsigned int i = 0; i < 24; i++) 398 { 399 coeffPos[i] = 1.0f/32767.0f; 400 coeffNeg[i] = 1.0f/32768.0f; 401 zero[i] = 0; 402 } 403 404 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 405 if (!cont) 406 { 407 cont = new ConfigValueContainer(ConfigFileType::Settings, getIdentifier(), getIdentifier()->getName(), "CoeffPos", coeffPos); 408 getIdentifier()->addConfigValueContainer("CoeffPos", cont); 409 } 410 cont->getValue(&coeffPos, this); 411 412 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 413 if (!cont) 414 { 415 cont = new ConfigValueContainer(ConfigFileType::Settings, getIdentifier(), getIdentifier()->getName(), "CoeffNeg", coeffNeg); 416 getIdentifier()->addConfigValueContainer("CoeffNeg", cont); 417 } 418 cont->getValue(&coeffNeg, this); 419 420 cont = getIdentifier()->getConfigValueContainer("Zero"); 421 if (!cont) 422 { 423 cont = new ConfigValueContainer(ConfigFileType::Settings, getIdentifier(), getIdentifier()->getName(), "Zero", zero); 424 getIdentifier()->addConfigValueContainer("Zero", cont); 425 } 426 cont->getValue(&zero, this); 427 428 // copy values to our own variables 429 for (unsigned int i = 0; i < 24; i++) 430 { 431 joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i]; 432 joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i]; 433 joySticksCalibration_[0].zeroStates[i] = zero[i]; 434 } 435 } 436 } 437 444 void InputManager::_evaluateCalibration() 445 { 446 for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick) 447 { 448 for (unsigned int i = 0; i < this->joyStickMinValues_[iJoyStick].size(); i++) 449 { 450 this->joyStickCalibrations_[iJoyStick].middleValue[i] = this->joyStickMiddleValues_[iJoyStick][i]; 451 this->joyStickCalibrations_[iJoyStick].negativeCoeff[i] = - 1.0f / (this->joyStickMinValues_[iJoyStick][i] - this->joyStickMiddleValues_[iJoyStick][i]); 452 this->joyStickCalibrations_[iJoyStick].positiveCoeff[i] = 1.0f / (this->joyStickMaxValues_[iJoyStick][i] - this->joyStickMiddleValues_[iJoyStick][i]); 453 } 454 } 455 } 456 457 void InputManager::_startCalibration() 458 { 459 for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick) 460 { 461 // Set initial values 462 for (unsigned int i = 0; i < this->joyStickMinValues_[iJoyStick].size(); ++i) 463 this->joyStickMinValues_[iJoyStick][i] = INT_MAX; 464 for (unsigned int i = 0; i < this->joyStickMaxValues_[iJoyStick].size(); ++i) 465 this->joyStickMaxValues_[iJoyStick][i] = INT_MIN; 466 for (unsigned int i = 0; i < this->joyStickMiddleValues_[iJoyStick].size(); ++i) 467 this->joyStickMiddleValues_[iJoyStick][i] = 0; 468 } 469 470 getInstance().internalState_ |= Calibrating; 471 getInstance().requestEnterState("calibrator"); 472 } 473 474 void InputManager::_completeCalibration() 475 { 476 for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick) 477 { 478 // Get the middle positions now 479 unsigned int iAxis = 0; 480 for (unsigned int i = 0; i < sliderAxes/2; ++i) 481 { 482 this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mSliders[i].abX; 483 this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mSliders[i].abY; 484 } 485 // Note: joyStickMiddleValues_[iJoyStick] was already correctly resized in _configureJoySticks() 486 assert(joySticks_[iJoyStick]->getJoyStickState().mAxes.size() == joyStickMiddleValues_[iJoyStick].size() - sliderAxes); 487 for (unsigned int i = 0; i < joyStickMiddleValues_[iJoyStick].size() - sliderAxes; ++i) 488 { 489 this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mAxes[i].abs; 490 } 491 492 for (unsigned int i = 0; i < joyStickMinValues_[iJoyStick].size(); ++i) 493 { 494 // Minimum values 495 if (joyStickMinValues_[iJoyStick][i] == INT_MAX) 496 joyStickMinValues_[iJoyStick][i] = -32768; 497 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 498 this->joyStickIDs_[iJoyStick], "MinValue", i, omni_cast<std::string>(joyStickMinValues_[iJoyStick][i]), false); 499 500 // Maximum values 501 if (joyStickMaxValues_[iJoyStick][i] == INT_MIN) 502 joyStickMaxValues_[iJoyStick][i] = 32767; 503 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 504 this->joyStickIDs_[iJoyStick], "MaxValue", i, omni_cast<std::string>(joyStickMaxValues_[iJoyStick][i]), false); 505 506 // Middle values 507 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 508 this->joyStickIDs_[iJoyStick], "MiddleValue", i, omni_cast<std::string>(joyStickMiddleValues_[iJoyStick][i]), false); 509 } 510 } 511 512 _evaluateCalibration(); 513 514 // restore old input state 515 requestLeaveState("calibrator"); 516 internalState_ &= ~Calibrating; 517 } 438 518 439 519 // ############################################################ … … 492 572 } 493 573 } 494 singletonRef_s = 0; 574 575 singletonRef_s = 0; 495 576 } 496 577 … … 660 741 /** 661 742 @brief 662 Updates the InputManager. Tick is called by the Core class.743 Updates the states and the InputState situation. 663 744 @param dt 664 745 Delta time … … 676 757 677 758 // check for states to leave 678 for (std::set<InputState*>::reverse_iterator rit = stateLeaveRequests_.rbegin(); 679 rit != stateLeaveRequests_.rend(); ++rit) 680 { 681 (*rit)->onLeave(); 682 // just to be sure that the state actually is registered 683 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end()); 684 685 activeStates_.erase((*rit)->getPriority()); 686 _updateActiveStates(); 687 } 688 stateLeaveRequests_.clear(); 759 if (!stateLeaveRequests_.empty()) 760 { 761 for (std::set<InputState*>::reverse_iterator rit = stateLeaveRequests_.rbegin(); 762 rit != stateLeaveRequests_.rend(); ++rit) 763 { 764 (*rit)->onLeave(); 765 // just to be sure that the state actually is registered 766 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end()); 767 768 activeStates_.erase((*rit)->getPriority()); 769 _updateActiveStates(); 770 } 771 stateLeaveRequests_.clear(); 772 } 689 773 690 774 // check for states to enter 691 for (std::set<InputState*>::reverse_iterator rit = stateEnterRequests_.rbegin(); 692 rit != stateEnterRequests_.rend(); ++rit) 693 { 694 // just to be sure that the state actually is registered 695 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end()); 696 697 activeStates_[(*rit)->getPriority()] = (*rit); 698 _updateActiveStates(); 699 (*rit)->onEnter(); 700 } 701 stateEnterRequests_.clear(); 775 if (!stateEnterRequests_.empty()) 776 { 777 for (std::set<InputState*>::reverse_iterator rit = stateEnterRequests_.rbegin(); 778 rit != stateEnterRequests_.rend(); ++rit) 779 { 780 // just to be sure that the state actually is registered 781 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end()); 782 783 activeStates_[(*rit)->getPriority()] = (*rit); 784 _updateActiveStates(); 785 (*rit)->onEnter(); 786 } 787 stateEnterRequests_.clear(); 788 } 702 789 703 790 // check for states to destroy 704 for (std::set<InputState*>::reverse_iterator rit = stateDestroyRequests_.rbegin(); 705 rit != stateDestroyRequests_.rend(); ++rit) 706 { 707 _destroyState((*rit)); 708 } 709 stateDestroyRequests_.clear(); 791 if (!stateDestroyRequests_.empty()) 792 { 793 for (std::set<InputState*>::reverse_iterator rit = stateDestroyRequests_.rbegin(); 794 rit != stateDestroyRequests_.rend(); ++rit) 795 { 796 _destroyState((*rit)); 797 } 798 stateDestroyRequests_.clear(); 799 } 710 800 711 801 // check whether a state has changed its EMPTY_HANDLER situation … … 733 823 joySticks_[i]->capture(); 734 824 735 if (! bCalibrating_)825 if (!(internalState_ & Calibrating)) 736 826 { 737 827 // call all the handlers for the held key events … … 804 894 /** 805 895 @brief 806 Processes the accumultated data for the joy stick calibration. 807 */ 808 void InputManager::_completeCalibration() 809 { 810 for (unsigned int i = 0; i < 24; i++) 811 { 812 // positive coefficient 813 if (marginalsMax_[i] == INT_MIN) 814 marginalsMax_[i] = 32767; 815 // coefficients 816 if (marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]) 817 { 818 joySticksCalibration_[0].positiveCoeff[i] 819 = 1.0f/(marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]); 820 } 821 else 822 joySticksCalibration_[0].positiveCoeff[i] = 1.0f; 823 824 // config value 825 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 826 assert(cont); 827 cont->set(i, joySticksCalibration_[0].positiveCoeff[i]); 828 829 // negative coefficient 830 if (marginalsMin_[i] == INT_MAX) 831 marginalsMin_[i] = -32768; 832 // coefficients 833 if (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]) 834 { 835 joySticksCalibration_[0].negativeCoeff[i] = -1.0f 836 / (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]); 837 } 838 else 839 joySticksCalibration_[0].negativeCoeff[i] = 1.0f; 840 // config value 841 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 842 assert(cont); 843 cont->set(i, joySticksCalibration_[0].negativeCoeff[i]); 844 845 // zero states 846 if (i < 8) 847 { 848 if (!(i & 1)) 849 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abX; 850 else 851 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abY; 852 } 853 else 854 { 855 if (i - 8 < joySticks_[0]->getJoyStickState().mAxes.size()) 856 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mAxes[i - 8].abs; 857 else 858 joySticksCalibration_[0].zeroStates[i] = 0; 859 } 860 // config value 861 cont = getIdentifier()->getConfigValueContainer("Zero"); 862 assert(cont); 863 cont->set(i, joySticksCalibration_[0].zeroStates[i]); 864 } 865 866 // restore old input state 867 requestLeaveState("calibrator"); 868 bCalibrating_ = false; 869 } 870 896 Clears all buffers that store what keys/buttons are being pressed at the moment. 897 */ 871 898 void InputManager::clearBuffers() 872 899 { … … 1099 1126 void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value) 1100 1127 { 1101 if ( bCalibrating_)1102 { 1103 if (value > marginalsMax_[axis])1104 marginalsMax_[axis] = value;1105 if (value < marginalsMin_[axis])1106 marginalsMin_[axis] = value;1128 if (internalState_ & Calibrating) 1129 { 1130 if (value < joyStickMinValues_[iJoyStick][axis]) 1131 joyStickMinValues_[iJoyStick][axis] = value; 1132 if (value > joyStickMaxValues_[iJoyStick][axis]) 1133 joyStickMaxValues_[iJoyStick][axis] = value; 1107 1134 } 1108 1135 else 1109 1136 { 1110 float fValue = value - joyStick sCalibration_[iJoyStick].zeroStates[axis];1137 float fValue = value - joyStickCalibrations_[iJoyStick].middleValue[axis]; 1111 1138 if (fValue > 0.0f) 1112 fValue *= joyStick sCalibration_[iJoyStick].positiveCoeff[axis];1139 fValue *= joyStickCalibrations_[iJoyStick].positiveCoeff[axis]; 1113 1140 else 1114 fValue *= joyStick sCalibration_[iJoyStick].negativeCoeff[axis];1141 fValue *= joyStickCalibrations_[iJoyStick].negativeCoeff[axis]; 1115 1142 1116 1143 activeStatesTop_[2 + iJoyStick]->joyStickAxisMoved(iJoyStick, axis, fValue); … … 1124 1151 1125 1152 // keep in mind that the first 8 axes are reserved for the sliders 1126 _fireAxis(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);1153 _fireAxis(iJoyStick, axis + sliderAxes, arg.state.mAxes[axis].abs); 1127 1154 1128 1155 return true; … … 1390 1417 void InputManager::calibrate() 1391 1418 { 1392 getInstance().bCalibrating_ = true; 1393 getInstance().requestEnterState("calibrator"); 1419 COUT(0) << "Move all joy stick axes fully in all directions." << std::endl 1420 << "When done, put the axex in the middle position and press enter." << std::endl; 1421 1422 getInstance()._startCalibration(); 1394 1423 } 1395 1424 -
code/trunk/src/core/input/InputManager.h
r2102 r2662 71 71 struct JoyStickCalibration 72 72 { 73 int zeroStates[24];73 int middleValue[24]; 74 74 float positiveCoeff[24]; 75 75 float negativeCoeff[24]; … … 136 136 public: // variables 137 137 static EmptyHandler EMPTY_HANDLER; 138 static const unsigned int sliderAxes = 8; 138 139 139 140 private: // functions … … 145 146 void _initialiseMouse(); 146 147 void _initialiseJoySticks(); 147 void _configureNumberOfJoySticks(); 148 void _configureJoySticks(); 149 150 void _loadCalibration(); 151 void _startCalibration(); 152 void _completeCalibration(); 153 void _evaluateCalibration(); 148 154 149 155 void _destroyKeyboard(); … … 154 160 155 161 void _reload(bool joyStickSupport); 156 157 void _completeCalibration();158 162 159 163 void _fireAxis(unsigned int iJoyStick, int axis, int value); … … 178 182 179 183 void setConfigValues(); 184 void _calibrationFileCallback(); 180 185 181 186 private: // variables … … 185 190 std::vector<OIS::JoyStick*> joySticks_; //!< OIS joy sticks 186 191 unsigned int joySticksSize_; 192 std::vector<std::string> joyStickIDs_; //!< Execution unique identification strings for the joy sticks 187 193 unsigned int devicesNum_; 188 194 size_t windowHnd_; //!< Render window handle … … 192 198 SimpleInputState* stateEmpty_; 193 199 ExtendedInputState* stateMaster_; //!< Always active master input state 194 KeyDetector* keyDetector_; //!< KeyDetector instance200 KeyDetector* keyDetector_; //!< KeyDetector instance 195 201 InputBuffer* calibratorCallbackBuffer_; 196 202 … … 207 213 208 214 // joystick calibration 209 //std::vector<int> marginalsMaxConfig_; 210 //std::vector<int> marginalsMinConfig_; 211 int marginalsMax_[24]; 212 int marginalsMin_[24]; 213 bool bCalibrated_; 214 bool bCalibrating_; 215 std::vector<std::vector<int> > joyStickMinValues_; 216 std::vector<std::vector<int> > joyStickMaxValues_; 217 std::vector<std::vector<int> > joyStickMiddleValues_; 218 std::vector<ConfigValueContainer*> calibrationConfigValueContainers_; 219 std::vector<JoyStickCalibration> joyStickCalibrations_; 215 220 216 221 unsigned int keyboardModifiers_; //!< Bit mask representing keyboard modifiers. 217 222 std::vector<POVStates> povStates_; //!< Keeps track of the joy stick POV states. 218 223 std::vector<SliderStates> sliderStates_; //!< Keeps track of the possibly two slider axes. 219 std::vector<JoyStickCalibration> joySticksCalibration_;220 224 221 225 std::vector<Key> keysDown_; … … 223 227 std::vector<std::vector<JoyStickButtonCode::ByEnum> > joyStickButtonsDown_; 224 228 225 static std::string bindingCommmandString_s; 229 // ConfigValues 230 std::string calibrationFilename_; //!< Joy stick calibration ini filename 231 226 232 static InputManager* singletonRef_s; 227 233 }; -
code/trunk/src/core/input/KeyBinder.cc
r2103 r2662 33 33 34 34 #include "KeyBinder.h" 35 35 36 #include <fstream> 36 37 #include <string> 38 37 39 #include "util/Convert.h" 38 40 #include "util/Debug.h" … … 66 68 std::string keyname = KeyCode::ByString[i]; 67 69 if (!keyname.empty()) 68 {69 70 keys_[i].name_ = std::string("Key") + keyname; 70 }71 71 else 72 { 73 // some keys have name "" because the code is not occupied by OIS 74 // Use "Key_" plus the number as name to put it at the end of the config file section 75 std::string number = convertToString(i); 76 if (i < 100) 77 number.insert(0, "0"); 78 keys_[i].name_ = std::string("Key_") + number; 79 } 72 keys_[i].name_ = ""; 80 73 keys_[i].paramCommandBuffer_ = ¶mCommandBuffer_; 81 74 keys_[i].groupName_ = "Keys"; … … 97 90 for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++) 98 91 { 99 mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i >> 1];92 mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i / 2]; 100 93 if (i & 1) 101 94 mouseAxes_[i].name_ += "Pos"; … … 224 217 allHalfAxes_.clear(); 225 218 219 // Note: Don't include the dummy keys which don't actually exist in OIS but have a number 226 220 for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++) 227 allButtons_[keys_[i].name_] = keys_ + i; 221 if (!keys_[i].name_.empty()) 222 allButtons_[keys_[i].name_] = keys_ + i; 228 223 for (unsigned int i = 0; i < numberOfMouseButtons_; i++) 229 224 allButtons_[mouseButtons_[i].name_] = mouseButtons_ + i; … … 327 322 if (bDeriveMouseInput_) 328 323 { 329 // only update when deriv edt has passed324 // only update when derivation dt has passed 330 325 if (deriveTime_ > derivePeriod_) 331 326 { 332 327 for (int i = 0; i < 2; i++) 333 328 { 334 if (mouseRelative_[i] >0)329 if (mouseRelative_[i] < 0) 335 330 { 336 331 mouseAxes_[2*i + 0].absVal_ 337 = 332 = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_; 338 333 mouseAxes_[2*i + 1].absVal_ = 0.0f; 339 334 } 340 else if (mouseRelative_[i] <0)335 else if (mouseRelative_[i] > 0) 341 336 { 342 337 mouseAxes_[2*i + 0].absVal_ = 0.0f; 343 338 mouseAxes_[2*i + 1].absVal_ 344 = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;339 = mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_; 345 340 } 346 341 else … … 363 358 // Why dividing relative value by dt? The reason lies in the simple fact, that when you 364 359 // press a button that has relative movement, that value has to be multiplied by dt to be 365 // frame rate independ ant. This can easily (and only) be done in tickInput(float).360 // frame rate independent. This can easily (and only) be done in tickInput(float). 366 361 // Hence we need to divide by dt here for the mouse to compensate, because the relative 367 362 // move movements have nothing to do with dt. … … 441 436 for (int i = 0; i < 2; i++) 442 437 { 443 if (rel[i]) // performance opt. ifrel[i] == 0438 if (rel[i]) // performance opt. for the case that rel[i] == 0 444 439 { 445 440 // write absolute values … … 454 449 mousePosition_[i] = -mouseClippingSize_; 455 450 456 if (mousePosition_[i] >=0)451 if (mousePosition_[i] < 0) 457 452 { 458 mouseAxes_[2*i + 0].absVal_ = 453 mouseAxes_[2*i + 0].absVal_ = -mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_; 459 454 mouseAxes_[2*i + 1].absVal_ = 0.0f; 460 455 } … … 462 457 { 463 458 mouseAxes_[2*i + 0].absVal_ = 0.0f; 464 mouseAxes_[2*i + 1].absVal_ = -mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;459 mouseAxes_[2*i + 1].absVal_ = mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_; 465 460 } 466 461 } … … 471 466 for (int i = 0; i < 2; i++) 472 467 { 473 if (rel[i] >0)474 mouseAxes_[0 + 2*i].relVal_ = 468 if (rel[i] < 0) 469 mouseAxes_[0 + 2*i].relVal_ = -((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_; 475 470 else 476 mouseAxes_[1 + 2*i].relVal_ = -((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;471 mouseAxes_[1 + 2*i].relVal_ = ((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_; 477 472 } 478 473 } … … 484 479 void KeyBinder::mouseScrolled(int abs, int rel) 485 480 { 486 if (rel >0)487 for (int i = 0; i < rel/mouseWheelStepSize_; i++)481 if (rel < 0) 482 for (int i = 0; i < -rel/mouseWheelStepSize_; i++) 488 483 mouseButtons_[8].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_); 489 484 else 490 for (int i = 0; i < -rel/mouseWheelStepSize_; i++)485 for (int i = 0; i < rel/mouseWheelStepSize_; i++) 491 486 mouseButtons_[9].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_); 492 487 } … … 495 490 { 496 491 int i = axis * 2; 497 if (value >=0)498 { 499 joyStickAxes_[joyStickID][i].absVal_ = value;500 joyStickAxes_[joyStickID][i].relVal_ = value;492 if (value < 0) 493 { 494 joyStickAxes_[joyStickID][i].absVal_ = -value; 495 joyStickAxes_[joyStickID][i].relVal_ = -value; 501 496 joyStickAxes_[joyStickID][i].hasChanged_ = true; 502 497 if (joyStickAxes_[joyStickID][i + 1].absVal_ > 0.0f) … … 509 504 else 510 505 { 511 joyStickAxes_[joyStickID][i + 1].absVal_ = -value;512 joyStickAxes_[joyStickID][i + 1].relVal_ = -value;506 joyStickAxes_[joyStickID][i + 1].absVal_ = value; 507 joyStickAxes_[joyStickID][i + 1].relVal_ = value; 513 508 joyStickAxes_[joyStickID][i + 1].hasChanged_ = true; 514 509 if (joyStickAxes_[joyStickID][i].absVal_ > 0.0f) -
code/trunk/src/core/input/KeyBinder.h
r2103 r2662 39 39 40 40 #include <vector> 41 #include <cassert> 42 41 43 #include "InputInterfaces.h" 42 44 #include "Button.h" … … 44 46 #include "InputCommands.h" 45 47 #include "JoyStickDeviceNumberListener.h" 46 #include "core/ConfigFileManager.h"47 48 48 49 namespace orxonox … … 171 172 172 173 inline void KeyBinder::keyPressed (const KeyEvent& evt) 173 { keys_[evt.key].execute(KeybindMode::OnPress); }174 { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnPress); } 174 175 175 176 inline void KeyBinder::keyReleased(const KeyEvent& evt) 176 { keys_[evt.key].execute(KeybindMode::OnRelease); }177 { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnRelease); } 177 178 178 179 inline void KeyBinder::keyHeld (const KeyEvent& evt) 179 { keys_[evt.key].execute(KeybindMode::OnHold); }180 { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnHold); } 180 181 181 182
Note: See TracChangeset
for help on using the changeset viewer.