change alpha with trackpad while holding a panel

This commit is contained in:
Crispy 2023-04-07 22:40:18 +02:00
parent 2c120f462f
commit 4bc69f2e53
3 changed files with 22 additions and 3 deletions

View file

@ -11,6 +11,7 @@ App::App()
InitOVR(); InitOVR();
InitX11(); InitX11();
InitGLFW(); InitGLFW();
printf("\n");
glGenTextures(1, &_gl_frame); glGenTextures(1, &_gl_frame);
glBindTexture(GL_TEXTURE_2D, _gl_frame); glBindTexture(GL_TEXTURE_2D, _gl_frame);
@ -124,6 +125,15 @@ glm::mat4 App::GetTrackerPose(TrackerID tracker)
return ConvertMat(tracked_pose.mDeviceToAbsoluteTracking); 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) bool App::IsGrabActive(TrackerID controller)
{ {
vr::VRControllerState_t state; vr::VRControllerState_t state;
@ -132,9 +142,7 @@ bool App::IsGrabActive(TrackerID controller)
return false; return false;
auto trigger_mask = vr::ButtonMaskFromId(vr::k_EButton_SteamVR_Trigger); auto trigger_mask = vr::ButtonMaskFromId(vr::k_EButton_SteamVR_Trigger);
auto b_mask = vr::ButtonMaskFromId(vr::k_EButton_IndexController_B); return state.ulButtonPressed & trigger_mask;
auto mask = trigger_mask | b_mask;
return (state.ulButtonPressed & mask) == mask;
} }
CursorPos App::GetCursorPosition() CursorPos App::GetCursorPosition()

View file

@ -20,6 +20,7 @@ class App
std::vector<TrackerID> GetControllers(); std::vector<TrackerID> GetControllers();
glm::mat4 GetTrackerPose(TrackerID tracker); glm::mat4 GetTrackerPose(TrackerID tracker);
vr::VRControllerState_t GetControllerState(TrackerID controller);
bool IsGrabActive(TrackerID controller); bool IsGrabActive(TrackerID controller);
CursorPos GetCursorPosition(); CursorPos GetCursorPosition();

View file

@ -3,6 +3,7 @@
#include "util.h" #include "util.h"
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <glm/common.hpp>
#include <glm/glm.hpp> #include <glm/glm.hpp>
Panel::Panel(App *app, vr::HmdMatrix34_t start_pose, 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)
@ -82,6 +83,15 @@ void Panel::Update()
{ {
ControllerRelease(); 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);
}
} }
} }