------------------------------------------------------------------------------
| 520 | |
| 521 | //------------------------------------------------------------------------------ |
| 522 | bool DInputManager::rumble( const char *pDeviceName, F32 x, F32 y ) |
| 523 | { |
| 524 | // Determine the device |
| 525 | U32 deviceType; |
| 526 | U32 deviceInst; |
| 527 | |
| 528 | // Find the requested device |
| 529 | if ( !ActionMap::getDeviceTypeAndInstance(pDeviceName, deviceType, deviceInst) ) |
| 530 | { |
| 531 | Con::printf("DInputManager::rumble: unknown device: %s", pDeviceName); |
| 532 | return false; |
| 533 | } |
| 534 | |
| 535 | // clamp (x, y) to the range of [0 ... 1] each |
| 536 | x = mClampF(x, 0.f, 1.f); |
| 537 | y = mClampF(y, 0.f, 1.f); |
| 538 | |
| 539 | // Easy path for xinput devices. |
| 540 | if(deviceType == GamepadDeviceType) |
| 541 | { |
| 542 | XINPUT_VIBRATION vibration; |
| 543 | vibration.wLeftMotorSpeed = static_cast<int>(x * 65535); |
| 544 | vibration.wRightMotorSpeed = static_cast<int>(y * 65535); |
| 545 | return ( mfnXInputSetState(deviceInst, &vibration) == ERROR_SUCCESS ); |
| 546 | } |
| 547 | |
| 548 | switch ( deviceType ) |
| 549 | { |
| 550 | case JoystickDeviceType: |
| 551 | |
| 552 | // Find the device and shake it! |
| 553 | DInputDevice* dptr; |
| 554 | for ( iterator ptr = begin(); ptr != end(); ptr++ ) |
| 555 | { |
| 556 | dptr = dynamic_cast<DInputDevice*>( *ptr ); |
| 557 | if ( dptr ) |
| 558 | { |
| 559 | if (deviceType == dptr->getDeviceType() && deviceInst == dptr->getDeviceID()) |
| 560 | { |
| 561 | dptr->rumble(x, y); |
| 562 | return true; |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | // We should never get here... something's really messed up |
| 568 | Con::errorf( "DInputManager::rumbleJoystick - Couldn't find device to rumble! This should never happen!\n" ); |
| 569 | return false; |
| 570 | |
| 571 | default: |
| 572 | Con::printf("DInputManager::rumble - only supports joystick and xinput/gamepad devices"); |
| 573 | return false; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | void DInputManager::buildXInputEvent( U32 deviceInst, InputEventType objType, InputObjectInstances objInst, InputActionType action, F32 fValue ) |
| 578 | { |
no test coverage detected