a/util: Add eye and face tracking to the builder roles helper
Co-authored-by: Korcan Hussein <korcan.hussein@collabora.com> Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2649>
102 unmodified linesExpand all10310410510610710810911011111211311411511611711822 unmodified lines14114214314414314414514614714814915014614715115215315415515615715815916016116216316416516616716816917017117217317417514915015115215315415517617717817918018118218318418513 unmodified lines19920020120220320420520620756 unmodified lines26426526626726826927027127227314 unmodified lines28828929029129229329429529627 unmodified lines102 unmodified linesExpand all}
voidu_builder_setup_tracking_origins(struct xrt_device *head, struct xrt_device *eyes, struct xrt_device *left, struct xrt_device *right, struct xrt_device *gamepad, struct xrt_vec3 *global_tracking_origin_offset){ struct xrt_tracking_origin *head_origin = head ? head->tracking_origin : NULL; struct xrt_tracking_origin *eyes_origin = eyes ? eyes->tracking_origin : NULL; struct xrt_tracking_origin *left_origin = left ? left->tracking_origin : NULL; struct xrt_tracking_origin *right_origin = right ? right->tracking_origin : NULL; struct xrt_tracking_origin *gamepad_origin = gamepad ? gamepad->tracking_origin : NULL;
22 unmodified lines head_origin->initial_offset.position.y = 1.6f; head_origin->initial_offset.position.z = 0.0f; }
if (head_origin) { apply_offset(&head_origin->initial_offset.position, global_tracking_origin_offset); if (eyes_origin != NULL && eyes_origin->type == XRT_TRACKING_TYPE_NONE) { // "nominal height" 1.6m eyes_origin->initial_offset.position.x = 0.0f; eyes_origin->initial_offset.position.y = 1.6f; eyes_origin->initial_offset.position.z = 0.0f; } if (left_origin && left_origin != head_origin) { apply_offset(&left->tracking_origin->initial_offset.position, global_tracking_origin_offset);
struct xrt_tracking_origin *origins[] = {head_origin, eyes_origin, left_origin, right_origin, gamepad_origin}; bool applied[ARRAY_SIZE(origins)] = {false};
for (size_t i = 0; i < ARRAY_SIZE(origins); i++) { struct xrt_tracking_origin *origin = origins[i];
if (origin == NULL) { continue; }
// Check if we already applied offset to this origin bool already_applied = false; for (size_t j = 0; j < i; j++) { if (origins[j] == origin && applied[j]) { already_applied = true; break; } }
if (!already_applied) { apply_offset(&origin->initial_offset.position, global_tracking_origin_offset); applied[i] = true; } } if (right_origin && right_origin != head_origin && right_origin != left_origin) { apply_offset(&right->tracking_origin->initial_offset.position, global_tracking_origin_offset); } if (gamepad_origin && gamepad_origin != head_origin && gamepad_origin != right_origin && gamepad_origin != left_origin) { apply_offset(&gamepad->tracking_origin->initial_offset.position, global_tracking_origin_offset); }}
voidu_builder_create_space_overseer_legacy(struct xrt_session_event_sink *broadcast, struct xrt_device *head, struct xrt_device *eyes, struct xrt_device *left, struct xrt_device *right, struct xrt_device *gamepad, struct xrt_device **xdevs,13 unmodified lines };
u_builder_setup_tracking_origins( // head, // eyes, // left, // right, // gamepad, // &global_tracking_origin_offset); //56 unmodified lines * Assign to role(s). */
xsysd->static_roles.head = ubrh.head; xsysd->static_roles.eyes = ubrh.eyes; xsysd->static_roles.face = ubrh.face;#define U_SET_HT_ROLE(SRC) \ xsysd->static_roles.hand_tracking.SRC.left = ubrh.hand_tracking.SRC.left; \ xsysd->static_roles.hand_tracking.SRC.right = ubrh.hand_tracking.SRC.right; U_SET_HT_ROLE(unobstructed)14 unmodified lines *out_xsysd = xsysd; u_builder_create_space_overseer_legacy( // broadcast, // broadcast ubrh.head, // head ubrh.eyes, // eyes ubrh.left, // left ubrh.right, // right ubrh.gamepad, // gamepad xsysd->xdevs, // xdevs27 unmodified lines81 unmodified lines8283848586878889909173 unmodified lines1651661671681691701711721738 unmodified lines18218318418518618718818919048 unmodified lines81 unmodified lines */struct u_builder_roles_helper{ struct xrt_device *head; struct xrt_device *eyes; struct xrt_device *face; struct xrt_device *left; struct xrt_device *right; struct xrt_device *gamepad;
73 unmodified lines * @ingroup aux_util */voidu_builder_setup_tracking_origins(struct xrt_device *head, struct xrt_device *eyes, struct xrt_device *left, struct xrt_device *right, struct xrt_device *gamepad, struct xrt_vec3 *global_tracking_origin_offset);8 unmodified lines */voidu_builder_create_space_overseer_legacy(struct xrt_session_event_sink *broadcast, struct xrt_device *head, struct xrt_device *eyes, struct xrt_device *left, struct xrt_device *right, struct xrt_device *gamepad, struct xrt_device **xdevs,48 unmodified lines358 unmodified linesExpand all3593603613623633643653663673683693703713723733743753763643773783793803813823833843853868 unmodified lines39539639739839940040140240340440540640740840941041141237 unmodified lines450451452453454455456457458459460461462463464465466467468469470471472473474475476143 unmodified linesExpand all358 unmodified linesExpand all *hand = XRT_DEVICE_ROLE_UNASSIGNED; }}
static boolinput_name_is_face_tracker(enum xrt_input_name name){ switch (name) { case XRT_INPUT_FB_FACE_TRACKING2_VISUAL: case XRT_INPUT_FB_FACE_TRACKING2_AUDIO: case XRT_INPUT_ANDROID_FACE_TRACKING: case XRT_INPUT_HTC_EYE_FACE_TRACKING: case XRT_INPUT_HTC_LIP_FACE_TRACKING: return true; default: return false; }}
voidu_device_assign_xdev_roles(struct xrt_device **xdevs, size_t xdev_count, int *head, int *left, int *right, int *gamepad)u_device_assign_xdev_roles( struct xrt_device **xdevs, size_t xdev_count, int *head, int *eyes, int *face, int *left, int *right, int *gamepad){ *head = XRT_DEVICE_ROLE_UNASSIGNED; *eyes = XRT_DEVICE_ROLE_UNASSIGNED; *face = XRT_DEVICE_ROLE_UNASSIGNED; *left = XRT_DEVICE_ROLE_UNASSIGNED; *right = XRT_DEVICE_ROLE_UNASSIGNED; *gamepad = XRT_DEVICE_ROLE_UNASSIGNED; assert(xdev_count < INT_MAX);8 unmodified lines if (*head == XRT_DEVICE_ROLE_UNASSIGNED) { *head = (int)i; } break; case XRT_DEVICE_TYPE_EYE_TRACKER: if (*eyes == XRT_DEVICE_ROLE_UNASSIGNED) { *eyes = (int)i; } break; case XRT_DEVICE_TYPE_FACE_TRACKER: if (*face == XRT_DEVICE_ROLE_UNASSIGNED) { *face = (int)i; } break; case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER: try_move_assignment(xdevs, left, right); if (*left == XRT_DEVICE_ROLE_UNASSIGNED) { *left = (int)i;37 unmodified lines } break; } }
// fill unassigned hand/face with other devices that contain the correct inputs for eye/face tracking for (size_t i = 0; i < xdev_count; i++) { struct xrt_device *xdev = xdevs[i];
if (xdev == NULL) { continue; }
for (size_t j = 0; j < xdev->input_count; j++) { enum xrt_input_name input_name = xdev->inputs[j].name; if (*eyes == XRT_DEVICE_ROLE_UNASSIGNED && input_name == XRT_INPUT_GENERIC_EYE_GAZE_POSE) { *eyes = (int)i; } if (*face == XRT_DEVICE_ROLE_UNASSIGNED && input_name_is_face_tracker(input_name)) { *face = (int)i; } } }}
voidu_device_get_view_pose(const struct xrt_vec3 *eye_relation, uint32_t view_index, struct xrt_pose *out_pose)143 unmodified linesExpand all135 unmodified linesExpand all136137138139140140141142143144107 unmodified linesExpand all135 unmodified linesExpand all * @ingroup aux_util */voidu_device_assign_xdev_roles( struct xrt_device **xdevs, size_t xdev_count, int *head, int *left, int *right, int *gamepad); struct xrt_device **xdevs, size_t xdev_count, int *head, int *eyes, int *face, int *left, int *right, int *gamepad);
/*! * Helper function for `get_view_pose` in an HMD driver. *107 unmodified linesExpand all47 unmodified lines484950515253545556555657585960616216 unmodified lines7980818283848586878485888990919293184 unmodified linesExpand all47 unmodified linesstatic struct qwerty_device *default_qwerty_device(struct xrt_device **xdevs, size_t xdev_count, struct qwerty_system *qsys){ int head; int eyes; int face; int left; int right; int gamepad; head = left = right = gamepad = XRT_DEVICE_ROLE_UNASSIGNED; u_device_assign_xdev_roles(xdevs, xdev_count, &head, &left, &right, &gamepad); head = eyes = face = left = right = gamepad = XRT_DEVICE_ROLE_UNASSIGNED; u_device_assign_xdev_roles(xdevs, xdev_count, &head, &eyes, &face, &left, &right, &gamepad);
struct xrt_device *xd_hmd = qsys->hmd ? &qsys->hmd->base.base : NULL; struct xrt_device *xd_left = &qsys->lctrl->base.base; struct xrt_device *xd_right = &qsys->rctrl->base.base;16 unmodified linesstatic struct qwerty_controller *default_qwerty_controller(struct xrt_device **xdevs, size_t xdev_count, struct qwerty_system *qsys){ int head; int eyes; int face; int left; int right; int gamepad; head = left = right = gamepad = XRT_DEVICE_ROLE_UNASSIGNED; u_device_assign_xdev_roles(xdevs, xdev_count, &head, &left, &right, &gamepad); head = eyes = face = left = right = gamepad = XRT_DEVICE_ROLE_UNASSIGNED; u_device_assign_xdev_roles(xdevs, xdev_count, &head, &eyes, &face, &left, &right, &gamepad);
struct xrt_device *xd_left = &qsys->lctrl->base.base; struct xrt_device *xd_right = &qsys->rctrl->base.base;
184 unmodified linesExpand all761 unmodified linesExpand all762763764765766766767768768769770771772145 unmodified linesExpand all761 unmodified linesExpand allxrt_result_tget_roles(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles){ bool update_gen = false; int head, left, right, gamepad; int head, eyes, face, left, right, gamepad;
u_device_assign_xdev_roles(xsysd->xdevs, xsysd->xdev_count, &head, &left, &right, &gamepad); u_device_assign_xdev_roles(xsysd->xdevs, xsysd->xdev_count, &head, &eyes, &face, &left, &right, &gamepad);
if (left != out_roles->left || right != out_roles->right || gamepad != out_roles->gamepad) { update_gen = true; }145 unmodified linesExpand all1549 unmodified linesExpand all1550155115521553155415541555155615571558238 unmodified linesExpand all1549 unmodified linesExpand all }
// use steamvr room setup instead struct xrt_vec3 offset = {0, 0, 0}; u_builder_setup_tracking_origins(m_xhmd, left_xdev, right_xdev, NULL, &offset); u_builder_setup_tracking_origins(m_xhmd, nullptr, left_xdev, right_xdev, nullptr, &offset);
if (left_xdev) { m_left = new CDeviceDriver_Monado_Controller(m_xinst, left_xdev, XRT_HAND_LEFT); ovrd_log("Added left Controller: %s\n", left_xdev->str);238 unmodified linesExpand all149 unmodified linesExpand all15015115215315415515415515615715815916016116216316416516616716816917017117217317417517611 unmodified lines18818919019119219319419519619739 unmodified lines149 unmodified linesExpand all /* * Setup the roles. */
int head_idx, left_idx, right_idx, gamepad_idx; u_device_assign_xdev_roles(xsysd->xdevs, xsysd->xdev_count, &head_idx, &left_idx, &right_idx, &gamepad_idx); int head_idx, eyes_idx, face_idx, left_idx, right_idx, gamepad_idx; u_device_assign_xdev_roles(xsysd->xdevs, xsysd->xdev_count, &head_idx, &eyes_idx, &face_idx, &left_idx, &right_idx, &gamepad_idx);
struct xrt_device *head = NULL; struct xrt_device *eyes = NULL, *face = NULL; struct xrt_device *left = NULL, *right = NULL, *gamepad = NULL; struct xrt_device *unobstructed_left_ht = NULL, *unobstructed_right_ht = NULL; struct xrt_device *conforming_left_ht = NULL, *conforming_right_ht = NULL;
if (head_idx >= 0) { head = xsysd->xdevs[head_idx]; } if (eyes_idx >= 0) { eyes = xsysd->xdevs[eyes_idx]; } if (face_idx >= 0) { face = xsysd->xdevs[face_idx]; } if (left_idx >= 0) { left = xsysd->xdevs[left_idx]; } if (right_idx >= 0) {11 unmodified lines conforming_right_ht = u_system_devices_get_ht_device_conforming_right(xsysd);
// Assign to role(s). ubrh->head = head; ubrh->eyes = eyes; ubrh->face = face; ubrh->left = left; ubrh->right = right; ubrh->gamepad = gamepad; ubrh->hand_tracking.unobstructed.left = unobstructed_left_ht;39 unmodified lines618 unmodified linesExpand all6196206216226236246256266276286276296306316326336344 unmodified lines63964064164264364464564664764897 unmodified lines74674774874975075175275375475549 unmodified lines618 unmodified linesExpand all }
// Device indices. int head_idx = -1; int eyes_idx = -1; int face_idx = -1; int left_idx = -1; int right_idx = -1; int gamepad_idx = -1;
u_device_assign_xdev_roles(xsysd->xdevs, xsysd->xdev_count, &head_idx, &left_idx, &right_idx, &gamepad_idx); u_device_assign_xdev_roles(xsysd->xdevs, xsysd->xdev_count, &head_idx, &eyes_idx, &face_idx, &left_idx, &right_idx, &gamepad_idx);
if (head_idx < 0) { LH_ERROR("Unable to find HMD"); result = XRT_ERROR_DEVICE_CREATION_FAILED;4 unmodified lines struct xrt_device *head = NULL; struct xrt_device *left = NULL, *right = NULL; struct xrt_device *unobstructed_left_ht = NULL, *unobstructed_right_ht = NULL; struct xrt_device *conforming_left_ht = NULL, *conforming_right_ht = NULL; struct xrt_device *face = (face_idx >= 0) ? xsysd->xdevs[face_idx] : NULL; struct xrt_device *eyes = (eyes_idx >= 0) ? xsysd->xdevs[eyes_idx] : NULL;
// Always have a head. head = xsysd->xdevs[head_idx];
97 unmodified lines }
// Assign to role(s). ubrh->head = head; ubrh->face = face; ubrh->eyes = eyes; ubrh->left = left; ubrh->right = right; ubrh->hand_tracking.unobstructed.left = unobstructed_left_ht; ubrh->hand_tracking.unobstructed.right = unobstructed_right_ht;49 unmodified lines147 unmodified linesExpand all14814915015115215315415515625 unmodified lines147 unmodified linesExpand all
u_builder_create_space_overseer_legacy( // &sp->usys->broadcast, // broadcast head, // head NULL, // eyes NULL, // left NULL, // right NULL, // gamepad sp->xsysd_base.xdevs, // xdevs25 unmodified lines