u/builders: Move setup tracking origin function here

This commit is contained in:
Jakob Bornecrantz 2023-03-02 17:19:06 +00:00
parent 05de788168
commit d84a679eb9
6 changed files with 75 additions and 64 deletions

View file

@ -7,8 +7,24 @@
* @ingroup aux_util
*/
#include "xrt/xrt_prober.h"
#include "u_builders.h"
#include "xrt/xrt_tracking.h"
#include "util/u_builders.h"
/*
*
* Helper functions.
*
*/
static void
apply_offset(struct xrt_vec3 *position, struct xrt_vec3 *offset)
{
position->x += offset->x;
position->y += offset->y;
position->z += offset->z;
}
/*
@ -75,3 +91,44 @@ u_builder_search(struct xrt_prober *xp,
}
}
}
void
u_builder_setup_tracking_origins(struct xrt_device *head,
struct xrt_device *left,
struct xrt_device *right,
struct xrt_vec3 *global_tracking_origin_offset)
{
struct xrt_tracking_origin *head_origin = head ? head->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;
if (left_origin != NULL && left_origin->type == XRT_TRACKING_TYPE_NONE) {
left_origin->offset.position.x = -0.2f;
left_origin->offset.position.y = 1.3f;
left_origin->offset.position.z = -0.5f;
}
if (right_origin != NULL && right_origin->type == XRT_TRACKING_TYPE_NONE) {
right_origin->offset.position.x = 0.2f;
right_origin->offset.position.y = 1.3f;
right_origin->offset.position.z = -0.5f;
}
// Head comes last, because left and right may share tracking origin.
if (head_origin != NULL && head_origin->type == XRT_TRACKING_TYPE_NONE) {
// "nominal height" 1.6m
head_origin->offset.position.x = 0.0f;
head_origin->offset.position.y = 1.6f;
head_origin->offset.position.z = 0.0f;
}
if (head_origin) {
apply_offset(&head_origin->offset.position, global_tracking_origin_offset);
}
if (left_origin && left_origin != head_origin) {
apply_offset(&left->tracking_origin->offset.position, global_tracking_origin_offset);
}
if (right_origin && right_origin != head_origin && right_origin != left_origin) {
apply_offset(&right->tracking_origin->offset.position, global_tracking_origin_offset);
}
}

View file

@ -77,6 +77,17 @@ u_builder_search(struct xrt_prober *xp,
size_t filter_count,
struct u_builder_search_results *results);
/*!
* Helper function for setting up tracking origins. Applies 3dof offsets for devices with XRT_TRACKING_TYPE_NONE.
*
* @ingroup aux_util
*/
void
u_builder_setup_tracking_origins(struct xrt_device *head,
struct xrt_device *left,
struct xrt_device *right,
struct xrt_vec3 *global_tracking_origin_offset);
#ifdef __cplusplus
}

View file

@ -373,54 +373,6 @@ u_device_assign_xdev_roles(struct xrt_device **xdevs, size_t xdev_count, int *he
}
}
static void
apply_offset(struct xrt_vec3 *position, struct xrt_vec3 *offset)
{
position->x += offset->x;
position->y += offset->y;
position->z += offset->z;
}
void
u_device_setup_tracking_origins(struct xrt_device *head,
struct xrt_device *left,
struct xrt_device *right,
struct xrt_vec3 *global_tracking_origin_offset)
{
if (head->tracking_origin->type == XRT_TRACKING_TYPE_NONE) {
// "nominal height" 1.6m
head->tracking_origin->offset.position.x = 0.0f;
head->tracking_origin->offset.position.y = 1.6f;
head->tracking_origin->offset.position.z = 0.0f;
}
if (left != NULL && left->tracking_origin->type == XRT_TRACKING_TYPE_NONE) {
left->tracking_origin->offset.position.x = -0.2f;
left->tracking_origin->offset.position.y = 1.3f;
left->tracking_origin->offset.position.z = -0.5f;
}
if (right != NULL && right->tracking_origin->type == XRT_TRACKING_TYPE_NONE) {
right->tracking_origin->offset.position.x = 0.2f;
right->tracking_origin->offset.position.y = 1.3f;
right->tracking_origin->offset.position.z = -0.5f;
}
struct xrt_tracking_origin *head_origin = head ? head->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;
if (head_origin) {
apply_offset(&head_origin->offset.position, global_tracking_origin_offset);
}
if (left_origin && left_origin != head_origin) {
apply_offset(&left->tracking_origin->offset.position, global_tracking_origin_offset);
}
if (right_origin && right_origin != head_origin && right_origin != left_origin) {
apply_offset(&right->tracking_origin->offset.position, global_tracking_origin_offset);
}
}
void
u_device_get_view_pose(const struct xrt_vec3 *eye_relation, uint32_t view_index, struct xrt_pose *out_pose)
{

View file

@ -128,17 +128,6 @@ u_device_free(struct xrt_device *xdev);
void
u_device_assign_xdev_roles(struct xrt_device **xdevs, size_t xdev_count, int *head, int *left, int *right);
/*!
* Helper function for setting up tracking origins. Applies 3dof offsets for devices with XRT_TRACKING_TYPE_NONE.
*
* @ingroup aux_util
*/
void
u_device_setup_tracking_origins(struct xrt_device *head,
struct xrt_device *left,
struct xrt_device *right,
struct xrt_vec3 *global_tracking_origin_offset);
/*!
* Helper function for `get_view_pose` in an HMD driver.
*

View file

@ -17,6 +17,7 @@
#include "util/u_misc.h"
#include "util/u_debug.h"
#include "util/u_git_tag.h"
#include "util/u_builders.h"
#ifdef XRT_OS_ANDROID
#include "android/android_globals.h"
@ -317,8 +318,8 @@ oxr_instance_create(struct oxr_logger *log,
debug_get_float_option_tracking_origin_offset_y(),
debug_get_float_option_tracking_origin_offset_z()};
u_device_setup_tracking_origins(dev, GET_XDEV_BY_ROLE(sys, left), GET_XDEV_BY_ROLE(sys, right),
&global_tracking_origin_offset);
u_builder_setup_tracking_origins(dev, GET_XDEV_BY_ROLE(sys, left), GET_XDEV_BY_ROLE(sys, right),
&global_tracking_origin_offset);
// Sets the enabled extensions, this is where we should do any extra validation.
inst->extensions = *extensions;

View file

@ -26,6 +26,7 @@ extern "C" {
#include "os/os_time.h"
#include "util/u_debug.h"
#include "util/u_device.h"
#include "util/u_builders.h"
#include "util/u_hand_tracking.h"
#include "xrt/xrt_system.h"
@ -1485,7 +1486,7 @@ CServerDriver_Monado::Init(vr::IVRDriverContext *pDriverContext)
// use steamvr room setup instead
struct xrt_vec3 offset = {0, 0, 0};
u_device_setup_tracking_origins(m_xhmd, left_xdev, right_xdev, &offset);
u_builder_setup_tracking_origins(m_xhmd, left_xdev, right_xdev, &offset);
if (left_xdev) {
m_left = new CDeviceDriver_Monado_Controller(m_xinst, left_xdev, XRT_HAND_LEFT);