mirror of
https://github.com/CrispyPin/sinpin-vr.git
synced 2024-11-25 19:40:26 +01:00
add reset function
This commit is contained in:
parent
38bebf8cf3
commit
edca13ca09
7 changed files with 75 additions and 42 deletions
|
@ -6,8 +6,9 @@ https://user-images.githubusercontent.com/54243225/233798783-27d1a6ae-b71d-448f-
|
|||
## features
|
||||
- one overlay per screen
|
||||
- shows cursor position
|
||||
- global visibility toggle (default: long press left B)
|
||||
- edit mode (default: long press right B)
|
||||
- global visibility toggle (default: press left touch)
|
||||
- reset positions (default: long press left A)
|
||||
- edit mode (default: press right touch)
|
||||
- move screens around (default: trigger)
|
||||
- resize screens (move with two controllers)
|
||||
- push/pull screens (default: joystick up/down)
|
||||
|
|
|
@ -21,6 +21,11 @@
|
|||
"requirement": "mandatory",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"name": "/actions/main/in/reset",
|
||||
"requirement": "suggested",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"name": "/actions/main/in/distance",
|
||||
"requirement": "suggested",
|
||||
|
@ -40,7 +45,8 @@
|
|||
"/actions/main/in/toggle_visibility": "Toggle visibility",
|
||||
"/actions/main/in/edit_mode": "Toggle edit mode",
|
||||
"/actions/main/in/grab": "grab panel",
|
||||
"/actions/main/in/distance": "Move away"
|
||||
"/actions/main/in/distance": "Move away",
|
||||
"/actions/main/in/reset": "Reset positions"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -138,7 +138,7 @@
|
|||
"hidden" : true
|
||||
}
|
||||
},
|
||||
"app_key" : "system.generated.overlay",
|
||||
"app_key" : "system.generated.sinpin_vr",
|
||||
"bindings" : {
|
||||
"/actions/legacy" : {
|
||||
"haptics" : [
|
||||
|
@ -588,15 +588,6 @@
|
|||
},
|
||||
"/actions/main" : {
|
||||
"sources" : [
|
||||
{
|
||||
"inputs" : {
|
||||
"long" : {
|
||||
"output" : "/actions/main/in/edit_mode"
|
||||
}
|
||||
},
|
||||
"mode" : "button",
|
||||
"path" : "/user/hand/right/input/b"
|
||||
},
|
||||
{
|
||||
"inputs" : {
|
||||
"position" : {
|
||||
|
@ -624,15 +615,6 @@
|
|||
"mode" : "button",
|
||||
"path" : "/user/hand/left/input/trigger"
|
||||
},
|
||||
{
|
||||
"inputs" : {
|
||||
"long" : {
|
||||
"output" : "/actions/main/in/toggle_visibility"
|
||||
}
|
||||
},
|
||||
"mode" : "button",
|
||||
"path" : "/user/hand/left/input/b"
|
||||
},
|
||||
{
|
||||
"inputs" : {
|
||||
"position" : {
|
||||
|
@ -641,15 +623,42 @@
|
|||
},
|
||||
"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" : {
|
||||
"output" : "/actions/main/in/reset"
|
||||
}
|
||||
},
|
||||
"mode" : "button",
|
||||
"path" : "/user/hand/left/input/a"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"category" : "steamvr_input",
|
||||
"controller_type" : "knuckles",
|
||||
"description" : "Default binding values for legacy apps using the Index Controller",
|
||||
"description" : "yes",
|
||||
"interaction_profile" : "",
|
||||
"name" : "Saved overlay configuration for Index Controller",
|
||||
"name" : "Saved sinpin_vr bindings",
|
||||
"options" : {
|
||||
"mirror_actions" : true,
|
||||
"simulated_controller_type" : "none"
|
||||
|
|
36
src/app.cpp
36
src/app.cpp
|
@ -5,6 +5,8 @@
|
|||
#include <cassert>
|
||||
#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()
|
||||
{
|
||||
_tracking_origin = vr::TrackingUniverseStanding;
|
||||
|
@ -26,9 +28,9 @@ App::App()
|
|||
XRRMonitorInfo *monitor_info = XRRGetMonitors(_xdisplay, _root_window, 1, &monitor_count);
|
||||
printf("found %d monitors:\n", monitor_count);
|
||||
|
||||
float pixels_per_meter = 1920;
|
||||
float total_width_meters = _root_width / pixels_per_meter;
|
||||
float total_height_meters = _root_height / pixels_per_meter;
|
||||
_pixels_per_meter = 1920;
|
||||
_total_width_meters = _root_width / _pixels_per_meter;
|
||||
_total_height_meters = _root_height / _pixels_per_meter;
|
||||
|
||||
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);
|
||||
|
||||
_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)
|
||||
|
@ -63,6 +57,8 @@ App::App()
|
|||
assert(action_err == 0);
|
||||
action_err = vr_input->GetActionHandle("/actions/main/in/edit_mode", &_input_handles.edit_mode);
|
||||
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);
|
||||
assert(action_err == 0);
|
||||
action_err = vr_input->GetActionSetHandle("/actions/main", &_input_handles.set);
|
||||
|
@ -75,6 +71,7 @@ App::~App()
|
|||
vr::VR_Shutdown();
|
||||
glfwDestroyWindow(_gl_window);
|
||||
glfwTerminate();
|
||||
XCloseDisplay(_xdisplay);
|
||||
}
|
||||
|
||||
void App::InitX11()
|
||||
|
@ -124,13 +121,7 @@ void App::InitRootOverlay()
|
|||
{
|
||||
_root_overlay = Overlay(this, "root");
|
||||
_root_overlay.SetAlpha(0.5f);
|
||||
// clang-format off
|
||||
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.SetWidth(0.25f);
|
||||
_root_overlay.SetTransformWorld(&root_start_pose);
|
||||
_root_overlay.SetTextureToColor(110, 30, 190);
|
||||
}
|
||||
|
@ -175,6 +166,15 @@ void App::UpdateInput()
|
|||
_controllers[0]->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))
|
||||
{
|
||||
_edit_mode = !_edit_mode;
|
||||
|
|
|
@ -23,6 +23,7 @@ struct InputHandles
|
|||
vr::VRActionHandle_t distance;
|
||||
vr::VRActionHandle_t grab;
|
||||
vr::VRActionHandle_t edit_mode;
|
||||
vr::VRActionHandle_t reset;
|
||||
};
|
||||
|
||||
class App
|
||||
|
@ -49,6 +50,9 @@ class App
|
|||
|
||||
int _root_width;
|
||||
int _root_height;
|
||||
float _pixels_per_meter;
|
||||
float _total_height_meters;
|
||||
float _total_width_meters;
|
||||
|
||||
vr::ETrackingUniverseOrigin _tracking_origin;
|
||||
std::filesystem::path _actions_path;
|
||||
|
|
|
@ -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;
|
||||
_overlay.SetRatio(height / (float)width);
|
||||
_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()
|
||||
|
|
|
@ -17,6 +17,7 @@ class Panel
|
|||
|
||||
void Update();
|
||||
void SetHidden(bool state);
|
||||
void ResetTransform();
|
||||
|
||||
Overlay *GetOverlay();
|
||||
|
||||
|
|
Loading…
Reference in a new issue