Changeset 2543 for code/branches/presentation/src/core/input/KeyBinder.cc
- Timestamp:
- Dec 28, 2008, 11:56:31 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/core/input/KeyBinder.cc
r2103 r2543 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)
Note: See TracChangeset
for help on using the changeset viewer.