d/remote: Update protocol to allow per view data

This commit is contained in:
Jakob Bornecrantz 2022-11-06 03:17:43 +00:00 committed by Jakob Bornecrantz
parent a8dc902468
commit 89aee1892b
4 changed files with 73 additions and 23 deletions

View file

@ -35,6 +35,15 @@ r_hmd(struct xrt_device *xdev)
return (struct r_hmd *)xdev; return (struct r_hmd *)xdev;
} }
static inline void
copy_head_center_to_relation(struct r_hmd *rh, struct xrt_space_relation *out_relation)
{
out_relation->pose = rh->r->latest.head.center;
out_relation->relation_flags = (enum xrt_space_relation_flags)(
XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | XRT_SPACE_RELATION_POSITION_VALID_BIT |
XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT | XRT_SPACE_RELATION_POSITION_TRACKED_BIT);
}
static void static void
r_hmd_destroy(struct xrt_device *xdev) r_hmd_destroy(struct xrt_device *xdev)
{ {
@ -67,10 +76,7 @@ r_hmd_get_tracked_pose(struct xrt_device *xdev,
return; return;
} }
out_relation->pose = rh->r->latest.hmd.pose; copy_head_center_to_relation(rh, out_relation);
out_relation->relation_flags = (enum xrt_space_relation_flags)(
XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | XRT_SPACE_RELATION_POSITION_VALID_BIT |
XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT | XRT_SPACE_RELATION_POSITION_TRACKED_BIT);
} }
static void static void
@ -93,8 +99,33 @@ r_hmd_get_view_poses(struct xrt_device *xdev,
struct xrt_fov *out_fovs, struct xrt_fov *out_fovs,
struct xrt_pose *out_poses) struct xrt_pose *out_poses)
{ {
u_device_get_view_poses(xdev, default_eye_relation, at_timestamp_ns, view_count, out_head_relation, out_fovs, struct r_hmd *rh = r_hmd(xdev);
out_poses);
if (!rh->r->latest.head.per_view_data_valid) {
u_device_get_view_poses( //
xdev, //
default_eye_relation, //
at_timestamp_ns, //
view_count, //
out_head_relation, //
out_fovs, //
out_poses); //
// Done now
return;
}
if (view_count > ARRAY_SIZE(rh->r->latest.head.views)) {
U_LOG_E("Asking for too many views!");
return;
}
copy_head_center_to_relation(rh, out_head_relation);
for (uint32_t i = 0; i < view_count; i++) {
out_poses[i] = rh->r->latest.head.views[i].pose;
out_fovs[i] = rh->r->latest.head.views[i].fov;
}
} }
static void static void

View file

@ -286,9 +286,9 @@ r_create_devices(uint16_t port, struct xrt_system_devices **out_xsysd)
r->base.destroy = r_hub_system_devices_destroy; r->base.destroy = r_hub_system_devices_destroy;
r->origin.type = XRT_TRACKING_TYPE_RGB; r->origin.type = XRT_TRACKING_TYPE_RGB;
r->origin.offset.orientation.w = 1.0f; // All other members are zero. r->origin.offset = (struct xrt_pose)XRT_POSE_IDENTITY;
r->reset.hmd.pose.position.y = 1.6f; r->reset.head.center = (struct xrt_pose)XRT_POSE_IDENTITY;
r->reset.hmd.pose.orientation.w = 1.0f; r->reset.head.center.position.y = 1.6f;
r->reset.left.active = true; r->reset.left.active = true;
r->reset.left.hand_tracking_active = true; r->reset.left.hand_tracking_active = true;
r->reset.left.pose.position.x = -0.2f; r->reset.left.pose.position.x = -0.2f;
@ -353,7 +353,7 @@ r_create_devices(uint16_t port, struct xrt_system_devices **out_xsysd)
u_var_add_root(r, "Remote Hub", true); u_var_add_root(r, "Remote Hub", true);
// u_var_add_gui_header(r, &r->gui.hmd, "MHD"); // u_var_add_gui_header(r, &r->gui.hmd, "MHD");
u_var_add_pose(r, &r->latest.hmd.pose, "hmd.pose"); u_var_add_pose(r, &r->latest.head.center, "head.center");
// u_var_add_gui_header(r, &r->gui.left, "Left"); // u_var_add_gui_header(r, &r->gui.left, "Left");
u_var_add_bool(r, &r->latest.left.active, "left.active"); u_var_add_bool(r, &r->latest.left.active, "left.active");
u_var_add_pose(r, &r->latest.left.pose, "left.pose"); u_var_add_pose(r, &r->latest.left.pose, "left.pose");

View file

@ -38,7 +38,7 @@ struct xrt_system_devices;
* *
* @ingroup drv_remote * @ingroup drv_remote
*/ */
#define R_HEADER_VALUE (*(uint64_t *)"mndrmt2\0") #define R_HEADER_VALUE (*(uint64_t *)"mndrmt3\0")
/*! /*!
* Data per controller. * Data per controller.
@ -78,6 +78,30 @@ struct r_remote_controller_data
// active(2) + bools(11) + pad(3) = 16 // active(2) + bools(11) + pad(3) = 16
}; };
struct r_head_data
{
struct
{
//! The field of view values of this view.
struct xrt_fov fov;
//! The pose of this view relative to @ref r_head_data::center.
struct xrt_pose pose;
//! Padded to fov(16) + pose(16 + 12) + 4 = 48
uint32_t _pad;
} views[2];
//! The center of the head, in OpenXR terms the view space.
struct xrt_pose center;
//! Is the per view data valid and should be used?
bool per_view_data_valid;
//! pose(16 + 12) bool(1) + pad(3) = 32.
bool _pad0, _pad1, _pad2;
};
/*! /*!
* Remote data sent from the debugger to the hub. * Remote data sent from the debugger to the hub.
* *
@ -87,10 +111,7 @@ struct r_remote_data
{ {
uint64_t header; uint64_t header;
struct struct r_head_data head;
{
struct xrt_pose pose;
} hmd;
struct r_remote_controller_data left, right; struct r_remote_controller_data left, right;
}; };

View file

@ -298,10 +298,8 @@ render_cheat_menu(struct gui_remote *gr, struct gui_program *p)
#define POSE(prefix) \ #define POSE(prefix) \
do { \ do { \
handle_draggable_vec3_f32(#prefix ".pose.position", &d->prefix.pose.position, \ handle_draggable_vec3_f32(#prefix ".pose.position", &d->prefix.position, &r->prefix.position); \
&r->prefix.pose.position); \ handle_draggable_quat(#prefix ".pose.orientation", &d->prefix.orientation, &r->prefix.orientation); \
handle_draggable_quat(#prefix ".pose.orientation", &d->prefix.pose.orientation, \
&r->prefix.pose.orientation); \
} while (false) } while (false)
#define LIN_ANG(prefix) \ #define LIN_ANG(prefix) \
@ -334,19 +332,19 @@ on_connected(struct gui_remote *gr, struct gui_program *p)
const struct r_remote_data *r = &gr->reset; const struct r_remote_data *r = &gr->reset;
struct r_remote_data *d = &gr->data; struct r_remote_data *d = &gr->data;
igPushIDPtr(&d->hmd); // Make all IDs unique. igPushIDPtr(&d->head); // Make all IDs unique.
POSE(hmd); POSE(head.center);
igPopID(); // Pop unique IDs igPopID(); // Pop unique IDs
igPushIDPtr(&d->left); // Make all IDs unique. igPushIDPtr(&d->left); // Make all IDs unique.
POSE(left); POSE(left.pose);
LIN_ANG(left); LIN_ANG(left);
BUTTONS(left); BUTTONS(left);
HAND(left); HAND(left);
igPopID(); // Pop unique IDs igPopID(); // Pop unique IDs
igPushIDPtr(&d->right); // Make all IDs unique. igPushIDPtr(&d->right); // Make all IDs unique.
POSE(right); POSE(right.pose);
LIN_ANG(right); LIN_ANG(right);
BUTTONS(right); BUTTONS(right);
HAND(right); HAND(right);