aux/vive: Add vive_poses

This commit is contained in:
Daniel Willmott committed 2023-02-05 20:19:52 +00:00
1 parent e383609cbc
commit ab857e8f74
3 files changed
+114 -1

No files matched your search

+9 -1
View File
@@ -1,7 +1,15 @@
# Copyright 2019-2022, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
add_library(aux_vive STATIC vive_config.h vive_config.c vive_bindings.c vive_bindings.h)
add_library(
aux_vive STATIC
vive_config.h
vive_config.c
vive_bindings.c
vive_bindings.h
vive_poses.h
vive_poses.c
)
target_link_libraries(
aux_vive
PRIVATE
+86
View File
@@ -0,0 +1,86 @@
// Copyright 2019-2021, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Vive poses implementation
* @author Daniel Willmott <web@dan-w.com>
* @ingroup drv_vive
*/
#include "vive_poses.h"
#include "math/m_mathinclude.h"
#include "math/m_api.h"
#define DEG_TO_RAD(DEG) (DEG * M_PI / 180.)
void
vive_poses_apply_right_transform(struct xrt_vec3 *out_transform_position, struct xrt_vec3 *out_transform_rotation)
{
out_transform_rotation->y *= -1.f;
out_transform_rotation->z *= -1.f;
out_transform_position->x *= -1.f;
}
void
vive_poses_get_index_offset_transforms(enum xrt_input_name input_name,
enum xrt_device_type device_type,
struct xrt_vec3 *out_transform_position,
struct xrt_vec3 *out_transform_rotation)
{
switch (input_name) {
case XRT_INPUT_INDEX_GRIP_POSE:
out_transform_position->x = 0.f;
out_transform_position->y = -0.015f;
out_transform_position->z = 0.13f;
out_transform_rotation->x = DEG_TO_RAD(15.392f);
out_transform_rotation->y = DEG_TO_RAD(-2.071f);
out_transform_rotation->z = DEG_TO_RAD(0.303);
break;
case XRT_INPUT_INDEX_AIM_POSE:
out_transform_position->x = 0.006f;
out_transform_position->y = -0.015f;
out_transform_position->z = 0.02f;
out_transform_rotation->x = DEG_TO_RAD(-40.f);
out_transform_rotation->y = DEG_TO_RAD(-5.f);
out_transform_rotation->z = 0.f;
break;
default:
*out_transform_position = (struct xrt_vec3)XRT_VEC3_ZERO;
*out_transform_rotation = (struct xrt_vec3)XRT_VEC3_ZERO;
break;
}
if (device_type == XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER) {
vive_poses_apply_right_transform(out_transform_position, out_transform_rotation);
}
}
void
vive_poses_get_pose_offset(enum xrt_device_name device_name,
enum xrt_device_type device_type,
enum xrt_input_name input_name,
struct xrt_pose *out_offset_pose)
{
struct xrt_vec3 transform_position = XRT_VEC3_ZERO;
struct xrt_vec3 transform_rotation = XRT_VEC3_ZERO;
switch (device_name) {
case XRT_DEVICE_INDEX_CONTROLLER:
vive_poses_get_index_offset_transforms(input_name, device_type, &transform_position,
&transform_rotation);
break;
default: break;
}
math_quat_from_euler_angles(&transform_rotation, &out_offset_pose->orientation);
out_offset_pose->position = transform_position;
}
+19
View File
@@ -0,0 +1,19 @@
// Copyright 2019-2021, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief vive poses header
* @author Daniel Willmott <web@dan-w.com>
* @ingroup drv_vive
*/
#pragma once
#include "xrt/xrt_defines.h"
#include "vive_config.h"
void
vive_poses_get_pose_offset(enum xrt_device_name device_name,
enum xrt_device_type device_type,
enum xrt_input_name input_name,
struct xrt_pose *out_offset_pose);