add reset function

This commit is contained in:
Crispy 2023-04-24 20:22:09 +02:00
parent 38bebf8cf3
commit edca13ca09
7 changed files with 75 additions and 42 deletions

View file

@ -6,8 +6,9 @@ https://user-images.githubusercontent.com/54243225/233798783-27d1a6ae-b71d-448f-
## features ## features
- one overlay per screen - one overlay per screen
- shows cursor position - shows cursor position
- global visibility toggle (default: long press left B) - global visibility toggle (default: press left touch)
- edit mode (default: long press right B) - reset positions (default: long press left A)
- edit mode (default: press right touch)
- move screens around (default: trigger) - move screens around (default: trigger)
- resize screens (move with two controllers) - resize screens (move with two controllers)
- push/pull screens (default: joystick up/down) - push/pull screens (default: joystick up/down)

View file

@ -21,6 +21,11 @@
"requirement": "mandatory", "requirement": "mandatory",
"type": "boolean" "type": "boolean"
}, },
{
"name": "/actions/main/in/reset",
"requirement": "suggested",
"type": "boolean"
},
{ {
"name": "/actions/main/in/distance", "name": "/actions/main/in/distance",
"requirement": "suggested", "requirement": "suggested",
@ -40,7 +45,8 @@
"/actions/main/in/toggle_visibility": "Toggle visibility", "/actions/main/in/toggle_visibility": "Toggle visibility",
"/actions/main/in/edit_mode": "Toggle edit mode", "/actions/main/in/edit_mode": "Toggle edit mode",
"/actions/main/in/grab": "grab panel", "/actions/main/in/grab": "grab panel",
"/actions/main/in/distance": "Move away" "/actions/main/in/distance": "Move away",
"/actions/main/in/reset": "Reset positions"
} }
] ]
} }

View file

@ -138,7 +138,7 @@
"hidden" : true "hidden" : true
} }
}, },
"app_key" : "system.generated.overlay", "app_key" : "system.generated.sinpin_vr",
"bindings" : { "bindings" : {
"/actions/legacy" : { "/actions/legacy" : {
"haptics" : [ "haptics" : [
@ -588,15 +588,6 @@
}, },
"/actions/main" : { "/actions/main" : {
"sources" : [ "sources" : [
{
"inputs" : {
"long" : {
"output" : "/actions/main/in/edit_mode"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/b"
},
{ {
"inputs" : { "inputs" : {
"position" : { "position" : {
@ -624,15 +615,6 @@
"mode" : "button", "mode" : "button",
"path" : "/user/hand/left/input/trigger" "path" : "/user/hand/left/input/trigger"
}, },
{
"inputs" : {
"long" : {
"output" : "/actions/main/in/toggle_visibility"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/b"
},
{ {
"inputs" : { "inputs" : {
"position" : { "position" : {
@ -641,15 +623,42 @@
}, },
"mode" : "joystick", "mode" : "joystick",
"path" : "/user/hand/left/input/thumbstick" "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" : {
"output" : "/actions/main/in/reset"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/a"
} }
] ]
} }
}, },
"category" : "steamvr_input", "category" : "steamvr_input",
"controller_type" : "knuckles", "controller_type" : "knuckles",
"description" : "Default binding values for legacy apps using the Index Controller", "description" : "yes",
"interaction_profile" : "", "interaction_profile" : "",
"name" : "Saved overlay configuration for Index Controller", "name" : "Saved sinpin_vr bindings",
"options" : { "options" : {
"mirror_actions" : true, "mirror_actions" : true,
"simulated_controller_type" : "none" "simulated_controller_type" : "none"

View file

@ -5,6 +5,8 @@
#include <cassert> #include <cassert>
#include <glm/matrix.hpp> #include <glm/matrix.hpp>
const VRMat root_start_pose = {{{1, 0, 0, 0}, {0, 1, 0, 0.8f}, {0, 0, 1, 0}}}; // 0.8m above origin
App::App() App::App()
{ {
_tracking_origin = vr::TrackingUniverseStanding; _tracking_origin = vr::TrackingUniverseStanding;
@ -26,9 +28,9 @@ App::App()
XRRMonitorInfo *monitor_info = XRRGetMonitors(_xdisplay, _root_window, 1, &monitor_count); XRRMonitorInfo *monitor_info = XRRGetMonitors(_xdisplay, _root_window, 1, &monitor_count);
printf("found %d monitors:\n", monitor_count); printf("found %d monitors:\n", monitor_count);
float pixels_per_meter = 1920; _pixels_per_meter = 1920;
float total_width_meters = _root_width / pixels_per_meter; _total_width_meters = _root_width / _pixels_per_meter;
float total_height_meters = _root_height / pixels_per_meter; _total_height_meters = _root_height / _pixels_per_meter;
for (int i = 0; i < monitor_count; i++) for (int i = 0; i < monitor_count; i++)
{ {
@ -36,14 +38,6 @@ App::App()
printf("screen %d: pos(%d, %d) %dx%d\n", i, mon.x, mon.y, mon.width, mon.height); printf("screen %d: pos(%d, %d) %dx%d\n", i, mon.x, mon.y, mon.width, mon.height);
_panels.push_back(Panel(this, i, mon.x, mon.y, mon.width, mon.height)); _panels.push_back(Panel(this, i, mon.x, mon.y, mon.width, mon.height));
float width = mon.width / pixels_per_meter;
float pos_x = mon.x / pixels_per_meter + width / 2.0f - total_width_meters / 2.0f;
float height = mon.height / pixels_per_meter;
float pos_y = 1.2f + mon.y / pixels_per_meter - height / 2.0f + total_height_meters / 2.0f;
VRMat start_pose = {{{1, 0, 0, pos_x}, {0, 1, 0, pos_y}, {0, 0, 1, 0}}};
_panels[i].GetOverlay()->SetTransformWorld(&start_pose);
_panels[i].GetOverlay()->SetWidth(width);
} }
for (auto &panel : _panels) for (auto &panel : _panels)
@ -63,6 +57,8 @@ App::App()
assert(action_err == 0); 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.edit_mode);
assert(action_err == 0); assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/reset", &_input_handles.reset);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/distance", &_input_handles.distance); action_err = vr_input->GetActionHandle("/actions/main/in/distance", &_input_handles.distance);
assert(action_err == 0); assert(action_err == 0);
action_err = vr_input->GetActionSetHandle("/actions/main", &_input_handles.set); action_err = vr_input->GetActionSetHandle("/actions/main", &_input_handles.set);
@ -75,6 +71,7 @@ App::~App()
vr::VR_Shutdown(); vr::VR_Shutdown();
glfwDestroyWindow(_gl_window); glfwDestroyWindow(_gl_window);
glfwTerminate(); glfwTerminate();
XCloseDisplay(_xdisplay);
} }
void App::InitX11() void App::InitX11()
@ -124,13 +121,7 @@ void App::InitRootOverlay()
{ {
_root_overlay = Overlay(this, "root"); _root_overlay = Overlay(this, "root");
_root_overlay.SetAlpha(0.5f); _root_overlay.SetAlpha(0.5f);
// clang-format off _root_overlay.SetWidth(0.25f);
VRMat root_start_pose = {{
{0.25f, 0.0f, 0.0f, 0},
{0.0f, 0.25f, 0.0f, 0.8f},
{0.0f, 0.0f, 1.0f, 0}
}};
// clang-format on
_root_overlay.SetTransformWorld(&root_start_pose); _root_overlay.SetTransformWorld(&root_start_pose);
_root_overlay.SetTextureToColor(110, 30, 190); _root_overlay.SetTextureToColor(110, 30, 190);
} }
@ -175,6 +166,15 @@ void App::UpdateInput()
_controllers[0]->SetHidden(_hidden || !_edit_mode); _controllers[0]->SetHidden(_hidden || !_edit_mode);
_controllers[1]->SetHidden(_hidden || !_edit_mode); _controllers[1]->SetHidden(_hidden || !_edit_mode);
} }
if (IsInputJustPressed(_input_handles.reset))
{
_root_overlay.SetTransformWorld(&root_start_pose);
_root_overlay.SetWidth(0.25f);
for (auto &panel : _panels)
{
panel.ResetTransform();
}
}
if (!_hidden && IsInputJustPressed(_input_handles.edit_mode)) if (!_hidden && IsInputJustPressed(_input_handles.edit_mode))
{ {
_edit_mode = !_edit_mode; _edit_mode = !_edit_mode;

View file

@ -23,6 +23,7 @@ struct InputHandles
vr::VRActionHandle_t distance; vr::VRActionHandle_t distance;
vr::VRActionHandle_t grab; vr::VRActionHandle_t grab;
vr::VRActionHandle_t edit_mode; vr::VRActionHandle_t edit_mode;
vr::VRActionHandle_t reset;
}; };
class App class App
@ -49,6 +50,9 @@ class App
int _root_width; int _root_width;
int _root_height; int _root_height;
float _pixels_per_meter;
float _total_height_meters;
float _total_width_meters;
vr::ETrackingUniverseOrigin _tracking_origin; vr::ETrackingUniverseOrigin _tracking_origin;
std::filesystem::path _actions_path; std::filesystem::path _actions_path;

View file

@ -24,6 +24,18 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height)
_texture.handle = (void *)(uintptr_t)_gl_texture; _texture.handle = (void *)(uintptr_t)_gl_texture;
_overlay.SetRatio(height / (float)width); _overlay.SetRatio(height / (float)width);
_overlay.SetTextureToColor(50, 20, 50); _overlay.SetTextureToColor(50, 20, 50);
ResetTransform();
}
void Panel::ResetTransform()
{
float width = _width / _app->_pixels_per_meter;
float pos_x = _x / _app->_pixels_per_meter + width / 2.0f - _app->_total_width_meters / 2.0f;
float height = _height / _app->_pixels_per_meter;
float pos_y = 1.2f + _y / _app->_pixels_per_meter - height / 2.0f + _app->_total_height_meters / 2.0f;
VRMat pose = {{{1, 0, 0, pos_x}, {0, 1, 0, pos_y}, {0, 0, 1, 0}}};
_overlay.SetTransformWorld(&pose);
_overlay.SetWidth(width);
} }
void Panel::Update() void Panel::Update()

View file

@ -17,6 +17,7 @@ class Panel
void Update(); void Update();
void SetHidden(bool state); void SetHidden(bool state);
void ResetTransform();
Overlay *GetOverlay(); Overlay *GetOverlay();