Update hand gesture for GUI repositioning to require that the hand is opened

This commit is contained in:
Guillaume Meunier
2025-11-02 17:51:59 +01:00
parent dd874eea4b
commit c4265d80a5
4 changed files with 97 additions and 21 deletions
+2 -1
View File
@@ -85,7 +85,8 @@ constexpr glm::vec3 keyboard_position = {0, -0.3, 0.1};
constexpr float near_plane = 0.02;
// Recenter gesture thresholds
constexpr float recenter_cosangle_min = 0.8;
constexpr float recenter_cos_palm_angle_min = 0.7;
constexpr float recenter_cos_fingertip_angle_max = 0.3;
constexpr float recenter_distance_up = 0.3;
constexpr float recenter_distance_front = 0.2;
+52 -19
View File
@@ -31,6 +31,7 @@
#include "render/scene_components.h"
#include "stream.h"
#include "utils/files.h"
#include "utils/glm_cast.h"
#include "utils/i18n.h"
#include "wivrn_client.h"
#include "wivrn_discover.h"
@@ -427,27 +428,59 @@ void scenes::lobby::connect(const configuration::server_data & data)
data.manual);
}
std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(xr::spaces space, const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints)
std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(
xr::spaces space,
const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints,
const std::pair<glm::vec3, glm::quat> & head_pose)
{
if (recentering_context and std::get<0>(*recentering_context) != space)
return std::nullopt;
if (not joints)
if (joints)
{
recentering_context.reset();
return std::nullopt;
}
const auto & palm = (*joints)[XR_HAND_JOINT_PALM_EXT].first;
const auto palm_y = glm::rotate(glm_cast(palm.pose.orientation), glm::vec3(0, 1, 0));
const auto & palm = (*joints)[XR_HAND_JOINT_PALM_EXT].first;
const auto & o = palm.pose.orientation;
const auto & p = palm.pose.position;
glm::quat q{o.w, o.x, o.y, o.z};
glm::vec3 v{p.x, p.y, p.z};
for (XrHandJointEXT index: {
XR_HAND_JOINT_INDEX_PROXIMAL_EXT,
XR_HAND_JOINT_INDEX_INTERMEDIATE_EXT,
XR_HAND_JOINT_INDEX_DISTAL_EXT,
if (glm::dot(q * glm::vec3(0, 1, 0), glm::vec3(0, -1, 0)) > constants::lobby::recenter_cosangle_min)
{
recentering_context.emplace(space, glm::vec3{}, 0);
return v + glm::vec3(0, constants::lobby::recenter_distance_up, 0) + q * glm::vec3(0, 0, -constants::lobby::recenter_distance_front);
XR_HAND_JOINT_MIDDLE_PROXIMAL_EXT,
XR_HAND_JOINT_MIDDLE_INTERMEDIATE_EXT,
XR_HAND_JOINT_MIDDLE_DISTAL_EXT,
XR_HAND_JOINT_RING_PROXIMAL_EXT,
XR_HAND_JOINT_RING_INTERMEDIATE_EXT,
XR_HAND_JOINT_RING_DISTAL_EXT,
XR_HAND_JOINT_LITTLE_PROXIMAL_EXT,
XR_HAND_JOINT_LITTLE_INTERMEDIATE_EXT,
XR_HAND_JOINT_LITTLE_DISTAL_EXT,
})
{
const auto fingertip_y = glm::rotate(glm_cast((*joints)[index].first.pose.orientation), glm::vec3(0, 1, 0));
if (glm::dot(palm_y, fingertip_y) < constants::lobby::recenter_cos_fingertip_angle_max)
{
recentering_context.reset();
return std::nullopt;
}
}
const auto q = glm_cast(palm.pose.orientation);
const auto x = glm_cast(palm.pose.position);
// Make the up vector orthogonal to forward
const glm::vec3 forward = glm::rotate(head_pose.second, glm::vec3{0, 0, -1});
const glm::vec3 up = glm::normalize(glm::vec3{0, 1, 0} - forward * glm::dot(forward, {0, 1, 0}));
// Y is pointing to the back of the hand
if (glm::dot(q * glm::vec3(0, -1, 0), up) > constants::lobby::recenter_cos_palm_angle_min)
{
recentering_context.emplace(space, glm::vec3{}, 0);
return x + glm::rotate(q, glm::vec3{0, -constants::lobby::recenter_distance_up, -constants::lobby::recenter_distance_front});
}
}
recentering_context.reset();
@@ -959,14 +992,14 @@ void scenes::lobby::render(const XrFrameState & frame_state)
hand_model::apply(world, left, right);
if (not new_gui_position)
new_gui_position = check_recenter_gesture(xr::spaces::palm_left, left);
if (not new_gui_position and head_position)
new_gui_position = check_recenter_gesture(xr::spaces::palm_left, left, *head_position);
if (not new_gui_position)
new_gui_position = check_recenter_gesture(xr::spaces::palm_right, right);
if (not new_gui_position and head_position)
new_gui_position = check_recenter_gesture(xr::spaces::palm_right, right, *head_position);
}
if (head_position && new_gui_position)
if (head_position and new_gui_position)
{
move_gui(head_position->first, *new_gui_position);
}
+1 -1
View File
@@ -238,7 +238,7 @@ class lobby : public scene_impl<lobby>
void connect(const configuration::server_data & data);
std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service service, bool manual_connection);
std::optional<glm::vec3> check_recenter_gesture(xr::spaces space, const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints);
std::optional<glm::vec3> check_recenter_gesture(xr::spaces space, const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints, const std::pair<glm::vec3, glm::quat> & head_pose);
std::optional<glm::vec3> check_recenter_action(XrTime predicted_display_time, glm::vec3 head_position);
std::optional<glm::vec3> check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation);
+42
View File
@@ -0,0 +1,42 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <glm/gtc/quaternion.hpp>
#include <openxr/openxr.h>
inline glm::quat glm_cast(const XrQuaternionf & q)
{
return glm::quat::wxyz(q.w, q.x, q.y, q.z);
}
inline XrQuaternionf glm_cast(const glm::quat & q)
{
return XrQuaternionf(q.w, q.x, q.y, q.z);
}
inline glm::vec3 glm_cast(const XrVector3f & v)
{
return glm::vec3(v.x, v.y, v.z);
}
inline XrVector3f glm_cast(const glm::vec3 & v)
{
return XrVector3f(v.x, v.y, v.z);
}