From 4bc69f2e53dab10cbc6a02abeaeb271a52ea8d62 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 7 Apr 2023 22:40:18 +0200 Subject: [PATCH] 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); + } } }