mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-21 06:01:43 +00:00
xrt: Add support for locating hand joints in action spaces
This commit is contained in:
parent
95af586654
commit
f5ef3985ba
|
@ -668,10 +668,11 @@ u_hand_joints_set_out_data(struct u_hand_tracking *set,
|
||||||
enum xrt_hand hand,
|
enum xrt_hand hand,
|
||||||
struct xrt_space_relation *hand_relation,
|
struct xrt_space_relation *hand_relation,
|
||||||
struct xrt_pose *hand_offset,
|
struct xrt_pose *hand_offset,
|
||||||
union xrt_hand_joint_set *out_value)
|
struct xrt_hand_joint_set *out_value)
|
||||||
{
|
{
|
||||||
|
|
||||||
struct xrt_hand_joint_value *l = out_value->hand_joint_set_default;
|
struct xrt_hand_joint_value *l =
|
||||||
|
out_value->values.hand_joint_set_default;
|
||||||
|
|
||||||
for (int i = 0; i < XRT_HAND_JOINT_COUNT; i++) {
|
for (int i = 0; i < XRT_HAND_JOINT_COUNT; i++) {
|
||||||
l[i].relation.relation_flags |=
|
l[i].relation.relation_flags |=
|
||||||
|
@ -685,23 +686,13 @@ u_hand_joints_set_out_data(struct u_hand_tracking *set,
|
||||||
|
|
||||||
struct u_joint_space_relation *data = get_joint_data(set, i);
|
struct u_joint_space_relation *data = get_joint_data(set, i);
|
||||||
|
|
||||||
// transform poses from "hand space" to "controller space in
|
struct xrt_space_graph graph = {0};
|
||||||
// world space"
|
m_space_graph_add_relation(&graph, &data->relation);
|
||||||
struct xrt_space_relation transformed;
|
m_space_graph_add_pose(&graph, hand_offset);
|
||||||
|
m_space_graph_resolve(&graph, &l[i].relation);
|
||||||
transformed.pose = data->relation.pose;
|
|
||||||
|
|
||||||
//! @todo: transform velocities
|
|
||||||
math_pose_transform(hand_offset, &data->relation.pose,
|
|
||||||
&transformed.pose);
|
|
||||||
|
|
||||||
math_pose_transform(&hand_relation->pose, &transformed.pose,
|
|
||||||
&transformed.pose);
|
|
||||||
|
|
||||||
|
|
||||||
//! @todo handle velocities
|
|
||||||
l[i].relation.pose = transformed.pose;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out_value->hand_origin = *hand_relation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -133,7 +133,7 @@ u_hand_joints_set_out_data(struct u_hand_tracking *set,
|
||||||
enum xrt_hand hand,
|
enum xrt_hand hand,
|
||||||
struct xrt_space_relation *hand_relation,
|
struct xrt_space_relation *hand_relation,
|
||||||
struct xrt_pose *hand_offset,
|
struct xrt_pose *hand_offset,
|
||||||
union xrt_hand_joint_set *out_value);
|
struct xrt_hand_joint_set *out_value);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -454,7 +454,7 @@ static void
|
||||||
survive_controller_get_hand_tracking(struct xrt_device *xdev,
|
survive_controller_get_hand_tracking(struct xrt_device *xdev,
|
||||||
enum xrt_input_name name,
|
enum xrt_input_name name,
|
||||||
uint64_t at_timestamp_ns,
|
uint64_t at_timestamp_ns,
|
||||||
union xrt_hand_joint_set *out_value)
|
struct xrt_hand_joint_set *out_value)
|
||||||
{
|
{
|
||||||
struct survive_device *survive = (struct survive_device *)xdev;
|
struct survive_device *survive = (struct survive_device *)xdev;
|
||||||
|
|
||||||
|
|
|
@ -324,7 +324,7 @@ static void
|
||||||
vive_controller_get_hand_tracking(struct xrt_device *xdev,
|
vive_controller_get_hand_tracking(struct xrt_device *xdev,
|
||||||
enum xrt_input_name name,
|
enum xrt_input_name name,
|
||||||
uint64_t at_timestamp_ns,
|
uint64_t at_timestamp_ns,
|
||||||
union xrt_hand_joint_set *out_value)
|
struct xrt_hand_joint_set *out_value)
|
||||||
{
|
{
|
||||||
struct vive_controller_device *d = vive_controller_device(xdev);
|
struct vive_controller_device *d = vive_controller_device(xdev);
|
||||||
|
|
||||||
|
@ -369,6 +369,10 @@ vive_controller_get_hand_tracking(struct xrt_device *xdev,
|
||||||
struct xrt_space_relation controller_relation = {
|
struct xrt_space_relation controller_relation = {
|
||||||
.pose = {.orientation = d->rot_filtered,
|
.pose = {.orientation = d->rot_filtered,
|
||||||
.position = {0, 0, pivot_offset_z}}};
|
.position = {0, 0, pivot_offset_z}}};
|
||||||
|
controller_relation.relation_flags =
|
||||||
|
XRT_SPACE_RELATION_ORIENTATION_VALID_BIT |
|
||||||
|
XRT_SPACE_RELATION_ORIENTATION_VALID_BIT |
|
||||||
|
XRT_SPACE_RELATION_POSITION_VALID_BIT;
|
||||||
|
|
||||||
struct xrt_vec3 static_offset = {0, 0, 0};
|
struct xrt_vec3 static_offset = {0, 0, 0};
|
||||||
|
|
||||||
|
|
|
@ -663,9 +663,15 @@ enum xrt_finger
|
||||||
*
|
*
|
||||||
* @ingroup xrt_iface
|
* @ingroup xrt_iface
|
||||||
*/
|
*/
|
||||||
union xrt_hand_joint_set {
|
struct xrt_hand_joint_set
|
||||||
struct xrt_hand_joint_value
|
{
|
||||||
hand_joint_set_default[XRT_HAND_JOINT_COUNT];
|
union {
|
||||||
|
struct xrt_hand_joint_value
|
||||||
|
hand_joint_set_default[XRT_HAND_JOINT_COUNT];
|
||||||
|
} values;
|
||||||
|
|
||||||
|
// in driver global space, without tracking_origin offset
|
||||||
|
struct xrt_space_relation hand_origin;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -305,7 +305,7 @@ struct xrt_device
|
||||||
void (*get_hand_tracking)(struct xrt_device *xdev,
|
void (*get_hand_tracking)(struct xrt_device *xdev,
|
||||||
enum xrt_input_name name,
|
enum xrt_input_name name,
|
||||||
uint64_t at_timestamp_ns,
|
uint64_t at_timestamp_ns,
|
||||||
union xrt_hand_joint_set *out_value);
|
struct xrt_hand_joint_set *out_value);
|
||||||
/*!
|
/*!
|
||||||
* Set a output value.
|
* Set a output value.
|
||||||
*
|
*
|
||||||
|
@ -389,7 +389,7 @@ static inline void
|
||||||
xrt_device_get_hand_tracking(struct xrt_device *xdev,
|
xrt_device_get_hand_tracking(struct xrt_device *xdev,
|
||||||
enum xrt_input_name name,
|
enum xrt_input_name name,
|
||||||
uint64_t requested_timestamp_ns,
|
uint64_t requested_timestamp_ns,
|
||||||
union xrt_hand_joint_set *out_value)
|
struct xrt_hand_joint_set *out_value)
|
||||||
{
|
{
|
||||||
xdev->get_hand_tracking(xdev, name, requested_timestamp_ns, out_value);
|
xdev->get_hand_tracking(xdev, name, requested_timestamp_ns, out_value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ void
|
||||||
ipc_client_device_get_hand_tracking(struct xrt_device *xdev,
|
ipc_client_device_get_hand_tracking(struct xrt_device *xdev,
|
||||||
enum xrt_input_name name,
|
enum xrt_input_name name,
|
||||||
uint64_t at_timestamp_ns,
|
uint64_t at_timestamp_ns,
|
||||||
union xrt_hand_joint_set *out_value)
|
struct xrt_hand_joint_set *out_value)
|
||||||
{
|
{
|
||||||
struct ipc_client_device *icd = ipc_client_device(xdev);
|
struct ipc_client_device *icd = ipc_client_device(xdev);
|
||||||
|
|
||||||
|
|
|
@ -598,7 +598,7 @@ ipc_handle_device_get_hand_tracking(volatile struct ipc_client_state *ics,
|
||||||
uint32_t id,
|
uint32_t id,
|
||||||
enum xrt_input_name name,
|
enum xrt_input_name name,
|
||||||
uint64_t at_timestamp,
|
uint64_t at_timestamp,
|
||||||
union xrt_hand_joint_set *out_value)
|
struct xrt_hand_joint_set *out_value)
|
||||||
{
|
{
|
||||||
|
|
||||||
// To make the code a bit more readable.
|
// To make the code a bit more readable.
|
||||||
|
|
|
@ -187,7 +187,7 @@
|
||||||
{"name": "at_timestamp", "type": "uint64_t"}
|
{"name": "at_timestamp", "type": "uint64_t"}
|
||||||
],
|
],
|
||||||
"out": [
|
"out": [
|
||||||
{"name": "value", "type": "union xrt_hand_joint_set"}
|
{"name": "value", "type": "struct xrt_hand_joint_set"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -942,7 +942,7 @@ oxr_xdev_get_hand_tracking_at(struct oxr_logger *log,
|
||||||
struct xrt_device *xdev,
|
struct xrt_device *xdev,
|
||||||
enum xrt_input_name name,
|
enum xrt_input_name name,
|
||||||
XrTime at_time,
|
XrTime at_time,
|
||||||
union xrt_hand_joint_set *out_value);
|
struct xrt_hand_joint_set *out_value);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
|
|
@ -2351,7 +2351,7 @@ oxr_session_hand_joints(struct oxr_logger *log,
|
||||||
&xdev->tracking_origin->offset;
|
&xdev->tracking_origin->offset;
|
||||||
|
|
||||||
XrTime at_time = locateInfo->time;
|
XrTime at_time = locateInfo->time;
|
||||||
union xrt_hand_joint_set value;
|
struct xrt_hand_joint_set value;
|
||||||
|
|
||||||
enum xrt_input_name name;
|
enum xrt_input_name name;
|
||||||
if (hand_tracker->hand_joint_set == XR_HAND_JOINT_SET_DEFAULT_EXT) {
|
if (hand_tracker->hand_joint_set == XR_HAND_JOINT_SET_DEFAULT_EXT) {
|
||||||
|
@ -2365,27 +2365,74 @@ oxr_session_hand_joints(struct oxr_logger *log,
|
||||||
&value);
|
&value);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < locations->jointCount; i++) {
|
for (uint32_t i = 0; i < locations->jointCount; i++) {
|
||||||
locations->jointLocations[i]
|
locations->jointLocations[i].locationFlags =
|
||||||
.locationFlags = xrt_to_xr_space_location_flags(
|
xrt_to_xr_space_location_flags(
|
||||||
value.hand_joint_set_default[i].relation.relation_flags);
|
value.values.hand_joint_set_default[i]
|
||||||
|
.relation.relation_flags);
|
||||||
locations->jointLocations[i].radius =
|
locations->jointLocations[i].radius =
|
||||||
value.hand_joint_set_default[i].radius;
|
value.values.hand_joint_set_default[i].radius;
|
||||||
|
|
||||||
struct xrt_space_relation r =
|
struct xrt_space_relation r =
|
||||||
value.hand_joint_set_default[i].relation;
|
value.values.hand_joint_set_default[i].relation;
|
||||||
|
|
||||||
struct xrt_space_relation result;
|
struct xrt_space_relation result;
|
||||||
struct xrt_space_graph graph = {0};
|
struct xrt_space_graph graph = {0};
|
||||||
m_space_graph_add_relation(&graph, &r);
|
m_space_graph_add_relation(&graph, &r);
|
||||||
m_space_graph_add_pose_if_not_identity(&graph,
|
|
||||||
tracking_origin_offset);
|
|
||||||
|
if (baseSpc->type == XR_REFERENCE_SPACE_TYPE_STAGE) {
|
||||||
|
|
||||||
|
m_space_graph_add_relation(&graph, &value.hand_origin);
|
||||||
|
m_space_graph_add_pose_if_not_identity(
|
||||||
|
&graph, tracking_origin_offset);
|
||||||
|
|
||||||
|
} else if (baseSpc->type == XR_REFERENCE_SPACE_TYPE_LOCAL) {
|
||||||
|
|
||||||
|
// for local space, first do stage space and transform
|
||||||
|
// result to local @todo: improve local space
|
||||||
|
m_space_graph_add_relation(&graph, &value.hand_origin);
|
||||||
|
m_space_graph_add_pose_if_not_identity(
|
||||||
|
&graph, tracking_origin_offset);
|
||||||
|
|
||||||
|
} else if (!baseSpc->is_reference) {
|
||||||
|
// action space
|
||||||
|
|
||||||
|
struct oxr_action_input *input = NULL;
|
||||||
|
oxr_action_get_pose_input(log, sess, baseSpc->act_key,
|
||||||
|
&baseSpc->sub_paths, &input);
|
||||||
|
|
||||||
|
// If the input isn't active.
|
||||||
|
if (input == NULL) {
|
||||||
|
locations->isActive = false;
|
||||||
|
return XR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct xrt_space_relation act_space_relation;
|
||||||
|
|
||||||
|
oxr_xdev_get_space_relation(
|
||||||
|
log, sess->sys->inst, input->xdev,
|
||||||
|
input->input->name, at_time, &act_space_relation);
|
||||||
|
|
||||||
|
|
||||||
|
m_space_graph_add_relation(&graph, &value.hand_origin);
|
||||||
|
m_space_graph_add_pose_if_not_identity(
|
||||||
|
&graph, tracking_origin_offset);
|
||||||
|
|
||||||
|
m_space_graph_add_inverted_relation(
|
||||||
|
&graph, &act_space_relation);
|
||||||
|
m_space_graph_add_inverted_pose_if_not_identity(
|
||||||
|
&graph, &input->xdev->tracking_origin->offset);
|
||||||
|
}
|
||||||
|
|
||||||
m_space_graph_add_inverted_pose_if_not_identity(&graph,
|
m_space_graph_add_inverted_pose_if_not_identity(&graph,
|
||||||
&baseSpc->pose);
|
&baseSpc->pose);
|
||||||
m_space_graph_resolve(&graph, &result);
|
m_space_graph_resolve(&graph, &result);
|
||||||
|
|
||||||
//! @todo need general handling of local space
|
|
||||||
if (baseSpc->type == XR_REFERENCE_SPACE_TYPE_LOCAL) {
|
if (baseSpc->type == XR_REFERENCE_SPACE_TYPE_LOCAL) {
|
||||||
global_to_local_space(sess, &result);
|
if (!global_to_local_space(sess, &result)) {
|
||||||
|
locations->isActive = false;
|
||||||
|
return XR_SUCCESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xrt_to_xr_pose(&result.pose,
|
xrt_to_xr_pose(&result.pose,
|
||||||
|
@ -2394,5 +2441,5 @@ oxr_session_hand_joints(struct oxr_logger *log,
|
||||||
|
|
||||||
locations->isActive = true;
|
locations->isActive = true;
|
||||||
|
|
||||||
return true;
|
return XR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,13 +107,13 @@ oxr_xdev_get_hand_tracking_at(struct oxr_logger *log,
|
||||||
struct xrt_device *xdev,
|
struct xrt_device *xdev,
|
||||||
enum xrt_input_name name,
|
enum xrt_input_name name,
|
||||||
XrTime at_time,
|
XrTime at_time,
|
||||||
union xrt_hand_joint_set *out_value)
|
struct xrt_hand_joint_set *out_value)
|
||||||
{
|
{
|
||||||
//! @todo Convert at_time to monotonic and give to device.
|
//! @todo Convert at_time to monotonic and give to device.
|
||||||
uint64_t at_timestamp_ns = os_monotonic_get_ns();
|
uint64_t at_timestamp_ns = os_monotonic_get_ns();
|
||||||
(void)at_time;
|
(void)at_time;
|
||||||
|
|
||||||
union xrt_hand_joint_set value;
|
struct xrt_hand_joint_set value;
|
||||||
|
|
||||||
xrt_device_get_hand_tracking(xdev, name, at_timestamp_ns, &value);
|
xrt_device_get_hand_tracking(xdev, name, at_timestamp_ns, &value);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue