use separate steamvr action sets for different modes

This commit is contained in:
Crispy 2023-04-29 17:40:03 +02:00
parent 29f4595750
commit d94e3040bb
6 changed files with 196 additions and 119 deletions

View file

@ -16,55 +16,62 @@
"requirement": "mandatory",
"type": "boolean"
},
{
"name": "/actions/main/in/grab",
"requirement": "mandatory",
"type": "boolean"
},
{
"name": "/actions/main/in/activate_cursor",
"requirement": "suggested",
"type": "boolean"
},
{
"name": "/actions/main/in/reset",
"requirement": "suggested",
"type": "boolean"
},
{
"name": "/actions/main/in/mouse_left",
"requirement": "suggested",
"name": "/actions/edit/in/grab",
"requirement": "mandatory",
"type": "boolean"
},
{
"name": "/actions/main/in/mouse_right",
"requirement": "suggested",
"type": "boolean"
},
{
"name": "/actions/main/in/distance",
"name": "/actions/edit/in/distance",
"requirement": "suggested",
"type": "vector2"
},
{
"name": "/actions/cursor/in/activate_cursor",
"requirement": "suggested",
"type": "boolean"
},
{
"name": "/actions/cursor/in/mouse_left",
"requirement": "suggested",
"type": "boolean"
},
{
"name": "/actions/cursor/in/mouse_right",
"requirement": "suggested",
"type": "boolean"
}
],
"action_sets": [
{
"name": "/actions/main",
"usage": "leftright"
},
{
"name": "/actions/edit",
"usage": "single"
},
{
"name": "/actions/cursor",
"usage": "single"
}
],
"localization": [
{
"language_tag": "en_us",
"/actions/main": "Overlay actions",
"/actions/main/in/toggle_visibility": "toggle visibility",
"/actions/main/in/edit_mode": "toggle edit mode",
"/actions/main/in/grab": "grab panel",
"/actions/main/in/activate_cursor": "activate cursor",
"/actions/main/in/distance": "move away",
"/actions/main/in/mouse_left": "mouse left",
"/actions/main/in/mouse_right": "mouse right",
"/actions/main/in/reset": "reset positions"
"/actions/main/in/reset": "reset positions",
"/actions/edit/in/grab": "grab panel",
"/actions/edit/in/distance": "push/pull overlay",
"/actions/cursor/in/activate_cursor": "activate cursor",
"/actions/cursor/in/mouse_left": "mouse left",
"/actions/cursor/in/mouse_right": "mouse right"
}
]
}

View file

@ -140,6 +140,104 @@
},
"app_key" : "system.generated.sinpin_vr",
"bindings" : {
"/actions/cursor" : {
"sources" : [
{
"inputs" : {
"click" : {
"output" : "/actions/cursor/in/mouse_right"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/a"
},
{
"inputs" : {
"click" : {
"output" : "/actions/cursor/in/mouse_right"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/a"
},
{
"inputs" : {
"click" : {
"output" : "/actions/cursor/in/mouse_left"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/cursor/in/mouse_left"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/cursor/in/activate_cursor"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/trackpad"
},
{
"inputs" : {
"click" : {
"output" : "/actions/cursor/in/activate_cursor"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/trackpad"
}
]
},
"/actions/edit" : {
"sources" : [
{
"inputs" : {
"position" : {
"output" : "/actions/edit/in/distance"
}
},
"mode" : "joystick",
"path" : "/user/hand/left/input/thumbstick"
},
{
"inputs" : {
"position" : {
"output" : "/actions/edit/in/distance"
}
},
"mode" : "joystick",
"path" : "/user/hand/right/input/thumbstick"
},
{
"inputs" : {
"click" : {
"output" : "/actions/edit/in/grab"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/edit/in/grab"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/trigger"
}
]
},
"/actions/legacy" : {
"haptics" : [
{
@ -588,60 +686,6 @@
},
"/actions/main" : {
"sources" : [
{
"inputs" : {
"position" : {
"output" : "/actions/main/in/distance"
}
},
"mode" : "joystick",
"path" : "/user/hand/right/input/thumbstick"
},
{
"inputs" : {
"click" : {
"output" : "/actions/main/in/grab"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/main/in/grab"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/trigger"
},
{
"inputs" : {
"position" : {
"output" : "/actions/main/in/distance"
}
},
"mode" : "joystick",
"path" : "/user/hand/left/input/thumbstick"
},
{
"inputs" : {
"click" : {
"output" : "/actions/main/in/toggle_visibility"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/trackpad"
},
{
"inputs" : {
"click" : {
"output" : "/actions/main/in/edit_mode"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/trackpad"
},
{
"inputs" : {
"long" : {
@ -654,20 +698,23 @@
{
"inputs" : {
"click" : {
"output" : "/actions/main/in/activate_cursor"
"output" : "/actions/main/in/mouse_left"
},
"long" : {
"output" : "/actions/main/in/toggle_visibility"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/trigger"
"path" : "/user/hand/left/input/b"
},
{
"inputs" : {
"click" : {
"output" : "/actions/main/in/activate_cursor"
"long" : {
"output" : "/actions/main/in/edit_mode"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/trigger"
"path" : "/user/hand/right/input/b"
}
]
}

View file

@ -53,23 +53,27 @@ App::App()
printf("actions path: %s\n", _actions_path.c_str());
vr_input->SetActionManifestPath(_actions_path.c_str());
auto action_err = vr_input->GetActionHandle("/actions/main/in/grab", &_input_handles.grab);
auto action_err = vr_input->GetActionHandle("/actions/edit/in/grab", &_input_handles.edit.grab);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/toggle_visibility", &_input_handles.toggle_hidden);
action_err = vr_input->GetActionHandle("/actions/main/in/toggle_visibility", &_input_handles.main.toggle_hidden);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/activate_cursor", &_input_handles.activate_cursor);
action_err = vr_input->GetActionHandle("/actions/cursor/in/activate_cursor", &_input_handles.cursor.activate);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/edit_mode", &_input_handles.edit_mode);
action_err = vr_input->GetActionHandle("/actions/main/in/edit_mode", &_input_handles.main.edit_mode);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/reset", &_input_handles.reset);
action_err = vr_input->GetActionHandle("/actions/main/in/reset", &_input_handles.main.reset);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/distance", &_input_handles.distance);
action_err = vr_input->GetActionHandle("/actions/edit/in/distance", &_input_handles.edit.distance);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/mouse_left", &_input_handles.mouse_left);
action_err = vr_input->GetActionHandle("/actions/cursor/in/mouse_left", &_input_handles.cursor.mouse_left);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/mouse_right", &_input_handles.mouse_right);
action_err = vr_input->GetActionHandle("/actions/cursor/in/mouse_right", &_input_handles.cursor.mouse_right);
assert(action_err == 0);
action_err = vr_input->GetActionSetHandle("/actions/main", &_input_handles.set);
action_err = vr_input->GetActionSetHandle("/actions/main", &_input_handles.main_set);
assert(action_err == 0);
action_err = vr_input->GetActionSetHandle("/actions/edit", &_input_handles.edit_set);
assert(action_err == 0);
action_err = vr_input->GetActionSetHandle("/actions/cursor", &_input_handles.cursor_set);
assert(action_err == 0);
}
}
@ -151,19 +155,27 @@ void App::Update()
void App::UpdateInput()
{
vr::VRActiveActionSet_t main;
main.ulActionSet = _input_handles.set;
main.ulRestrictedToDevice = 0;
main.nPriority = 10;
vr::EVRInputError err = vr_input->UpdateActionState(&main, sizeof(vr::VRActiveActionSet_t), 1);
if (err)
vr::VRActiveActionSet_t active_sets[2];
active_sets[0].ulActionSet = _input_handles.main_set;
active_sets[0].ulRestrictedToDevice = 0;
active_sets[0].nPriority = 10;
int set_count = 1;
if (!_hidden)
{
printf("Error: (update action state): %d\n", err);
set_count = 2;
active_sets[1].ulRestrictedToDevice = 0;
active_sets[1].nPriority = 10;
active_sets[1].ulActionSet = _input_handles.cursor_set;
if (_edit_mode)
active_sets[1].ulActionSet = _input_handles.edit_set;
}
vr::EVRInputError err = vr_input->UpdateActionState(active_sets, sizeof(vr::VRActiveActionSet_t), set_count);
if (err)
printf("Error updating action state: %d\n", err);
vr_sys->GetDeviceToAbsoluteTrackingPose(_tracking_origin, 0, _tracker_poses, MAX_TRACKERS);
if (IsInputJustPressed(_input_handles.toggle_hidden))
if (IsInputJustPressed(_input_handles.main.toggle_hidden))
{
_hidden = !_hidden;
for (auto &panel : _panels)
@ -174,7 +186,7 @@ void App::UpdateInput()
}
if (!_hidden)
{
if (IsInputJustPressed(_input_handles.reset))
if (IsInputJustPressed(_input_handles.main.reset))
{
_root_overlay.SetTransformWorld(&root_start_pose);
_root_overlay.SetWidth(0.25f);
@ -183,7 +195,7 @@ void App::UpdateInput()
panel.ResetTransform();
}
}
if (IsInputJustPressed(_input_handles.edit_mode))
if (IsInputJustPressed(_input_handles.main.edit_mode))
{
_edit_mode = !_edit_mode;
UpdateUIVisibility();

View file

@ -18,15 +18,26 @@ struct CursorPos
struct InputHandles
{
vr::VRActionSetHandle_t set;
struct
{
vr::VRActionHandle_t toggle_hidden;
vr::VRActionHandle_t distance;
vr::VRActionHandle_t grab;
vr::VRActionHandle_t activate_cursor;
vr::VRActionHandle_t mouse_left;
vr::VRActionHandle_t mouse_right;
vr::VRActionHandle_t edit_mode;
vr::VRActionHandle_t reset;
} main;
vr::VRActionSetHandle_t main_set;
struct
{
vr::VRActionHandle_t activate;
vr::VRActionHandle_t mouse_left;
vr::VRActionHandle_t mouse_right;
} cursor;
vr::VRActionSetHandle_t cursor_set;
struct
{
vr::VRActionHandle_t distance;
vr::VRActionHandle_t grab;
} edit;
vr::VRActionSetHandle_t edit_set;
};
class App

View file

@ -81,7 +81,7 @@ void Controller::Update()
if (_last_ray.overlay != nullptr)
{
auto ray = _last_ray;
if (_app->IsInputJustPressed(_app->_input_handles.grab, _input_handle))
if (_app->IsInputJustPressed(_app->_input_handles.edit.grab, _input_handle))
{
if (ray.overlay->IsHeld())
{
@ -97,7 +97,7 @@ void Controller::Update()
if (_grabbed_overlay != nullptr)
{
float move = _app->GetInputAnalog(_app->_input_handles.distance, _input_handle).y * 0.1; // TODO use frame time
float move = _app->GetInputAnalog(_app->_input_handles.edit.distance, _input_handle).y * 0.1; // TODO use frame time
if (move != 0.0f)
{
auto transform = _grabbed_overlay->GetTarget()->transform;
@ -108,7 +108,7 @@ void Controller::Update()
}
else //view mode
{
if (_app->IsInputJustPressed(_app->_input_handles.activate_cursor, _input_handle))
if (_app->IsInputJustPressed(_app->_input_handles.cursor.activate, _input_handle))
{
if (!_cursor_active && _app->_active_cursor.has_value())
{
@ -135,12 +135,12 @@ void Controller::Update()
pos *= _last_ray.hit_panel->Width();
_last_ray.hit_panel->SetCursor(pos.x, pos.y);
}
auto mouse_left = _app->GetInputDigital(_app->_input_handles.mouse_left, _input_handle);
auto mouse_left = _app->GetInputDigital(_app->_input_handles.cursor.mouse_left, _input_handle);
if (mouse_left.bChanged)
{
_app->SendMouseInput(1, mouse_left.bState);
}
auto mouse_right = _app->GetInputDigital(_app->_input_handles.mouse_right, _input_handle);
auto mouse_right = _app->GetInputDigital(_app->_input_handles.cursor.mouse_right, _input_handle);
if (mouse_right.bChanged)
{
_app->SendMouseInput(3, mouse_right.bState);

View file

@ -208,10 +208,10 @@ void Overlay::Update()
if (_holding_controller != nullptr)
{
bool hold_controller_holding = _app->GetInputDigital(_app->_input_handles.grab, _holding_controller->InputHandle()).bState;
bool hold_controller_holding = _app->GetInputDigital(_app->_input_handles.edit.grab, _holding_controller->InputHandle()).bState;
if (_resize_controller != nullptr)
{
bool resize_controller_holding = _app->GetInputDigital(_app->_input_handles.grab, _resize_controller->InputHandle()).bState;
bool resize_controller_holding = _app->GetInputDigital(_app->_input_handles.edit.grab, _resize_controller->InputHandle()).bState;
if (!resize_controller_holding)
{
_resize_controller = nullptr;