2020-10-12 00:41:35 +00:00
|
|
|
// Copyright 2019-2020, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Hand Tracking API interface.
|
|
|
|
* @author Christoph Haag <christoph.haag@collabora.com>
|
2022-08-01 16:39:35 +00:00
|
|
|
* @author Daniel Willmott <web@dan-w.com>
|
2020-10-12 00:41:35 +00:00
|
|
|
* @ingroup aux_tracking
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "u_hand_tracking.h"
|
|
|
|
|
2020-10-30 19:12:15 +00:00
|
|
|
#include "math/m_mathinclude.h"
|
2020-10-12 00:41:35 +00:00
|
|
|
#include "math/m_api.h"
|
|
|
|
#include "math/m_space.h"
|
2020-11-18 22:42:14 +00:00
|
|
|
#include "math/m_vec3.h"
|
|
|
|
#include "math/m_api.h"
|
2020-10-12 00:41:35 +00:00
|
|
|
|
2022-05-22 13:00:17 +00:00
|
|
|
#include "util/u_time.h"
|
|
|
|
|
|
|
|
|
2020-10-30 19:12:15 +00:00
|
|
|
#define DEG_TO_RAD(DEG) (DEG * M_PI / 180.)
|
2020-10-12 00:41:35 +00:00
|
|
|
|
2020-12-25 22:52:33 +00:00
|
|
|
bool
|
|
|
|
u_hand_joint_is_metacarpal(enum xrt_hand_joint joint)
|
|
|
|
{
|
2021-01-14 14:13:48 +00:00
|
|
|
return joint == XRT_HAND_JOINT_LITTLE_METACARPAL || joint == XRT_HAND_JOINT_RING_METACARPAL ||
|
|
|
|
joint == XRT_HAND_JOINT_MIDDLE_METACARPAL || joint == XRT_HAND_JOINT_INDEX_METACARPAL ||
|
2020-12-25 22:52:33 +00:00
|
|
|
joint == XRT_HAND_JOINT_THUMB_METACARPAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
u_hand_joint_is_proximal(enum xrt_hand_joint joint)
|
|
|
|
{
|
2021-01-14 14:13:48 +00:00
|
|
|
return joint == XRT_HAND_JOINT_LITTLE_PROXIMAL || joint == XRT_HAND_JOINT_RING_PROXIMAL ||
|
|
|
|
joint == XRT_HAND_JOINT_MIDDLE_PROXIMAL || joint == XRT_HAND_JOINT_INDEX_PROXIMAL ||
|
2020-12-25 22:52:33 +00:00
|
|
|
joint == XRT_HAND_JOINT_THUMB_PROXIMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
u_hand_joint_is_intermediate(enum xrt_hand_joint joint)
|
|
|
|
{
|
2021-01-14 14:13:48 +00:00
|
|
|
return joint == XRT_HAND_JOINT_LITTLE_INTERMEDIATE || joint == XRT_HAND_JOINT_RING_INTERMEDIATE ||
|
|
|
|
joint == XRT_HAND_JOINT_MIDDLE_INTERMEDIATE || joint == XRT_HAND_JOINT_INDEX_INTERMEDIATE;
|
2020-12-25 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
u_hand_joint_is_distal(enum xrt_hand_joint joint)
|
|
|
|
{
|
2021-01-14 14:13:48 +00:00
|
|
|
return joint == XRT_HAND_JOINT_LITTLE_DISTAL || joint == XRT_HAND_JOINT_RING_DISTAL ||
|
|
|
|
joint == XRT_HAND_JOINT_MIDDLE_DISTAL || joint == XRT_HAND_JOINT_INDEX_DISTAL ||
|
2020-12-25 22:52:33 +00:00
|
|
|
joint == XRT_HAND_JOINT_THUMB_DISTAL;
|
|
|
|
}
|
|
|
|
|
2020-10-12 00:41:35 +00:00
|
|
|
bool
|
|
|
|
u_hand_joint_is_tip(enum xrt_hand_joint joint)
|
|
|
|
{
|
2021-01-14 14:13:48 +00:00
|
|
|
return joint == XRT_HAND_JOINT_LITTLE_TIP || joint == XRT_HAND_JOINT_RING_TIP ||
|
|
|
|
joint == XRT_HAND_JOINT_MIDDLE_TIP || joint == XRT_HAND_JOINT_INDEX_TIP ||
|
2020-10-12 00:41:35 +00:00
|
|
|
joint == XRT_HAND_JOINT_THUMB_TIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-12-25 22:52:33 +00:00
|
|
|
u_hand_joint_is_thumb(enum xrt_hand_joint joint)
|
2020-10-12 00:41:35 +00:00
|
|
|
{
|
2021-01-14 14:13:48 +00:00
|
|
|
return joint == XRT_HAND_JOINT_THUMB_METACARPAL || joint == XRT_HAND_JOINT_THUMB_PROXIMAL ||
|
|
|
|
joint == XRT_HAND_JOINT_THUMB_DISTAL || joint == XRT_HAND_JOINT_THUMB_TIP;
|
2020-10-12 00:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-04-26 20:20:13 +00:00
|
|
|
u_hand_joints_offset_valve_index_controller(enum xrt_hand hand,
|
|
|
|
const struct xrt_vec3 *static_offset,
|
|
|
|
struct xrt_pose *offset)
|
2020-10-12 00:41:35 +00:00
|
|
|
{
|
|
|
|
/* Controller space origin is at the very tip of the controller,
|
|
|
|
* handle pointing forward at -z.
|
|
|
|
*
|
|
|
|
* Transform joints into controller space by rotating "outwards" around
|
|
|
|
* -z "forward" by -75/75 deg. Then, rotate "forward" around x by 72
|
|
|
|
* deg.
|
|
|
|
*
|
|
|
|
* Then position everything at static_offset..
|
|
|
|
*
|
|
|
|
* Now the hand points "through the strap" like at normal use.
|
|
|
|
*/
|
2021-04-26 21:08:10 +00:00
|
|
|
const struct xrt_vec3 x = XRT_VEC3_UNIT_X;
|
|
|
|
const struct xrt_vec3 y = XRT_VEC3_UNIT_Y;
|
|
|
|
const struct xrt_vec3 negative_z = {0, 0, -1};
|
2020-10-12 00:41:35 +00:00
|
|
|
|
|
|
|
float hand_on_handle_x_rotation = DEG_TO_RAD(-72);
|
|
|
|
float hand_on_handle_y_rotation = 0;
|
|
|
|
float hand_on_handle_z_rotation = 0;
|
|
|
|
if (hand == XRT_HAND_LEFT) {
|
|
|
|
hand_on_handle_z_rotation = DEG_TO_RAD(-75);
|
|
|
|
} else if (hand == XRT_HAND_RIGHT) {
|
|
|
|
hand_on_handle_z_rotation = DEG_TO_RAD(75);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-26 20:04:47 +00:00
|
|
|
struct xrt_quat hand_rotation_y = XRT_QUAT_IDENTITY;
|
2021-01-14 14:13:48 +00:00
|
|
|
math_quat_from_angle_vector(hand_on_handle_y_rotation, &y, &hand_rotation_y);
|
2020-10-12 00:41:35 +00:00
|
|
|
|
2021-04-26 20:04:47 +00:00
|
|
|
struct xrt_quat hand_rotation_z = XRT_QUAT_IDENTITY;
|
2021-04-26 21:08:10 +00:00
|
|
|
math_quat_from_angle_vector(hand_on_handle_z_rotation, &negative_z, &hand_rotation_z);
|
2020-10-12 00:41:35 +00:00
|
|
|
|
2021-04-26 20:04:47 +00:00
|
|
|
struct xrt_quat hand_rotation_x = XRT_QUAT_IDENTITY;
|
2021-01-14 14:13:48 +00:00
|
|
|
math_quat_from_angle_vector(hand_on_handle_x_rotation, &x, &hand_rotation_x);
|
2020-10-12 00:41:35 +00:00
|
|
|
|
|
|
|
struct xrt_quat hand_rotation;
|
|
|
|
math_quat_rotate(&hand_rotation_x, &hand_rotation_z, &hand_rotation);
|
|
|
|
|
2021-01-14 14:13:48 +00:00
|
|
|
struct xrt_pose hand_on_handle_pose = {.orientation = hand_rotation, .position = *static_offset};
|
2020-10-12 00:41:35 +00:00
|
|
|
|
|
|
|
*offset = hand_on_handle_pose;
|
|
|
|
}
|