From e1cf8b3b40b144e391801261514325ee6d45ded4 Mon Sep 17 00:00:00 2001 From: OneUp Date: Tue, 16 Jul 2024 18:09:01 -0500 Subject: [PATCH] Add configurable radius for pitch emulation --- README.md | 1 + vrto3d/src/hmd_device_driver.cpp | 27 ++++++++++--------- vrto3d/src/hmd_device_driver.h | 1 + .../resources/settings/default.vrsettings | 1 + 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d000061..f70b3a0 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Windows-only solution, but there are other solutions on Linux like MonadoVR. | `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` | +| `pitch_radius` | `float` | Radius of curvature for the HMD to move along. Useful in 3rd person games | `0.0` | | `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` | diff --git a/vrto3d/src/hmd_device_driver.cpp b/vrto3d/src/hmd_device_driver.cpp index c519c2b..c7551cd 100644 --- a/vrto3d/src/hmd_device_driver.cpp +++ b/vrto3d/src/hmd_device_driver.cpp @@ -100,6 +100,7 @@ MockControllerDeviceDriver::MockControllerDeviceDriver() display_configuration.ctrl_toggle_key = XInputMappings[ctrl_toggle_key]; display_configuration.ctrl_xinput = true; } + display_configuration.pitch_radius = vrs->GetFloat(stereo_display_settings_section, "pitch_radius"); display_configuration.ctrl_deadzone = vrs->GetFloat(stereo_display_settings_section, "ctrl_deadzone"); display_configuration.ctrl_sensitivity = vrs->GetFloat(stereo_display_settings_section, "ctrl_sensitivity"); @@ -322,16 +323,7 @@ vr::DriverPose_t MockControllerDeviceDriver::GetPose() pose.qRotation = HmdQuaternion_Identity; - pose.vecPosition[ 0 ] = 0.0f; - pose.vecPosition[ 1 ] = stereo_display_component_->GetConfig().hmd_height; - pose.vecPosition[ 2 ] = 0.0f; - - pose.poseIsValid = true; - pose.deviceIsConnected = true; - pose.result = vr::TrackingResult_Running_OK; - - // For HMDs we want to apply rotation/motion prediction - pose.shouldApplyHeadModel = false; + float radius = stereo_display_component_->GetConfig().pitch_radius; // Configurable radius for pitch // Adjust pitch based on controller input if (stereo_display_component_->GetConfig().pitch_enable) @@ -345,13 +337,24 @@ vr::DriverPose_t MockControllerDeviceDriver::GetPose() stereo_display_component_->AdjustYaw(currentYaw); } + // Calculate the vertical position based on pitch and radius + float pitchRadians = DEG_TO_RAD(currentPitch); + float yawRadians = DEG_TO_RAD(currentYaw); + pose.vecPosition[0] = radius * sin(pitchRadians) * sin(yawRadians); // Adjust for yaw in the x direction + pose.vecPosition[1] = stereo_display_component_->GetConfig().hmd_height - radius * (1 - cos(pitchRadians)); // Adjust the height based on pitch + pose.vecPosition[2] = radius * sin(pitchRadians) * cos(yawRadians); // Adjust for yaw in the z direction + // Recompose the rotation quaternion from pitch and yaw vr::HmdQuaternion_t pitchQuaternion = HmdQuaternion_FromEulerAngles(0, DEG_TO_RAD(currentPitch), 0); vr::HmdQuaternion_t yawQuaternion = HmdQuaternion_FromEulerAngles(0, 0, DEG_TO_RAD(currentYaw)); - - // Combine pitch and yaw quaternions pose.qRotation = HmdQuaternion_Normalize(yawQuaternion * pitchQuaternion); + pose.poseIsValid = true; + pose.deviceIsConnected = true; + pose.result = vr::TrackingResult_Running_OK; + pose.shouldApplyHeadModel = false; + pose.willDriftInYaw = false; + return pose; } diff --git a/vrto3d/src/hmd_device_driver.h b/vrto3d/src/hmd_device_driver.h index 5e87ce8..b3543d1 100644 --- a/vrto3d/src/hmd_device_driver.h +++ b/vrto3d/src/hmd_device_driver.h @@ -57,6 +57,7 @@ struct StereoDisplayDriverConfiguration bool yaw_enable; int32_t ctrl_toggle_key; bool ctrl_xinput; + float pitch_radius; float ctrl_deadzone; float ctrl_sensitivity; diff --git a/vrto3d/vrto3d/resources/settings/default.vrsettings b/vrto3d/vrto3d/resources/settings/default.vrsettings index 5046b72..3fc8d85 100644 --- a/vrto3d/vrto3d/resources/settings/default.vrsettings +++ b/vrto3d/vrto3d/resources/settings/default.vrsettings @@ -22,6 +22,7 @@ "pitch_enable": false, "yaw_enable": false, "ctrl_toggle_key": "XINPUT_GAMEPAD_RIGHT_THUMB", + "pitch_radius": 0.0, "ctrl_deadzone": 0.05, "ctrl_sensitivity": 1.0, "num_user_settings": 3,