Changeset 1344
- Timestamp:
- May 21, 2008, 6:26:15 PM (17 years ago)
- Location:
- code/branches/input
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/bin/keybindings.ini
r1340 r1344 154 154 MouseButton6= 155 155 MouseButton7= 156 MouseXPos=exit | ButtonThreshold 0.85 156 MouseWheel1Up=AxisAmp 0.1 slomo 157 MouseWheel1Down=AxisAmp 0.1 slomo 158 MouseWheel2Up= 159 MouseWheel2Down= 160 MouseXPos= #exit | ButtonThreshold 0.85 157 161 MouseXNeg= 158 162 MouseYPos= 159 163 MouseYNeg= 160 MouseWheel1Pos=161 MouseWheel1Neg=162 MouseWheel2Pos=163 MouseWheel2Neg=164 Empty1Pos= 165 Empty1Neg= 166 Empty2Pos= 167 Empty2Neg= 164 168 JoyAxis1Pos= 165 169 JoyAxis1Neg= -
code/branches/input/src/core/InputHandler.cc
r1340 r1344 72 72 BufferedParamCommand& paramCommand = *paramCommand_; 73 73 // command has an additional parameter 74 if (bRelative_ )74 if (bRelative_ && (rel > 0 || rel < 0)) 75 75 { 76 76 // we have to calculate a relative movement. 77 // amplitudesays how much one keystroke is77 // paramModifier_ says how much one keystroke is 78 78 paramCommand.value_ += paramModifier_ * rel; 79 79 } 80 else 80 else if (abs > 0 || abs < 0) 81 81 { 82 82 // we have to calculate absolute position of the axis. 83 // for a key this simply is 1, but multiplied by a user defined factor 84 // since there might be another axis that is affected, we have to wait and 83 // Since there might be another axis that is affected, we have to wait and 85 84 // store the result in a temporary place 86 85 paramCommand.value_ = (paramCommand.value_ * paramCommand.nValuesAdded_ + paramModifier_ * abs) … … 254 253 } 255 254 256 bool Button::execute(KeybindMode::Enum mode )255 bool Button::execute(KeybindMode::Enum mode, float abs, float rel) 257 256 { 258 257 // execute all the parsed commands in the string 259 258 for (unsigned int iCommand = 0; iCommand < nCommands_[mode]; iCommand++) 260 commands_[mode][iCommand]->execute( );259 commands_[mode][iCommand]->execute(abs, rel); 261 260 return true; 262 261 } … … 306 305 @brief Constructor that does as little as necessary. 307 306 */ 308 KeyBinder::KeyBinder() 307 KeyBinder::KeyBinder() : deriveTime_(0.0f) 309 308 { 310 309 RegisterObject(KeyBinder); … … 413 412 "MouseLeft", "MouseRight", "MouseMiddle", 414 413 "MouseButton3", "MouseButton4", "MouseButton5", 415 "MouseButton6", "MouseButton7" }; 414 "MouseButton6", "MouseButton7", 415 "MouseWheel1Up", "MouseWheel1Down", 416 "MouseWheel2Up", "MouseWheel2Down" }; 416 417 for (int i = 0; i < nMouseButtons_s; i++) 417 418 mouseButtons_[i].name_ = mouseButtonNames[i]; … … 432 433 rawNames[0] = "MouseX"; 433 434 rawNames[1] = "MouseY"; 434 rawNames[2] = " MouseWheel1";435 rawNames[3] = " MouseWheel2";435 rawNames[2] = "Empty1"; 436 rawNames[3] = "Empty2"; 436 437 for (unsigned int i = 4; i < nHalfAxes_s/2; i++) 437 438 rawNames[i] = "JoyAxis" + getConvertedValue<int, std::string>(i - 3); … … 475 476 void KeyBinder::setConfigValues() 476 477 { 477 SetConfigValue(analogThreshold_, 0.01f).description("Threshold for analog axes until which the state is 0."); 478 SetConfigValue(analogThreshold_, 0.01f) .description("Threshold for analog axes until which the state is 0."); 479 SetConfigValue(bDeriveMouseInput_, false).description("Whether or not to derive moues movement for the absolute value."); 480 SetConfigValue(derivePeriod_, 0.1f) .description("Accuracy of the mouse input deriver. The higher the more precise, but laggier."); 481 SetConfigValue(mouseSensitivity_, 1.0f) .description("Mouse sensitivity."); 482 478 483 float oldThresh = buttonThreshold_; 479 484 SetConfigValue(buttonThreshold_, 0.80f).description("Threshold for analog axes until which the button is not pressed."); … … 573 578 } 574 579 580 if (bDeriveMouseInput_) 581 { 582 if (deriveTime_ > derivePeriod_) 583 { 584 deriveTime_ = 0.0f; 585 CCOUT(3) << "mouse abs: "; 586 for (int i = 0; i < 2; i++) 587 { 588 if (mouseRelative_[i] > 0) 589 { 590 halfAxes_[2*i + 0].absVal_ = mouseRelative_[i] * derivePeriod_ / 500; 591 halfAxes_[2*i + 1].absVal_ = 0.0f; 592 } 593 else if (mouseRelative_[0] < 0) 594 { 595 halfAxes_[2*i + 0].absVal_ = 0.0f; 596 halfAxes_[2*i + 1].absVal_ = -mouseRelative_[i] * derivePeriod_ / 500; 597 } 598 COUT(3) << mouseRelative_[i] << " | "; 599 mouseRelative_[i] = 0.0f; 600 } 601 COUT(3) << std::endl; 602 } 603 else 604 deriveTime_ += dt; 605 } 606 575 607 // execute all buffered bindings (addional parameter) 576 608 for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++) … … 578 610 579 611 // always reset the relative movement of the mouse 580 for (unsigned int i = 0; i < 4; i++)581 halfAxes_[i].relVal_ = 0 ;612 for (unsigned int i = 0; i < 8; i++) 613 halfAxes_[i].relVal_ = 0.0f; 582 614 } 583 615 … … 615 647 @param e Mouse state information 616 648 */ 617 void KeyBinder::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) 618 { 619 // translate absolute mouse position into joystick like behaviour 620 if (clippingSize.x > clippingSize.y) 621 { 622 int margin = (clippingSize.x - clippingSize.y) / 2; 623 if (abs.x - margin > clippingSize.y) 649 void KeyBinder::mouseMoved(IntVector2 abs_, IntVector2 rel_, IntVector2 clippingSize) 650 { 651 if (!bDeriveMouseInput_) 652 { 653 // y axis of mouse input is inverted 654 int rel[] = { rel_.x * mouseSensitivity_, -rel_.y * mouseSensitivity_ }; 655 656 COUT(3) << rel[0] << " | " << rel[1] << std::endl; 657 658 for (int i = 0; i < 2; i++) 624 659 { 625 halfAxes_[0].absVal_ = 1.0f; 626 halfAxes_[1].absVal_ = 0.0f; 627 } 628 else if (abs.x < margin) 629 { 630 halfAxes_[0].absVal_ = 0.0f; 631 halfAxes_[1].absVal_ = 1.0f; 632 } 633 else 634 { 635 float temp = ((float)abs.x) / clippingSize.y * 2 - 1; 636 if (temp > 0) 660 if (rel[i]) 637 661 { 638 halfAxes_[0].absVal_ = temp; 639 halfAxes_[1].absVal_ = 0.0f; 640 } 641 else 642 { 643 halfAxes_[0].absVal_ = 0.0f; 644 halfAxes_[1].absVal_ = -temp; 662 // absolute 663 if (mousePosition_[i] >= 0) 664 { 665 mousePosition_[i] += rel[i]; 666 halfAxes_[0 + 2*i].hasChanged_ = true; 667 if (mousePosition_[i] < 0) 668 { 669 halfAxes_[1 + 2*i].hasChanged_ = true; 670 halfAxes_[1 + 2*i].absVal_ = -((float)mousePosition_[i])/1024; 671 halfAxes_[0 + 2*i].absVal_ = 0.0f; 672 } 673 else 674 halfAxes_[1 + 2*i].absVal_ = ((float)mousePosition_[i])/1024; 675 } 676 else 677 { 678 mousePosition_[i] += rel[i]; 679 halfAxes_[1 + 2*i].hasChanged_ = true; 680 if (mousePosition_[i] > 0) 681 { 682 halfAxes_[0 + 2*i].hasChanged_ = true; 683 halfAxes_[0 + 2*i].absVal_ = ((float)mousePosition_[i])/1024; 684 halfAxes_[1 + 2*i].absVal_ = 0.0f; 685 } 686 else 687 halfAxes_[1 + 2*i].absVal_ = -((float)mousePosition_[i])/1024; 688 } 689 690 // relative 691 if (rel[i] > 0) 692 halfAxes_[0 + 2*i].relVal_ = ((float)rel[i])/1024; 693 else 694 halfAxes_[1 + 2*i].relVal_ = -((float)rel[i])/1024; 645 695 } 646 696 } 647 648 float temp = -((float)abs.y) / clippingSize.y * 2 + 1;649 if (temp > 0)650 {651 halfAxes_[2].absVal_ = temp;652 halfAxes_[3].absVal_ = 0.0;653 }654 else655 {656 halfAxes_[2].absVal_ = 0.0;657 halfAxes_[3].absVal_ = -temp;658 }659 697 } 660 698 else 661 699 { 662 float temp = ((float)abs.x) / clippingSize.x * 2 - 1; 663 if (temp > 0) 664 { 665 halfAxes_[0].absVal_ = temp; 666 halfAxes_[1].absVal_ = 0.0; 667 } 668 else 669 { 670 halfAxes_[0].absVal_ = 0.0; 671 halfAxes_[1].absVal_ = -temp; 672 } 673 674 int margin = (clippingSize.y - clippingSize.x) / 2; 675 if (abs.y - margin > clippingSize.x) 676 { 677 halfAxes_[2].absVal_ = 0.0; 678 halfAxes_[3].absVal_ = 1.0; 679 } 680 else if (abs.y < margin) 681 { 682 halfAxes_[2].absVal_ = 1.0; 683 halfAxes_[3].absVal_ = 0.0; 684 } 685 else 686 { 687 float temp = -((float)abs.y) / clippingSize.x * 2 + 1; 688 if (temp > 0) 689 { 690 halfAxes_[2].absVal_ = temp; 691 halfAxes_[3].absVal_ = 0.0; 692 } 693 else 694 { 695 halfAxes_[2].absVal_ = 0.0; 696 halfAxes_[3].absVal_ = -temp; 697 } 698 } 699 } 700 701 // relative movements 702 if (rel.x > 0) 703 { 704 halfAxes_[0].hasChanged_ = true; 705 halfAxes_[1].hasChanged_ = true; 706 halfAxes_[0].relVal_ = rel.x; 707 halfAxes_[1].relVal_ = 0.0; 708 } 709 else if (rel.x < 0) 710 { 711 halfAxes_[0].hasChanged_ = true; 712 halfAxes_[1].hasChanged_ = true; 713 halfAxes_[0].relVal_ = 0.0; 714 halfAxes_[1].relVal_ = rel.x; 715 } 716 717 if (rel.y /*!*/ < /*!*/ 0) 718 { 719 halfAxes_[2].hasChanged_ = true; 720 halfAxes_[3].hasChanged_ = true; 721 halfAxes_[0].relVal_ = -rel.y; 722 halfAxes_[1].relVal_ = 0.0; 723 } 724 else if (rel.y > 0) 725 { 726 halfAxes_[2].hasChanged_ = true; 727 halfAxes_[3].hasChanged_ = true; 728 halfAxes_[0].relVal_ = 0.0; 729 halfAxes_[1].relVal_ = -rel.y; 700 mouseRelative_[0] += rel_.x * mouseSensitivity_; 701 mouseRelative_[1] -= rel_.y * mouseSensitivity_; 730 702 } 731 703 } … … 737 709 void KeyBinder::mouseScrolled(int abs, int rel) 738 710 { 739 // TODO: obvious... 711 COUT(3) << mouseButtons_[8].name_ << " " << abs << " | " << rel << std::endl; 712 713 if (rel > 0) 714 for (int i = 0; i < rel/120; i++) 715 mouseButtons_[8].execute(KeybindMode::OnPress, ((float)abs)/120.0f); 716 else 717 for (int i = 0; i < -rel/120; i++) 718 mouseButtons_[9].execute(KeybindMode::OnPress, ((float)abs)/120.0f); 740 719 } 741 720 … … 743 722 { 744 723 // TODO: check whether 16 bit integer as general axis value is a good idea (works under windows) 745 //CCOUT(3) << axis<< std::endl;724 CCOUT(3) << halfAxes_[8 + axis].name_ << std::endl; 746 725 if (value >= 0) 747 726 { -
code/branches/input/src/core/InputHandler.h
r1340 r1344 60 60 BufferedParamCommand() : value_(0.0f), nValuesAdded_(0), paramIndex_(-1) { } 61 61 bool execute(); 62 62 63 float value_; 63 64 unsigned int nValuesAdded_; … … 93 94 virtual bool addParamCommand(ParamCommand* command) { return false; } 94 95 void parse(std::vector<BufferedParamCommand*>& paramCommandBuffer); 95 bool execute(KeybindMode::Enum mode );96 bool execute(KeybindMode::Enum mode, float abs = 1.0f, float rel = 1.0f); 96 97 97 98 //! The configured string value … … 114 115 HalfAxis() : relVal_(0.0f), absVal_(0.0f), paramCommands_(0), nParamCommands_(0), 115 116 wasDown_(false), hasChanged_(false) { } 117 using Button::execute; 116 118 bool execute(); 117 bool execute(KeybindMode::Enum mode) { return Button::execute(mode); }119 //bool execute(KeybindMode::Enum mode) { return Button::execute(mode); } 118 120 bool addParamCommand(ParamCommand* command); 119 121 void clear(); … … 176 178 177 179 //! denotes the number of different mouse buttons there are in OIS. 178 static const unsigned int nMouseButtons_s = 8 ;180 static const unsigned int nMouseButtons_s = 8 + 2*2; // 8 buttons and 2 scroll wheels 179 181 //! Actual key bindings as bundle for Press, Hold and Release 180 182 Button mouseButtons_ [nMouseButtons_s]; … … 193 195 * Sequence is as follows: 194 196 * 0 - 3: Mouse x and y 195 * 4 - 7: Mouse scroll wheels 1 and 2 (2 not yet supported)197 * 4 - 7: empty 196 198 * 8 - 23: joy stick (slider) axes 1 to 8 197 199 * 24 - 55: joy stick axes 1 - 16 … … 205 207 std::vector<BufferedParamCommand*> paramCommandBuffer_; 206 208 209 //! Keeps track of the absolute mouse value (incl. scroll wheel) 210 int mousePosition_[3]; 211 //! Used to derive mouse input if requested 212 int mouseRelative_[2]; 213 float deriveTime_; 214 215 //**** ConfigValues *****\\ 207 216 //! Threshold for analog triggers until which the state is 0. 208 217 float analogThreshold_; 209 218 //! Threshold for analog triggers until which the button is not pressed. 210 219 float buttonThreshold_; 220 //! Derive mouse input for absolute values? 221 bool bDeriveMouseInput_; 222 //! Accuracy of the mouse input deriver. The higher the more precise, but laggier. 223 float derivePeriod_; 224 //! mouse sensitivity 225 float mouseSensitivity_; 211 226 }; 212 227 -
code/branches/input/src/util/Math.h
r1323 r1344 156 156 }; 157 157 158 class _UtilExport IntVector3 159 { 160 public: 161 IntVector3() : x(0), y(0), z(0) { } 162 IntVector3(int _x, int _y, int _z) : x(_x), y(_y), z(_z) { } 163 int x; 164 int y; 165 int z; 166 }; 167 158 168 #endif /* _Util_Math_H__ */
Note: See TracChangeset
for help on using the changeset viewer.