Skip to content

Commit

Permalink
Add hold option for ctrl_toggle_key
Browse files Browse the repository at this point in the history
  • Loading branch information
oneup03 committed Sep 27, 2024
1 parent 99b6417 commit 9914635
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ Checkout the [Compatibility List](https://github.com/oneup03/VRto3D/wiki/Compati
| `yaw_enable` + | `bool` | Enables or disables Controller right stick x-axis mapped to HMD Yaw | `false` |
| `pose_reset_key` + | `string`| The Virtual-Key Code to reset the HMD position and orientation | `"VK_NUMPAD7"` |
| `ctrl_toggle_key` + | `string`| The Virtual-Key Code to toggle Pitch and Yaw emulation on/off when they are enabled | `"XINPUT_GAMEPAD_RIGHT_THUMB"` |
| `ctrl_toggle_type` + | `string`| The ctrl_toggle_key's behavior ("toggle" "hold") | `"toggle"` |
| `pitch_radius` + | `float` | Radius of curvature for the HMD to pitch along. Useful in 3rd person VR and RealVR games | `0.0` |
| `ctrl_deadzone` + | `float` | Controller Deadzone when using pitch or yaw emulation | `0.05` |
| `ctrl_sensitivity` +| `float` | Controller Sensitivity when using pitch or yaw emulation | `1.0` |
| `num_user_settings` + | `int` | The number of user settings defined below. | `3` |
| `num_user_settings` + | `int` | The number of user settings defined below. | `3` |
| `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") (replace # with integer number) | `"switch"` |
| `user_depth#` + | `float` | The depth value for user setting # (replace # with integer number) | `0.5` |
| `user_convergence#` + | `float` | The convergence value for user setting # (replace # with integer number) | `0.02` |
| `user_convergence#` + | `float`| The convergence value for user setting # (replace # with integer number) | `0.02` |


## Base Installation
Expand Down Expand Up @@ -216,7 +217,7 @@ Checkout the [Compatibility List](https://github.com/oneup03/VRto3D/wiki/Compati
- Several VR controller only games can be made to work by using [Driver4VR](https://www.driver4vr.com/), a paid SteamVR Vive controller emulator. Games with mainly pointer controls work ok. Games with a lot of interaction/movement don't work well.
- Optional HMD `pitch_enable` and `yaw_enable` emulation can be turned on to help with games or mods that need it (maps to XInput right stick)
- Reference [Virtual-Key Codes](https://github.com/oneup03/VRto3D/blob/main/vrto3d/src/key_mappings.h) to find the strings to use for these hotkeys
- 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)
- 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). The `ctrl_toggle_type` can be set to either `"toggle"` them on/off or `"hold"` that disables them while the button is held
- The `pose_reset_key` can be set to allow resetting the view to the original position and orientation
- Both of these keys can be set to XInput buttons & combinations or single keyboard/mouse keys as outlined in User Settings - Load Keys
- The `pitch_radius` can be set to make the pitch emulation move along a semicircle instead of just tilting up/down in place
Expand Down
35 changes: 27 additions & 8 deletions vrto3d/src/hmd_device_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ MockControllerDeviceDriver::MockControllerDeviceDriver()
}
display_configuration.ctrl_xinput = true;
}
char ctrl_toggle_type[1024];
vrs->GetString(stereo_display_settings_section, "ctrl_toggle_type", ctrl_toggle_type, sizeof(ctrl_toggle_type));
display_configuration.ctrl_type = KeyBindTypes[ctrl_toggle_type];
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 @@ -741,6 +744,7 @@ void MockControllerDeviceDriver::SaveSettings()
vrs->SetInt32(stereo_display_settings_section, (app_name_ + "/pose_reset_key").c_str(), config.pose_reset_key);
vrs->SetBool(stereo_display_settings_section, (app_name_ + "/reset_xinput").c_str(), config.reset_xinput);
vrs->SetInt32(stereo_display_settings_section, (app_name_ + "/ctrl_toggle_key").c_str(), config.ctrl_toggle_key);
vrs->SetInt32(stereo_display_settings_section, (app_name_ + "/ctrl_toggle_type").c_str(), config.ctrl_type);
vrs->SetBool(stereo_display_settings_section, (app_name_ + "/ctrl_xinput").c_str(), config.ctrl_xinput);
vrs->SetFloat(stereo_display_settings_section, (app_name_ + "/pitch_radius").c_str(), config.pitch_radius);
vrs->SetFloat(stereo_display_settings_section, (app_name_ + "/ctrl_deadzone").c_str(), config.ctrl_deadzone);
Expand Down Expand Up @@ -1025,20 +1029,34 @@ void StereoDisplayComponent::CheckUserSettings(uint32_t device_index)
auto config = GetConfig();

// Toggle Pitch and Yaw control
if (((config.ctrl_xinput && got_xinput &&
if ((config.ctrl_xinput && got_xinput &&
((xstate & config.ctrl_toggle_key) == 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 (config.ctrl_type == HOLD && !config.ctrl_held)
{
config.ctrl_held = true;
config.pitch_enable = false;
config.yaw_enable = false;
}
if (yaw_set) {
config.yaw_enable = !config.yaw_enable;
else if ((config.ctrl_type == TOGGLE || config.ctrl_type == SWITCH) && sleep_ctrl < 1)
{
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) {
else if (config.ctrl_type == HOLD && config.ctrl_held)
{
config.ctrl_held = false;
config.pitch_enable = pitch_set;
config.yaw_enable = yaw_set;
}
if (sleep_ctrl > 0) {
sleep_ctrl--;
}

Expand Down Expand Up @@ -1194,6 +1212,7 @@ void StereoDisplayComponent::LoadSettings(const std::string& app_name, uint32_t
config_.pose_reset_key = vrs->GetInt32(stereo_display_settings_section, (app_name + "/pose_reset_key").c_str());
config_.reset_xinput = vrs->GetBool(stereo_display_settings_section, (app_name + "/reset_xinput").c_str());
config_.ctrl_toggle_key = vrs->GetInt32(stereo_display_settings_section, (app_name + "/ctrl_toggle_key").c_str());
config_.ctrl_type = vrs->GetInt32(stereo_display_settings_section, (app_name + "/ctrl_toggle_type").c_str());
config_.ctrl_xinput = vrs->GetBool(stereo_display_settings_section, (app_name + "/ctrl_xinput").c_str());
config_.pitch_radius = vrs->GetFloat(stereo_display_settings_section, (app_name + "/pitch_radius").c_str());
config_.ctrl_deadzone = vrs->GetFloat(stereo_display_settings_section, (app_name + "/ctrl_deadzone").c_str());
Expand Down
2 changes: 2 additions & 0 deletions vrto3d/src/hmd_device_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ struct StereoDisplayDriverConfiguration
bool pose_reset;
int32_t ctrl_toggle_key;
bool ctrl_xinput;
int32_t ctrl_type;
bool ctrl_held;
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 @@ -25,6 +25,7 @@
"yaw_enable": false,
"pose_reset_key": "VK_NUMPAD7",
"ctrl_toggle_key": "XINPUT_GAMEPAD_RIGHT_THUMB",
"ctrl_toggle_type": "toggle",
"pitch_radius": 0.0,
"ctrl_deadzone": 0.05,
"ctrl_sensitivity": 1.0,
Expand Down

0 comments on commit 9914635

Please sign in to comment.