From 74d2c71c531bd0848f6943e043a8cecc1d7ebea9 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 7 Apr 2023 13:26:42 +0200 Subject: [PATCH 1/6] cleanup --- src/app.cpp | 27 ++++++++++++++++----------- src/app.h | 3 ++- src/panel.cpp | 18 +++++------------- src/panel.h | 1 + 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index b437ddb..144252a 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -5,7 +5,7 @@ App::App() { - _tracking_origin = vr::ETrackingUniverseOrigin::TrackingUniverseStanding; + _tracking_origin = vr::TrackingUniverseStanding; InitOVR(); InitX11(); @@ -36,8 +36,9 @@ void App::InitX11() void App::InitOVR() { vr::EVRInitError init_err; - vr_sys = vr::VR_Init(&init_err, vr::EVRApplicationType::VRApplication_Background); - if (init_err == vr::EVRInitError::VRInitError_Init_NoServerForBackgroundApp) + // would normally be using VRApplication_Overlay, but Background allows it to quit if steamvr is not running, instead of opening steamvr. + vr_sys = vr::VR_Init(&init_err, vr::VRApplication_Background); + if (init_err == vr::VRInitError_Init_NoServerForBackgroundApp) { printf("SteamVR is not running\n"); exit(1); @@ -55,7 +56,7 @@ void App::InitGLFW() { assert(glfwInit() == true); glfwWindowHint(GLFW_VISIBLE, false); - // TODO this is creating a 1x1 window, should it be bigger? + // creating a 1x1 window, since it is hidden anyway _gl_window = glfwCreateWindow(1, 1, "Overlay", nullptr, nullptr); assert(_gl_window != nullptr); glfwMakeContextCurrent(_gl_window); @@ -70,6 +71,14 @@ void App::Update() } } +std::vector App::GetControllers() +{ + static const auto max_len = 64; + TrackerID controllers[max_len]; + int controller_count = vr_sys->GetSortedTrackedDeviceIndicesOfClass(vr::TrackedDeviceClass_Controller, controllers, max_len); + return std::vector(controllers, controllers + controller_count); +} + glm::mat4 App::GetTrackerPose(TrackerID tracker) { vr::VRControllerState_t state; @@ -83,19 +92,15 @@ glm::mat4 App::GetTrackerPose(TrackerID tracker) return ConvertMat(tracked_pose.mDeviceToAbsoluteTracking); } -bool App::IsGrabActive(vr::TrackedDeviceIndex_t controller) +bool App::IsGrabActive(TrackerID controller) { vr::VRControllerState_t state; auto get_state_err = vr_sys->GetControllerState(controller, &state, sizeof(vr::VRControllerState_t)); if (get_state_err == false) - { - printf("Error getting controller state: %d\n", get_state_err); return false; - } - // printf("got state\n"); - auto trigger_mask = vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_SteamVR_Trigger); - auto b_mask = vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_IndexController_B); + auto trigger_mask = vr::ButtonMaskFromId(vr::k_EButton_SteamVR_Trigger); + auto b_mask = vr::ButtonMaskFromId(vr::k_EButton_IndexController_B); auto mask = trigger_mask | b_mask; return (state.ulButtonPressed & mask) == mask; } diff --git a/src/app.h b/src/app.h index c3dc926..10cd469 100644 --- a/src/app.h +++ b/src/app.h @@ -17,8 +17,9 @@ class App ~App(); void Update(); + std::vector GetControllers(); glm::mat4 GetTrackerPose(TrackerID tracker); - bool IsGrabActive(vr::TrackedDeviceIndex_t controller); + bool IsGrabActive(TrackerID controller); CursorPos GetCursorPosition(); Display *_xdisplay; diff --git a/src/panel.cpp b/src/panel.cpp index e95a683..8e93e51 100644 --- a/src/panel.cpp +++ b/src/panel.cpp @@ -20,8 +20,8 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) glGenTextures(1, &_gl_texture); glBindTexture(GL_TEXTURE_2D, _gl_texture); - _texture.eColorSpace = vr::EColorSpace::ColorSpace_Auto; - _texture.eType = vr::ETextureType::TextureType_OpenGL; + _texture.eColorSpace = vr::ColorSpace_Auto; + _texture.eType = vr::TextureType_OpenGL; _texture.handle = (void *)(uintptr_t)_gl_texture; // create overlay @@ -37,7 +37,6 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) // (flipping uv on y axis because opengl and xorg are opposite) vr::VRTextureBounds_t bounds{0, 1, 1, 0}; _app->vr_overlay->SetOverlayTextureBounds(_id, &bounds); - _app->vr_overlay->SetOverlayTransformAbsolute(_id, _app->_tracking_origin, &DEFAULT_POSE); } } @@ -49,23 +48,16 @@ void Panel::Update() if (!_is_held) { - vr::TrackedDeviceIndex_t controllers[8]; - auto controller_count = _app->vr_sys->GetSortedTrackedDeviceIndicesOfClass(vr::ETrackedDeviceClass::TrackedDeviceClass_Controller, controllers, 8); - - for (unsigned int i = 0; i < controller_count; i++) + for (auto controller : _app->GetControllers()) { - auto controller = controllers[i]; - vr::HmdMatrix34_t overlay_pose; vr::ETrackingUniverseOrigin tracking_universe; _app->vr_overlay->GetOverlayTransformAbsolute(_id, &tracking_universe, &overlay_pose); - auto controller_pose = _app->GetTrackerPose(controller); - auto controller_pos = glm::vec3(controller_pose[3]); - auto overlay_pos = glm::vec3(ConvertMat(overlay_pose)[3]); + auto controller_pos = GetPos(_app->GetTrackerPose(controller)); + auto overlay_pos = GetPos(ConvertMat(overlay_pose)); bool close_enough = glm::length(overlay_pos - controller_pos) < 1.0f; - // close_enough = true; if (close_enough && _app->IsGrabActive(controller)) { diff --git a/src/panel.h b/src/panel.h index e2becd8..65c3e4f 100644 --- a/src/panel.h +++ b/src/panel.h @@ -3,6 +3,7 @@ #include const vr::HmdMatrix34_t DEFAULT_POSE = {{{1, 0, 0, 0}, {0, 1, 0, 1}, {0, 0, 1, 0}}}; + class App; class Panel From 54ea68da6bb4ac5e0fb6f638a343381c6da0a3b2 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 7 Apr 2023 19:13:52 +0200 Subject: [PATCH 2/6] separate overlays by screen --- Makefile | 2 +- src/app.cpp | 28 +++++++++++++++++++++++++++- src/app.h | 2 ++ src/panel.cpp | 21 +++++++++++++++------ src/panel.h | 1 + 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 09207d5..e42894c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ build: - CPATH=. g++ -Wall -lX11 -lglfw -lGL openvr/libopenvr_api.so src/*.cpp -o overlay + CPATH=. g++ -Wall -lX11 -lXrandr -lglfw -lGL openvr/libopenvr_api.so src/*.cpp -o overlay run: build ./overlay diff --git a/src/app.cpp b/src/app.cpp index 144252a..cb56b7e 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -1,6 +1,7 @@ #include "app.h" #include "panel.h" #include "util.h" +#include #include App::App() @@ -11,7 +12,21 @@ App::App() InitX11(); InitGLFW(); - _panels.push_back(Panel(this, 0, 0, 0, _root_width, _root_height)); + glGenTextures(1, &_gl_frame); + glBindTexture(GL_TEXTURE_2D, _gl_frame); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + + int monitor_count; + XRRMonitorInfo *monitor_info = XRRGetMonitors(_xdisplay, _root_window, 1, &monitor_count); + printf("found %d monitors:\n", monitor_count); + + for (int i = 0; i < monitor_count; i++) + { + XRRMonitorInfo mon = monitor_info[i]; + printf("screen %d: pos(%d, %d) wh(%d, %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)); + } } App::~App() @@ -65,6 +80,17 @@ void App::InitGLFW() void App::Update() { + auto frame = XGetImage( + _xdisplay, + _root_window, + 0, 0, + _root_width, _root_height, + AllPlanes, + ZPixmap); + glBindTexture(GL_TEXTURE_2D, _gl_frame); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _root_width, _root_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, frame->data); + XDestroyImage(frame); + for (auto &panel : _panels) { panel.Update(); diff --git a/src/app.h b/src/app.h index 10cd469..373a499 100644 --- a/src/app.h +++ b/src/app.h @@ -1,3 +1,4 @@ +#define GL_GLEXT_PROTOTYPES #include "util.h" #include #include @@ -25,6 +26,7 @@ class App Display *_xdisplay; Window _root_window; GLFWwindow *_gl_window; + GLuint _gl_frame; int _root_width; int _root_height; diff --git a/src/panel.cpp b/src/panel.cpp index 8e93e51..cfe0e27 100644 --- a/src/panel.cpp +++ b/src/panel.cpp @@ -2,7 +2,6 @@ #include "app.h" #include "util.h" -#include #include #include @@ -19,6 +18,11 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) _active_hand = -1; glGenTextures(1, &_gl_texture); glBindTexture(GL_TEXTURE_2D, _gl_texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D( + GL_TEXTURE_2D, 0, GL_RGB, + _width, _height, 0, + GL_BGRA, GL_UNSIGNED_BYTE, 0); _texture.eColorSpace = vr::ColorSpace_Auto; _texture.eType = vr::TextureType_OpenGL; @@ -29,7 +33,7 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) auto overlay_create_err = _app->vr_overlay->CreateOverlay(_name.c_str(), _name.c_str(), &_id); assert(overlay_create_err == 0); _app->vr_overlay->ShowOverlay(_id); - _app->vr_overlay->SetOverlayWidthInMeters(_id, 2.5f); + // _app->vr_overlay->SetOverlayWidthInMeters(_id, 2.5f); uint8_t col[4] = {20, 50, 50, 255}; _app->vr_overlay->SetOverlayRaw(_id, &col, 1, 1, 4); printf("Created overlay instance %d\n", _index); @@ -37,7 +41,9 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) // (flipping uv on y axis because opengl and xorg are opposite) vr::VRTextureBounds_t bounds{0, 1, 1, 0}; _app->vr_overlay->SetOverlayTextureBounds(_id, &bounds); - _app->vr_overlay->SetOverlayTransformAbsolute(_id, _app->_tracking_origin, &DEFAULT_POSE); + vr::HmdMatrix34_t start_pose = DEFAULT_POSE; + start_pose.m[0][3] += index * 1.5f; + _app->vr_overlay->SetOverlayTransformAbsolute(_id, _app->_tracking_origin, &start_pose); } } @@ -76,9 +82,12 @@ void Panel::Update() void Panel::Render() { - auto frame = XGetImage(_app->_xdisplay, _app->_root_window, _x, _y, _width, _height, AllPlanes, ZPixmap); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _width, _height, 0, GL_BGRA, GL_UNSIGNED_BYTE, frame->data); - XDestroyImage(frame); + glCopyImageSubData( + _app->_gl_frame, GL_TEXTURE_2D, 0, + _x, _y, 0, + _gl_texture, GL_TEXTURE_2D, 0, + 0, 0, 0, + _width, _height, 1); auto set_texture_err = _app->vr_overlay->SetOverlayTexture(_id, &_texture); assert(set_texture_err == 0); diff --git a/src/panel.h b/src/panel.h index 65c3e4f..7f80c00 100644 --- a/src/panel.h +++ b/src/panel.h @@ -1,3 +1,4 @@ +#define GL_GLEXT_PROTOTYPES #include "util.h" #include #include From 03d15b42bdaa0b07ce3807d6a8672df08d1090fe Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 7 Apr 2023 19:27:35 +0200 Subject: [PATCH 3/6] correctly display cursor position when multiple screens exist --- src/panel.cpp | 15 +++++++++++---- src/panel.h | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/panel.cpp b/src/panel.cpp index cfe0e27..69f1ace 100644 --- a/src/panel.cpp +++ b/src/panel.cpp @@ -95,13 +95,20 @@ void Panel::Render() void Panel::UpdateCursor() { - auto global = _app->GetCursorPosition(); + auto global_pos = _app->GetCursorPosition(); + if (global_pos.x < _x || global_pos.x >= _x + _width || global_pos.y < _y || global_pos.y >= _y + _height) + { + _app->vr_overlay->ClearOverlayCursorPositionOverride(_id); + return; + } + int local_x = global_pos.x - _x; + int local_y = global_pos.y - _y; + // TODO: make this work when aspect ratio is >1 (root window is taller than it is wide) - // TODO take into account that the panel is smaller than the root window float ratio = (float)_height / (float)_width; float top_edge = 0.5f - ratio / 2.0f; - float x = global.x / (float)_width; - float y = 1.0f - (global.y / (float)_width + top_edge); + float x = local_x / (float)_width; + float y = 1.0f - (local_y / (float)_width + top_edge); auto pos = vr::HmdVector2_t{x, y}; _app->vr_overlay->SetOverlayCursorPositionOverride(_id, &pos); } diff --git a/src/panel.h b/src/panel.h index 7f80c00..afca6fc 100644 --- a/src/panel.h +++ b/src/panel.h @@ -28,8 +28,8 @@ class Panel TrackerID _active_hand; bool _is_held; - unsigned int _x, _y; - unsigned int _width, _height; + int _x, _y; + int _width, _height; float _alpha; vr::Texture_t _texture; From 1770dd6e264094fbf0a16addf8709debe16226f4 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 7 Apr 2023 20:32:52 +0200 Subject: [PATCH 4/6] order panels correctly based on pixel coordinates --- src/app.cpp | 10 ++++++++-- src/panel.cpp | 5 +---- src/panel.h | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index cb56b7e..d44ad82 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -20,12 +20,18 @@ 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 x_min = -(monitor_info[0].x + monitor_info[0].width / 2.0f); + for (int i = 0; i < monitor_count; i++) { XRRMonitorInfo mon = monitor_info[i]; - printf("screen %d: pos(%d, %d) wh(%d, %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)); + float pos_x = (x_min + mon.x) / pixels_per_meter; + float pos_y = 1.2f; + vr::HmdMatrix34_t start_pose = {{{1, 0, 0, pos_x}, {0, 1, 0, pos_y}, {0, 0, 1, 0}}}; + _panels.push_back(Panel(this, start_pose, i, mon.x, mon.y, mon.width, mon.height)); } } diff --git a/src/panel.cpp b/src/panel.cpp index 69f1ace..c38e59c 100644 --- a/src/panel.cpp +++ b/src/panel.cpp @@ -5,7 +5,7 @@ #include #include -Panel::Panel(App *app, int index, int x, int y, int width, int height) +Panel::Panel(App *app, vr::HmdMatrix34_t start_pose, int index, int x, int y, int width, int height) : _app(app), _index(index), _x(x), @@ -33,7 +33,6 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) auto overlay_create_err = _app->vr_overlay->CreateOverlay(_name.c_str(), _name.c_str(), &_id); assert(overlay_create_err == 0); _app->vr_overlay->ShowOverlay(_id); - // _app->vr_overlay->SetOverlayWidthInMeters(_id, 2.5f); uint8_t col[4] = {20, 50, 50, 255}; _app->vr_overlay->SetOverlayRaw(_id, &col, 1, 1, 4); printf("Created overlay instance %d\n", _index); @@ -41,8 +40,6 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) // (flipping uv on y axis because opengl and xorg are opposite) vr::VRTextureBounds_t bounds{0, 1, 1, 0}; _app->vr_overlay->SetOverlayTextureBounds(_id, &bounds); - vr::HmdMatrix34_t start_pose = DEFAULT_POSE; - start_pose.m[0][3] += index * 1.5f; _app->vr_overlay->SetOverlayTransformAbsolute(_id, _app->_tracking_origin, &start_pose); } } diff --git a/src/panel.h b/src/panel.h index afca6fc..e0abf82 100644 --- a/src/panel.h +++ b/src/panel.h @@ -10,7 +10,7 @@ class App; class Panel { public: - Panel(App *app, int index, int xmin, int xmax, int ymin, int ymax); + Panel(App *app, vr::HmdMatrix34_t start_pose, int index, int xmin, int xmax, int ymin, int ymax); void Update(); From 2c120f462fd914500e10cf80a5a167732ed297ae Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 7 Apr 2023 20:49:09 +0200 Subject: [PATCH 5/6] make grabbable area a box instead of sphere, colour grabbed panels --- src/panel.cpp | 34 +++++++++++++++++++++++----------- src/panel.h | 1 + src/util.h | 5 +++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/panel.cpp b/src/panel.cpp index c38e59c..0eb07bc 100644 --- a/src/panel.cpp +++ b/src/panel.cpp @@ -15,6 +15,7 @@ Panel::Panel(App *app, vr::HmdMatrix34_t start_pose, int index, int x, int y, in { _name = "screen_view_" + std::to_string(index); _alpha = 1.0f; + _meters = 1.0f; _active_hand = -1; glGenTextures(1, &_gl_texture); glBindTexture(GL_TEXTURE_2D, _gl_texture); @@ -53,18 +54,25 @@ void Panel::Update() { for (auto controller : _app->GetControllers()) { - vr::HmdMatrix34_t overlay_pose; - vr::ETrackingUniverseOrigin tracking_universe; - _app->vr_overlay->GetOverlayTransformAbsolute(_id, &tracking_universe, &overlay_pose); - - auto controller_pos = GetPos(_app->GetTrackerPose(controller)); - auto overlay_pos = GetPos(ConvertMat(overlay_pose)); - - bool close_enough = glm::length(overlay_pos - controller_pos) < 1.0f; - - if (close_enough && _app->IsGrabActive(controller)) + if (_app->IsGrabActive(controller)) { - ControllerGrab(controller); + vr::HmdMatrix34_t overlay_pose; + vr::ETrackingUniverseOrigin tracking_universe; + _app->vr_overlay->GetOverlayTransformAbsolute(_id, &tracking_universe, &overlay_pose); + + auto controller_pos = GetPos(_app->GetTrackerPose(controller)); + + auto local_pos = glm::inverse(ConvertMat(overlay_pose)) * glm::vec4(controller_pos - GetPos(overlay_pose), 0); + + float grab_area_thickness = 0.3f; + bool close_enough = glm::abs(local_pos.z) < grab_area_thickness; + close_enough &= glm::abs(local_pos.x) < _meters / 2.0f; + close_enough &= glm::abs(local_pos.y) < _meters / 2.0f; + + if (close_enough) + { + ControllerGrab(controller); + } } } } @@ -116,6 +124,8 @@ void Panel::ControllerGrab(TrackerID controller) _is_held = true; _active_hand = controller; + _app->vr_overlay->SetOverlayColor(_id, 0.6f, 1.0f, 1.0f); + vr::HmdMatrix34_t abs_pose; vr::ETrackingUniverseOrigin tracking_universe; @@ -134,6 +144,8 @@ void Panel::ControllerRelease() printf("Released panel %d\n", _index); _is_held = false; + _app->vr_overlay->SetOverlayColor(_id, 1.0f, 1.0f, 1.0f); + vr::HmdMatrix34_t relative_pose; _app->vr_overlay->GetOverlayTransformTrackedDeviceRelative(_id, &_active_hand, &relative_pose); auto relative_mat = ConvertMat(relative_pose); diff --git a/src/panel.h b/src/panel.h index e0abf82..4b3a3e2 100644 --- a/src/panel.h +++ b/src/panel.h @@ -30,6 +30,7 @@ class Panel int _x, _y; int _width, _height; + float _meters; float _alpha; vr::Texture_t _texture; diff --git a/src/util.h b/src/util.h index 1ddd58b..4b52b6a 100644 --- a/src/util.h +++ b/src/util.h @@ -46,3 +46,8 @@ inline glm::vec3 GetPos(glm::mat4x4 mat) { return glm::vec3(mat[3][0], mat[3][1], mat[3][2]); } + +inline glm::vec3 GetPos(vr::HmdMatrix34_t mat) +{ + return glm::vec3(mat.m[0][3], mat.m[1][3], mat.m[2][3]); +} From 4bc69f2e53dab10cbc6a02abeaeb271a52ea8d62 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 7 Apr 2023 22:40:18 +0200 Subject: [PATCH 6/6] change alpha with trackpad while holding a panel --- src/app.cpp | 14 +++++++++++--- src/app.h | 1 + src/panel.cpp | 10 ++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index d44ad82..2381e78 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -11,6 +11,7 @@ App::App() InitOVR(); InitX11(); InitGLFW(); + printf("\n"); glGenTextures(1, &_gl_frame); glBindTexture(GL_TEXTURE_2D, _gl_frame); @@ -124,6 +125,15 @@ glm::mat4 App::GetTrackerPose(TrackerID tracker) return ConvertMat(tracked_pose.mDeviceToAbsoluteTracking); } +vr::VRControllerState_t App::GetControllerState(TrackerID controller) +{ + vr::VRControllerState_t state; + auto get_state_err = vr_sys->GetControllerState(controller, &state, sizeof(vr::VRControllerState_t)); + if (get_state_err == false) + printf("failed to get state of controller %d\n", controller); + return state; +} + bool App::IsGrabActive(TrackerID controller) { vr::VRControllerState_t state; @@ -132,9 +142,7 @@ bool App::IsGrabActive(TrackerID controller) return false; auto trigger_mask = vr::ButtonMaskFromId(vr::k_EButton_SteamVR_Trigger); - auto b_mask = vr::ButtonMaskFromId(vr::k_EButton_IndexController_B); - auto mask = trigger_mask | b_mask; - return (state.ulButtonPressed & mask) == mask; + return state.ulButtonPressed & trigger_mask; } CursorPos App::GetCursorPosition() diff --git a/src/app.h b/src/app.h index 373a499..d881b2e 100644 --- a/src/app.h +++ b/src/app.h @@ -20,6 +20,7 @@ class App std::vector GetControllers(); glm::mat4 GetTrackerPose(TrackerID tracker); + vr::VRControllerState_t GetControllerState(TrackerID controller); bool IsGrabActive(TrackerID controller); CursorPos GetCursorPosition(); diff --git a/src/panel.cpp b/src/panel.cpp index 0eb07bc..ce2a910 100644 --- a/src/panel.cpp +++ b/src/panel.cpp @@ -3,6 +3,7 @@ #include "util.h" #include +#include #include Panel::Panel(App *app, vr::HmdMatrix34_t start_pose, int index, int x, int y, int width, int height) @@ -82,6 +83,15 @@ void Panel::Update() { ControllerRelease(); } + auto state = _app->GetControllerState(_active_hand); + auto touchpad = state.rAxis[0]; + if (touchpad.x != 0.0f) + { + // TODO take into account the current framerate + _alpha += touchpad.x * 0.05; + _alpha = glm::clamp(_alpha, 0.1f, 1.0f); + _app->vr_overlay->SetOverlayAlpha(_id, _alpha); + } } }