Skip to content

Commit

Permalink
Add configurable radius for pitch emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
oneup03 committed Jul 16, 2024
1 parent de6871f commit e1cf8b3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
27 changes: 15 additions & 12 deletions vrto3d/src/hmd_device_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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)
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions vrto3d/src/hmd_device_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions vrto3d/vrto3d/resources/settings/default.vrsettings
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e1cf8b3

Please sign in to comment.