diff --git a/README.md b/README.md index 5365f99..bf7b573 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,11 @@ Windows-only solution, but there are other solutions on Linux like MonadoVR. | `display_frequency` | `float` | The display refresh rate, in Hz. | `60.0` | | `pitch_enable` | `bool` | Enables or disables Controller right stick y-axis mapped to HMD Pitch | `false` | | `yaw_enable` | `bool` | Enables or disables Controller right stick x-axis mapped to HMD Yaw | `false` | +| `ctrl_toggle_key` | `string`| The [Virtual-Key Code](https://github.com/oneup03/VRto3D/blob/main/vrto3d/src/key_mappings.h) to toggle Pitch and Yaw emulation on/off when they are enabled | `XINPUT_GAMEPAD_RIGHT_THUMB` | | `ctrl_deadzone` | `float` | Controller Deadzone | `0.05` | | `ctrl_sensitivity` | `float` | Controller Sensitivity | `1.0` | | `num_user_settings` | `int` | The number of user settings defined below. | `3` | -| `user_load_key#` | `string`| The [Virtual-Key Code](https://github.com/oneup03/VRto3D/blob/main/vrto3d/src/key_mappings.h) to load user setting # (replace # with integer number) | `"VK_NUMPAD1"` | +| `user_load_key#` | `string`| The Virtual-Key Code to load user setting # (replace # with integer number) | `"VK_NUMPAD1"` | | `user_store_key#` | `string`| The Virtual-Key Code to store user setting # (replace # with integer number) | `"VK_NUMPAD4"` | | `user_key_type#` | `string`| The store key's behavior ("switch" "toggle" "hold") | `"switch"` | | `user_depth#` | `float` | The depth value for user setting # (replace # with integer number) | `0.5` | @@ -130,6 +131,8 @@ Windows-only solution, but there are other solutions on Linux like MonadoVR. - Recommend using a XInput controller - OpenXR games/mods seem to be more likely to work and be stable than OpenVR ones - Optional HMD pitch and yaw emulation can be turned on to help with games or mods that need it (maps to XInput right stick) + - The `ctrl_toggle_key` can be set and used to toggle these settings on/off in-game (only functions if `pitch_enable` and/or `yaw_enable` is set to true) +- HMD Height can be toggled between 0.1m and `hmd_height` using `Ctrl + F9`. This is useful for games that force a calibration on the "floor" - HDR doesn't seem to work currently - Several mods/games may override your settings - DLSS, TAA, and other temporal based settings often create a halo around objects. UEVR has a halo fix that lets you use TAA, but others may not diff --git a/vrto3d/src/hmd_device_driver.cpp b/vrto3d/src/hmd_device_driver.cpp index 033284f..4a73ae8 100644 --- a/vrto3d/src/hmd_device_driver.cpp +++ b/vrto3d/src/hmd_device_driver.cpp @@ -73,6 +73,7 @@ MockControllerDeviceDriver::MockControllerDeviceDriver() display_configuration.display_latency = vrs->GetFloat(stereo_display_settings_section, "display_latency"); display_configuration.display_frequency = vrs->GetFloat(stereo_display_settings_section, "display_frequency"); + display_configuration.sleep_count_max = (int)(floor(1600.0 / (1000.0 / display_configuration.display_frequency))); int32_t half_width = display_configuration.half_enable ? 1 : 2; if (display_configuration.tab_enable) @@ -89,6 +90,16 @@ MockControllerDeviceDriver::MockControllerDeviceDriver() // Controller settings display_configuration.pitch_enable = vrs->GetBool(stereo_display_settings_section, "pitch_enable"); display_configuration.yaw_enable = vrs->GetBool(stereo_display_settings_section, "yaw_enable"); + char ctrl_toggle_key[1024]; + vrs->GetString(stereo_display_settings_section, "ctrl_toggle_key", ctrl_toggle_key, sizeof(ctrl_toggle_key)); + if (VirtualKeyMappings.find(ctrl_toggle_key) != VirtualKeyMappings.end()) { + display_configuration.ctrl_toggle_key = VirtualKeyMappings[ctrl_toggle_key]; + display_configuration.ctrl_xinput = false; + } + else if (XInputMappings.find(ctrl_toggle_key) != XInputMappings.end()) { + display_configuration.ctrl_toggle_key = XInputMappings[ctrl_toggle_key]; + display_configuration.ctrl_xinput = true; + } display_configuration.ctrl_deadzone = vrs->GetFloat(stereo_display_settings_section, "ctrl_deadzone"); display_configuration.ctrl_sensitivity = vrs->GetFloat(stereo_display_settings_section, "ctrl_sensitivity"); @@ -345,6 +356,7 @@ vr::DriverPose_t MockControllerDeviceDriver::GetPose() void MockControllerDeviceDriver::PoseUpdateThread() { static int sleep_time = (int)(floor(1000.0 / stereo_display_component_->GetConfig().display_frequency)); + static int sleep_counter = 0; while ( is_active_ ) { // Inform the vrserver that our tracked device's pose has updated, giving it the pose returned by our GetPose(). @@ -370,6 +382,14 @@ void MockControllerDeviceDriver::PoseUpdateThread() if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_F7) & 0x8000)) { SaveDepthConv(); } + // Ctrl+F9 Toggle HMD height + if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_F9) & 0x8000) && sleep_counter == 0) { + sleep_counter = stereo_display_component_->GetConfig().sleep_count_max; + stereo_display_component_->SetHeight(); + } + else if (sleep_counter > 0) { + sleep_counter--; + } // Check User binds stereo_display_component_->CheckUserSettings(device_index_); @@ -627,12 +647,34 @@ float StereoDisplayComponent::GetConvergence() //----------------------------------------------------------------------------- void StereoDisplayComponent::CheckUserSettings(uint32_t device_index) { - static int sleep_count = (int)(floor(1600.0 / (1000.0 / config_.display_frequency))); + static bool pitch_set = config_.pitch_enable; + static bool yaw_set = config_.yaw_enable; + static int sleep_ctrl = 0; + XINPUT_STATE state; ZeroMemory(&state, sizeof(XINPUT_STATE)); // Get the state of the first controller (index 0) DWORD dwResult = XInputGetState(0, &state); + if (((config_.ctrl_xinput && dwResult == ERROR_SUCCESS && + ((config_.ctrl_toggle_key == XINPUT_GAMEPAD_LEFT_TRIGGER && state.Gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD) + || (config_.ctrl_toggle_key == XINPUT_GAMEPAD_RIGHT_TRIGGER && state.Gamepad.bRightTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD) + || (state.Gamepad.wButtons & config_.ctrl_toggle_key))) + || (!config_.ctrl_xinput && (GetAsyncKeyState(config_.ctrl_toggle_key) & 0x8000))) + && sleep_ctrl == 0) + { + sleep_ctrl = config_.sleep_count_max; + if (pitch_set) { + config_.pitch_enable = !config_.pitch_enable; + } + if (yaw_set) { + config_.yaw_enable = !config_.yaw_enable; + } + } + else if (sleep_ctrl > 0) { + sleep_ctrl--; + } + for (int i = 0; i < config_.num_user_settings; i++) { // Decrement the sleep count if it's greater than zero @@ -658,7 +700,7 @@ void StereoDisplayComponent::CheckUserSettings(uint32_t device_index) } else if (config_.user_key_type[i] == TOGGLE && config_.sleep_count[i] < 1) { - config_.sleep_count[i] = sleep_count; + config_.sleep_count[i] = config_.sleep_count_max; if (GetDepth() == config_.user_depth[i] && GetConvergence() == config_.user_convergence[i]) { // If the current state matches the user settings, revert to the previous state @@ -775,3 +817,16 @@ void StereoDisplayComponent::AdjustYaw(float& currentYaw) if (currentYaw < -180.0f) currentYaw += 360.0f; } } + + +//----------------------------------------------------------------------------- +// Purpose: Toggle HMD Height for games that have incorrect HMD position +//----------------------------------------------------------------------------- +void StereoDisplayComponent::SetHeight() +{ + static float user_height = config_.hmd_height; + if (config_.hmd_height == user_height) + config_.hmd_height = 0.1; + else + config_.hmd_height = user_height; +} diff --git a/vrto3d/src/hmd_device_driver.h b/vrto3d/src/hmd_device_driver.h index 472f913..5e87ce8 100644 --- a/vrto3d/src/hmd_device_driver.h +++ b/vrto3d/src/hmd_device_driver.h @@ -51,9 +51,12 @@ struct StereoDisplayDriverConfiguration float display_latency; float display_frequency; + int sleep_count_max; bool pitch_enable; bool yaw_enable; + int32_t ctrl_toggle_key; + bool ctrl_xinput; float ctrl_deadzone; float ctrl_sensitivity; @@ -93,6 +96,7 @@ class StereoDisplayComponent : public vr::IVRDisplayComponent void CheckUserSettings(uint32_t device_index); void AdjustPitch(float& currentPitch); void AdjustYaw(float& currentYaw); + void SetHeight(); private: StereoDisplayDriverConfiguration config_; diff --git a/vrto3d/vrto3d/resources/settings/default.vrsettings b/vrto3d/vrto3d/resources/settings/default.vrsettings index 2e9c605..5046b72 100644 --- a/vrto3d/vrto3d/resources/settings/default.vrsettings +++ b/vrto3d/vrto3d/resources/settings/default.vrsettings @@ -21,6 +21,7 @@ "display_frequency": 60.0, "pitch_enable": false, "yaw_enable": false, + "ctrl_toggle_key": "XINPUT_GAMEPAD_RIGHT_THUMB", "ctrl_deadzone": 0.05, "ctrl_sensitivity": 1.0, "num_user_settings": 3,