Changeset 1444 for code/branches/network/src
- Timestamp:
- May 28, 2008, 12:01:16 AM (16 years ago)
- Location:
- code/branches/network/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/core/ConfigValueContainer.cc
r1062 r1444 139 139 /** 140 140 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 141 @param input The new value 141 @param input The new value. If bIsVector_ then write "index value" 142 142 @return True if the new value was successfully assigned 143 143 */ -
code/branches/network/src/core/ConfigValueIncludes.h
r1428 r1444 121 121 } 122 122 123 /**124 @brief Assigns the command, defined in the keybind-file, to the key-variable (or an empty string, if there is no entry in the file).125 @param varname The name of the key-variable126 */127 #define SetKeybind(keyname) \128 orxonox::ConfigValueContainer* container##keyname = this->getIdentifier()->getConfigValueContainer(#keyname); \129 if (!container##keyname) \130 { \131 container##keyname = new orxonox::ConfigValueContainer(CFT_Keybindings, this->getIdentifier(), #keyname, keyname = ""); \132 this->getIdentifier()->addConfigValueContainer(#keyname, container##keyname); \133 } \134 container##keyname->getValue(&varname)135 136 123 #endif /* _ConfigValueIncludes_H__ */ -
code/branches/network/src/core/CorePrereqs.h
r1414 r1444 156 156 // input 157 157 //class GUIInputHandler; 158 class Calibrator; 159 class CalibratorCallback; 158 160 class InputBuffer; 159 161 class InputBufferListener; -
code/branches/network/src/core/InputInterfaces.h
r1413 r1444 313 313 virtual void joyStickButtonReleased(int joyStickID, int button) = 0; 314 314 virtual void joyStickButtonHeld (int joyStickID, int button) = 0; 315 virtual void joyStickAxisMoved (int joyStickID, int axis, int value) = 0;315 virtual void joyStickAxisMoved (int joyStickID, int axis, float value) = 0; 316 316 //virtual bool joyStickVector3Moved (int joyStickID, int index /*, fill list*/) {return true;} 317 317 //virtual void tickJoyStick (float dt) { } -
code/branches/network/src/core/InputManager.cc
r1428 r1444 34 34 35 35 #include "InputManager.h" 36 #include "util/Convert.h" 36 37 #include "CoreIncludes.h" 38 #include "ConfigValueIncludes.h" 37 39 #include "Debug.h" 38 40 #include "InputBuffer.h" … … 45 47 ConsoleCommandShortcut(InputManager, keyBind, AccessLevel::User); 46 48 ConsoleCommandShortcut(InputManager, storeKeyStroke, AccessLevel::Offline); 49 ConsoleCommandShortcut(InputManager, calibrate, AccessLevel::User); 47 50 48 51 // ############################### … … 58 61 inputSystem_(0), keyboard_(0), mouse_(0), 59 62 joySticksSize_(0), 60 keyBinder_(0), buffer_(0), keyDetector_(0),63 keyBinder_(0), keyDetector_(0), buffer_(0), calibratorCallback_(0), 61 64 state_(IS_UNINIT), stateRequest_(IS_UNINIT), savedState_(IS_UNINIT), 62 65 keyboardModifiers_(0) … … 143 146 state_ = IS_NONE; 144 147 CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl; 148 149 // InputManager holds the input buffer --> create one and add it. 150 buffer_ = new InputBuffer(); 151 addKeyHandler(buffer_, "buffer"); 152 153 keyBinder_ = new KeyBinder(); 154 keyBinder_->loadBindings(); 155 addKeyHandler(keyBinder_, "keybinder"); 156 addMouseHandler(keyBinder_, "keybinder"); 157 addJoyStickHandler(keyBinder_, "keybinder"); 158 159 keyDetector_ = new KeyDetector(); 160 keyDetector_->loadBindings(); 161 addKeyHandler(keyDetector_, "keydetector"); 162 addMouseHandler(keyDetector_, "keydetector"); 163 addJoyStickHandler(keyDetector_, "keydetector"); 164 165 calibratorCallback_ = new CalibratorCallback(); 166 addKeyHandler(calibratorCallback_, "calibratorcallback"); 167 168 setConfigValues(); 169 170 CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl; 145 171 } 146 172 else … … 148 174 CCOUT(ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl; 149 175 } 150 151 // InputManager holds the input buffer --> create one and add it.152 buffer_ = new InputBuffer();153 addKeyHandler(buffer_, "buffer");154 155 keyBinder_ = new KeyBinder();156 keyBinder_->loadBindings();157 addKeyHandler(keyBinder_, "keybinder");158 addMouseHandler(keyBinder_, "keybinder");159 addJoyStickHandler(keyBinder_, "keybinder");160 161 keyDetector_ = new KeyDetector();162 keyDetector_->loadBindings();163 addKeyHandler(keyDetector_, "keydetector");164 addMouseHandler(keyDetector_, "keydetector");165 addJoyStickHandler(keyDetector_, "keydetector");166 167 CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;168 176 return true; 169 177 } … … 285 293 povStates_.resize(joySticksSize_); 286 294 sliderStates_.resize(joySticksSize_); 295 joySticksCalibration_.resize(joySticksSize_); 296 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 297 { 298 // reset the calibration with default values 299 for (unsigned int i = 0; i < 24; i++) 300 { 301 joySticksCalibration_[iJoyStick].negativeCoeff[i] = 1.0f/32767.0f; 302 joySticksCalibration_[iJoyStick].positiveCoeff[i] = 1.0f/32768.0f; 303 joySticksCalibration_[iJoyStick].zeroStates[i] = 0; 304 } 305 } 287 306 return success; 307 } 308 309 /** 310 @brief Sets the configurable values. Use keybindings.ini as file.. 311 */ 312 void InputManager::setConfigValues() 313 { 314 if (joySticksSize_) 315 { 316 std::vector<MultiTypeMath> coeffPos; 317 std::vector<MultiTypeMath> coeffNeg; 318 std::vector<MultiTypeMath> zero; 319 coeffPos.resize(24); 320 coeffNeg.resize(24); 321 zero.resize(24); 322 for (unsigned int i = 0; i < 24; i++) 323 { 324 coeffPos[i] = 1.0f/32767.0f; 325 coeffNeg[i] = 1.0f/32768.0f; 326 zero[i] = 0; 327 } 328 329 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 330 if (!cont) 331 { 332 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffPos", coeffPos); 333 getIdentifier()->addConfigValueContainer("CoeffPos", cont); 334 } 335 cont->getValue(&coeffPos); 336 337 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 338 if (!cont) 339 { 340 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffNeg", coeffNeg); 341 getIdentifier()->addConfigValueContainer("CoeffNeg", cont); 342 } 343 cont->getValue(&coeffNeg); 344 345 cont = getIdentifier()->getConfigValueContainer("Zero"); 346 if (!cont) 347 { 348 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "Zero", zero); 349 getIdentifier()->addConfigValueContainer("Zero", cont); 350 } 351 cont->getValue(&zero); 352 353 // copy values to our own variables 354 for (unsigned int i = 0; i < 24; i++) 355 { 356 joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i]; 357 joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i]; 358 joySticksCalibration_[0].zeroStates[i] = zero[i]; 359 } 360 } 288 361 } 289 362 … … 305 378 if (keyDetector_) 306 379 delete keyDetector_; 380 381 if (calibratorCallback_) 382 delete calibratorCallback_; 307 383 308 384 keyHandlers_.clear(); … … 313 389 _destroyMouse(); 314 390 _destroyJoySticks(); 391 392 activeHandlers_.clear(); 315 393 316 394 // inputSystem_ can never be 0, or else the code is mistaken … … 367 445 activeJoyStickHandlers_.clear(); 368 446 joyStickButtonsDown_.clear(); 447 povStates_.clear(); 448 sliderStates_.clear(); 449 joySticksCalibration_.clear(); 369 450 } 370 451 CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl; … … 423 504 if (state_ != stateRequest_) 424 505 { 425 if (stateRequest_ != IS_CUSTOM) 426 { 427 if (stateRequest_ != IS_DETECT) 506 InputState sr = stateRequest_; 507 switch (sr) 508 { 509 case IS_NORMAL: 510 activeKeyHandlers_.clear(); 511 activeMouseHandlers_.clear(); 512 for (unsigned int i = 0; i < joySticksSize_; i++) 513 activeJoyStickHandlers_[i].clear(); 514 515 // normal play mode 516 // note: we assume that the handlers exist since otherwise, something's wrong anyway. 517 enableKeyHandler("keybinder"); 518 enableMouseHandler("keybinder"); 519 enableJoyStickHandler("keybinder", 0); 520 stateRequest_ = IS_NORMAL; 521 state_ = IS_NORMAL; 522 break; 523 524 case IS_GUI: 525 state_ = IS_GUI; 526 break; 527 528 case IS_CONSOLE: 529 activeKeyHandlers_.clear(); 530 activeMouseHandlers_.clear(); 531 for (unsigned int i = 0; i < joySticksSize_; i++) 532 activeJoyStickHandlers_[i].clear(); 533 534 enableMouseHandler("keybinder"); 535 enableJoyStickHandler("keybinder", 0); 536 enableKeyHandler("buffer"); 537 stateRequest_ = IS_CONSOLE; 538 state_ = IS_CONSOLE; 539 break; 540 541 case IS_DETECT: 542 savedState_ = state_; 543 _saveState(); 544 545 activeKeyHandlers_.clear(); 546 activeMouseHandlers_.clear(); 547 for (unsigned int i = 0; i < joySticksSize_; i++) 548 activeJoyStickHandlers_[i].clear(); 549 550 enableKeyHandler("keydetector"); 551 enableMouseHandler("keydetector"); 552 enableJoyStickHandler("keydetector", 0); 553 554 stateRequest_ = IS_DETECT; 555 state_ = IS_DETECT; 556 break; 557 558 case IS_NODETECT: 559 _restoreState(); 560 state_ = IS_NODETECT; 561 stateRequest_ = savedState_; 562 break; 563 564 case IS_CALIBRATE: 565 if (joySticksSize_) 428 566 { 567 savedState_ = _getSingleton().state_; 568 for (unsigned int i = 0; i < 24; i++) 569 { 570 marginalsMax_[i] = INT_MIN; 571 marginalsMin_[i] = INT_MAX; 572 } 573 COUT(3) << "Move all joy stick axes in all directions a few times. " 574 << "Then put all axes in zero state and hit enter." << std::endl; 575 576 savedState_ = state_; 577 _saveState(); 578 429 579 activeKeyHandlers_.clear(); 430 580 activeMouseHandlers_.clear(); 431 581 for (unsigned int i = 0; i < joySticksSize_; i++) 432 582 activeJoyStickHandlers_[i].clear(); 583 584 enableKeyHandler("calibratorcallback"); 585 stateRequest_ = IS_CALIBRATE; 586 state_ = IS_CALIBRATE; 433 587 } 434 435 switch (stateRequest_) 588 else 436 589 { 437 case IS_NORMAL: 438 // normal play mode 439 // note: we assume that the handlers exist since otherwise, something's wrong anyway. 440 enableKeyHandler("keybinder"); 441 enableMouseHandler("keybinder"); 442 enableJoyStickHandler("keybinder", 0); 443 break; 444 445 case IS_GUI: 446 break; 447 448 case IS_CONSOLE: 449 enableMouseHandler("keybinder"); 450 enableJoyStickHandler("keybinder", 0); 451 enableKeyHandler("buffer"); 452 break; 453 454 case IS_DETECT: 455 savedState_ = state_; 456 _saveState(); 457 458 activeKeyHandlers_.clear(); 459 activeMouseHandlers_.clear(); 460 for (unsigned int i = 0; i < joySticksSize_; i++) 461 activeJoyStickHandlers_[i].clear(); 462 463 enableKeyHandler("keydetector"); 464 enableMouseHandler("keydetector"); 465 enableJoyStickHandler("keydetector", 0); 466 break; 467 468 case IS_NODETECT: 469 _restoreState(); 470 break; 471 472 default: 473 break; 590 COUT(3) << "Connot calibrate, no joy stick found!" << std::endl; 591 stateRequest_ = state_; 474 592 } 475 476 if (stateRequest_ == IS_NODETECT) 477 state_ = savedState_; 478 else 479 state_ = stateRequest_; 593 break; 594 595 case IS_NOCALIBRATE: 596 _completeCalibration(); 597 _restoreState(); 598 state_ = IS_NOCALIBRATE; 599 stateRequest_ = savedState_; 600 break; 601 602 case IS_NONE: 603 activeKeyHandlers_.clear(); 604 activeMouseHandlers_.clear(); 605 for (unsigned int i = 0; i < joySticksSize_; i++) 606 activeJoyStickHandlers_[i].clear(); 607 state_ = IS_NONE; 608 609 default: 610 break; 480 611 } 481 612 } … … 489 620 joySticks_[i]->capture(); 490 621 491 492 // call all the handlers for the held key events 493 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 494 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 495 activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 496 497 // call all the handlers for the held mouse button events 498 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 499 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 500 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); 501 502 // call all the handlers for the held joy stick button events 503 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 504 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 505 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 506 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 507 622 if (state_ != IS_CALIBRATE) 623 { 624 // call all the handlers for the held key events 625 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 626 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 627 activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 628 629 // call all the handlers for the held mouse button events 630 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 631 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 632 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); 633 634 // call all the handlers for the held joy stick button events 635 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 636 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 637 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 638 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 639 } 508 640 509 641 // call the ticks for the handlers (need to be treated specially) 510 642 for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++) 511 643 activeHandlers_[iHandler].first->tickInput(dt, activeHandlers_[iHandler].second); 512 513 /*for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 514 activeKeyHandlers_[iHandler]->tickKey(dt); 515 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 516 activeMouseHandlers_[iHandler]->tickMouse(dt); 517 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 518 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 519 activeJoyStickHandlers_[iJoyStick][iHandler]->tickJoyStick(dt);*/ 644 } 645 646 void InputManager::_completeCalibration() 647 { 648 for (unsigned int i = 0; i < 24; i++) 649 { 650 // positive coefficient 651 if (marginalsMax_[i] == INT_MIN) 652 marginalsMax_[i] = 32767; 653 // coefficients 654 if (marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]) 655 joySticksCalibration_[0].positiveCoeff[i] = 1.0f/(marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]); 656 else 657 joySticksCalibration_[0].positiveCoeff[i] = 1.0f; 658 659 // config value 660 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 661 assert(cont); 662 cont->set(getConvertedValue<int, std::string>(i) + " " 663 + getConvertedValue<float, std::string>(joySticksCalibration_[0].positiveCoeff[i])); 664 665 // negative coefficient 666 if (marginalsMin_[i] == INT_MAX) 667 marginalsMin_[i] = -32768; 668 // coefficients 669 if (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]) 670 joySticksCalibration_[0].negativeCoeff[i] = -1.0f/(marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]); 671 else 672 joySticksCalibration_[0].negativeCoeff[i] = 1.0f; 673 // config value 674 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 675 assert(cont); 676 cont->set(getConvertedValue<int, std::string>(i) + " " 677 + getConvertedValue<float, std::string>(joySticksCalibration_[0].negativeCoeff[i])); 678 679 // zero states 680 if (i < 8) 681 { 682 if (!(i & 1)) 683 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abX; 684 else 685 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abY; 686 } 687 else 688 { 689 if (i - 8 < joySticks_[0]->getJoyStickState().mAxes.size()) 690 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mAxes[i - 8].abs; 691 else 692 joySticksCalibration_[0].zeroStates[i] = 0; 693 } 694 // config value 695 cont = getIdentifier()->getConfigValueContainer("Zero"); 696 assert(cont); 697 cont->set(getConvertedValue<int, std::string>(i) + " " 698 + getConvertedValue<int, std::string>(joySticksCalibration_[0].zeroStates[i])); 699 } 520 700 } 521 701 … … 652 832 // ###### Joy Stick Events ###### 653 833 654 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)834 inline unsigned int InputManager::_getJoystick(const OIS::JoyStickEvent& arg) 655 835 { 656 836 // use the device to identify which one called the method … … 658 838 unsigned int iJoyStick = 0; 659 839 while (joySticks_[iJoyStick] != joyStick) 840 { 660 841 iJoyStick++; 842 if (iJoyStick == joySticksSize_) 843 { 844 CCOUT(3) << "Unknown joystick fired an event. This means there is a bug somewhere! Aborting." << std::endl; 845 abort(); 846 } 847 } 848 return iJoyStick; 849 } 850 851 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button) 852 { 853 unsigned int iJoyStick = _getJoystick(arg); 661 854 662 855 // check whether the button already is in the list (can happen when focus was lost) … … 676 869 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button) 677 870 { 678 // use the device to identify which one called the method 679 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 680 unsigned int iJoyStick = 0; 681 while (joySticks_[iJoyStick] != joyStick) 682 iJoyStick++; 871 unsigned int iJoyStick = _getJoystick(arg); 683 872 684 873 // remove the button from the joyStickButtonsDown_ list … … 699 888 } 700 889 890 void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value) 891 { 892 if (state_ == IS_CALIBRATE) 893 { 894 if (value > marginalsMax_[axis]) 895 marginalsMax_[axis] = value; 896 if (value < marginalsMin_[axis]) 897 marginalsMin_[axis] = value; 898 } 899 else 900 { 901 float fValue = value - joySticksCalibration_[iJoyStick].zeroStates[axis]; 902 if (fValue > 0.0f) 903 fValue *= joySticksCalibration_[iJoyStick].positiveCoeff[axis]; 904 else 905 fValue *= joySticksCalibration_[iJoyStick].negativeCoeff[axis]; 906 907 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 908 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis, fValue); 909 } 910 } 911 701 912 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 702 913 { 703 914 //if (arg.state.mAxes[axis].abs > 10000 || arg.state.mAxes[axis].abs < -10000) 704 915 //{ CCOUT(3) << "axis " << axis << " moved" << arg.state.mAxes[axis].abs << std::endl;} 705 // use the device to identify which one called the method 706 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 707 unsigned int iJoyStick = 0; 708 while (joySticks_[iJoyStick] != joyStick) 709 iJoyStick++; 916 917 unsigned int iJoyStick = _getJoystick(arg); 710 918 711 919 // keep in mind that the first 8 axes are reserved for the sliders 712 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 713 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs); 920 _fireAxis(iJoyStick, axis + 8, arg.state.mAxes[axis].abs); 714 921 715 922 return true; … … 721 928 //{CCOUT(3) << "slider " << id << " moved" << arg.state.mSliders[id].abX << std::endl;} 722 929 //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl; 723 // use the device to identify which one called the method 724 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 725 unsigned int iJoyStick = 0; 726 while (joySticks_[iJoyStick] != joyStick) 727 iJoyStick++; 930 931 unsigned int iJoyStick = _getJoystick(arg); 728 932 729 933 if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX) 730 { 731 // slider X axis changed 732 sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX; 733 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 734 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX); 735 } 934 _fireAxis(iJoyStick, id * 2, arg.state.mSliders[id].abX); 736 935 else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY) 737 { 738 // slider Y axis changed 739 sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY; 740 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 741 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY); 742 } 936 _fireAxis(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY); 743 937 744 938 return true; … … 747 941 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 748 942 { 749 // use the device to identify which one called the method 750 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 751 unsigned int iJoyStick = 0; 752 while (joySticks_[iJoyStick] != joyStick) 753 iJoyStick++; 943 unsigned int iJoyStick = _getJoystick(arg); 754 944 755 945 // translate the POV into 8 simple buttons … … 765 955 766 956 povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction; 957 767 958 int currentState = povStates_[iJoyStick][id]; 768 959 if (currentState & OIS::Pov::North) … … 780 971 /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 781 972 { 782 // use the device to identify which one called the method 783 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 784 unsigned int iJoyStick = 0; 785 while (joySticks_[iJoyStick] != joyStick) 786 iJoyStick++; 973 unsigned int iJoyStick = _getJoystick(arg); 787 974 788 975 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) … … 943 1130 bindingCommmandString_s = command; 944 1131 setInputState(IS_DETECT); 1132 COUT(3) << "Press any button/key or move a mouse/joystick axis" << std::endl; 1133 } 1134 1135 void InputManager::calibrate() 1136 { 1137 _getSingleton().setInputState(IS_CALIBRATE); 945 1138 } 946 1139 -
code/branches/network/src/core/InputManager.h
r1428 r1444 76 76 std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_; 77 77 std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_; 78 }; 79 80 struct JoyStickCalibration 81 { 82 int zeroStates[24]; 83 float positiveCoeff[24]; 84 float negativeCoeff[24]; 78 85 }; 79 86 … … 98 105 IS_DETECT, //!< All the input additionally goes to the KeyDetector 99 106 IS_NODETECT, //!< remove KeyDetector 107 IS_NOCALIBRATE, 108 IS_CALIBRATE, 100 109 IS_CUSTOM //!< Any possible configuration. 101 110 }; 111 112 public: // member functions 113 void setConfigValues(); 102 114 103 115 public: // static functions … … 129 141 static void keyBind(const std::string& command); 130 142 143 static void calibrate(); 144 131 145 static bool addKeyHandler (KeyHandler* handler, const std::string& name); 132 146 static bool removeKeyHandler (const std::string& name); … … 171 185 void _saveState(); 172 186 void _restoreState(); 187 188 void _completeCalibration(); 189 190 void _fireAxis(unsigned int iJoyStick, int axis, int value); 191 unsigned int _getJoystick(const OIS::JoyStickEvent& arg); 173 192 174 193 void tick(float dt); … … 200 219 KeyDetector* keyDetector_; //!< KeyDetector instance 201 220 InputBuffer* buffer_; //!< InputBuffer instance 221 CalibratorCallback* calibratorCallback_; 202 222 203 223 InputState state_; 204 224 InputState stateRequest_; 225 InputState savedState_; 205 226 unsigned int keyboardModifiers_; 206 InputState savedState_;207 227 StoredState savedHandlers_; 228 229 // joystick calibration 230 //std::vector<int> marginalsMaxConfig_; 231 //std::vector<int> marginalsMinConfig_; 232 int marginalsMax_[24]; 233 int marginalsMin_[24]; 234 bool bCalibrated_; 208 235 209 236 //! Keeps track of the joy stick POV states … … 211 238 //! Keeps track of the possibly two slider axes 212 239 std::vector<SliderStates> sliderStates_; 240 std::vector<JoyStickCalibration> joySticksCalibration_; 213 241 214 242 std::map<std::string, KeyHandler*> keyHandlers_; -
code/branches/network/src/core/KeyBinder.cc
r1428 r1444 34 34 #include "KeyBinder.h" 35 35 #include <fstream> 36 #include <limits.h> 36 37 #include "util/Convert.h" 37 38 #include "util/SubString.h" … … 42 43 #include "CommandExecutor.h" 43 44 #include "Executor.h" 45 // TODO: only needed by the CalibratorCallback class; move to new file 46 #include "InputManager.h" 44 47 45 48 namespace orxonox … … 805 808 } 806 809 807 void KeyBinder::joyStickAxisMoved(int joyStickID, int axis, int value)810 void KeyBinder::joyStickAxisMoved(int joyStickID, int axis, float value) 808 811 { 809 812 // TODO: Use proper calibration values instead of generally 16-bit integer … … 814 817 //{ CCOUT(3) << halfAxes_[i].name_ << std::endl; } 815 818 816 halfAxes_[i].absVal_ = ((float)value)/0x8000;817 halfAxes_[i].relVal_ = ((float)value)/0x8000;819 halfAxes_[i].absVal_ = value; 820 halfAxes_[i].relVal_ = value; 818 821 halfAxes_[i].hasChanged_ = true; 819 if (halfAxes_[i + 1].absVal_ > 0 )822 if (halfAxes_[i + 1].absVal_ > 0.0f) 820 823 { 821 824 halfAxes_[i + 1].absVal_ = -0.0f; … … 829 832 //{ CCOUT(3) << halfAxes_[i + 1].name_ << std::endl; } 830 833 831 halfAxes_[i + 1].absVal_ = - ((float)value)/0x8000;832 halfAxes_[i + 1].relVal_ = - ((float)value)/0x8000;834 halfAxes_[i + 1].absVal_ = -value; 835 halfAxes_[i + 1].relVal_ = -value; 833 836 halfAxes_[i + 1].hasChanged_ = true; 834 if (halfAxes_[i].absVal_ > 0 )837 if (halfAxes_[i].absVal_ > 0.0f) 835 838 { 836 839 halfAxes_[i].absVal_ = -0.0f; … … 879 882 button.nCommands_[KeybindMode::OnPress] = 1; 880 883 } 881 884 885 886 // ############################### 887 // ##### CalibratorCallback ##### 888 // ############################### 889 890 void CalibratorCallback::keyPressed(const orxonox::KeyEvent &evt) 891 { 892 if (evt.key == KeyCode::Return) 893 { 894 InputManager::setInputState(InputManager::IS_NOCALIBRATE); 895 } 896 } 882 897 } -
code/branches/network/src/core/KeyBinder.h
r1428 r1444 165 165 void joyStickButtonReleased(int joyStickID, int button); 166 166 void joyStickButtonHeld (int joyStickID, int button); 167 void joyStickAxisMoved (int joyStickID, int axis, int value);167 void joyStickAxisMoved (int joyStickID, int axis, float value); 168 168 169 169 protected: // variables … … 192 192 * 0 - 3: Mouse x and y 193 193 * 4 - 7: empty 194 * 8 - 23: joy stick (slider)axes 1 to 8194 * 8 - 23: joy stick slider axes 1 to 8 195 195 * 24 - 55: joy stick axes 1 - 16 196 196 */ … … 237 237 void readTrigger(Button& button); 238 238 }; 239 240 class _CoreExport CalibratorCallback : public KeyHandler 241 { 242 public: 243 CalibratorCallback() {} 244 ~CalibratorCallback() {} 245 246 private: 247 void keyPressed (const KeyEvent& evt); 248 void keyReleased(const KeyEvent& evt) {} 249 void keyHeld (const KeyEvent& evt) {} 250 251 void tickInput(float dt, const HandlerState &state) { } 252 }; 239 253 } 240 254 -
code/branches/network/src/orxonox/hud/Navigation.cc
r1411 r1444 125 125 // top right quadrant 126 126 if(-phiNav<phiUpperCorner){ 127 COUT(3) << "arrow up\n";127 //COUT(3) << "arrow up\n"; 128 128 navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, 0); 129 129 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); … … 132 132 } 133 133 else { 134 COUT(3) << "arrow right\n";134 //COUT(3) << "arrow right\n"; 135 135 navMarker_->setPosition(windowW_-16, tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2); 136 136 navMarker_->setUV(0.5, 0.5, 1.0, 1.0); … … 142 142 // bottom right quadrant 143 143 if(phiNav<phiUpperCorner) { 144 COUT(3) << "arrow down\n";144 //COUT(3) << "arrow down\n"; 145 145 navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, windowH_-16); 146 146 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); … … 149 149 } 150 150 else { 151 COUT(3) << "arrow right\n";151 //COUT(3) << "arrow right\n"; 152 152 navMarker_->setPosition(windowW_-16, tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2); 153 153 navMarker_->setUV(0.5, 0.5, 1.0, 1.0); … … 159 159 // top left quadrant 160 160 if(phiNav<phiUpperCorner){ 161 COUT(3) << "arrow up\n";161 //COUT(3) << "arrow up\n"; 162 162 navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, 0); 163 163 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); … … 166 166 } 167 167 else { 168 COUT(3) << "arrow left\n";168 //COUT(3) << "arrow left\n"; 169 169 navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2); 170 170 navMarker_->setUV(0.0, 0.0, 0.5, 0.5); … … 176 176 // bottom left quadrant 177 177 if(phiNav>-phiUpperCorner) { 178 COUT(3) << "arrow down\n";178 //COUT(3) << "arrow down\n"; 179 179 navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, windowH_-16); 180 180 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); … … 183 183 } 184 184 else { 185 COUT(3) << "arrow left\n";185 //COUT(3) << "arrow left\n"; 186 186 navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2); 187 187 navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
Note: See TracChangeset
for help on using the changeset viewer.