mirror of
https://github.com/CrispyPin/sinpin-vr.git
synced 2024-11-22 18:10:26 +01:00
change alpha with trackpad while holding a panel
This commit is contained in:
parent
2c120f462f
commit
4bc69f2e53
3 changed files with 22 additions and 3 deletions
14
src/app.cpp
14
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()
|
||||
|
|
|
@ -20,6 +20,7 @@ class App
|
|||
|
||||
std::vector<TrackerID> GetControllers();
|
||||
glm::mat4 GetTrackerPose(TrackerID tracker);
|
||||
vr::VRControllerState_t GetControllerState(TrackerID controller);
|
||||
bool IsGrabActive(TrackerID controller);
|
||||
CursorPos GetCursorPosition();
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "util.h"
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
#include <glm/common.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue