Monado OpenXR Runtime
ns_hmd.h
Go to the documentation of this file.
1// Copyright 2019, Collabora, Ltd.
2// Copyright 2020, Nova King.
3// Copyright 2021, Moses Turner.
4// SPDX-License-Identifier: BSL-1.0
5/*!
6 * @file
7 * @brief Interface between North Star distortion and HMD code.
8 * @author Nova King <technobaboo@gmail.com>
9 * @author Moses Turner <mosesturner@protonmail.com>
10 * @ingroup drv_ns
11 */
12
13#pragma once
14
15#include "math/m_api.h"
16#include "util/u_json.h"
17#include "util/u_misc.h"
18#include "xrt/xrt_defines.h"
19#include "xrt/xrt_device.h"
20#include "util/u_logging.h"
21#include "os/os_threading.h"
23
24#include <stdio.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*
31 *
32 * 3D distortion structs
33 * Sometimes known as "v1", config file name is often "Calibration.json"
34 *
35 */
36
37/*!
38 * Opaque struct for optical system C++ integration
39 *
40 * @ingroup drv_ns
41 */
42struct ns_3d_optical_system;
43
44/*!
45 * Distortion information about an eye parsed from the configuration file.
46 *
47 * @ingroup drv_ns
48 */
50{
51 float ellipse_minor_axis;
52 float ellipse_major_axis;
53
54 struct xrt_vec3 screen_forward;
55 struct xrt_vec3 screen_position;
56
57 struct xrt_pose eye_pose;
58
59 // This is more of a vec4 than a quat
60 struct xrt_quat camera_projection;
61
62 struct xrt_matrix_4x4 sphere_to_world_space;
63 struct xrt_matrix_4x4 world_to_screen_space;
64
65 struct ns_optical_system *optical_system;
66};
67
69{
70 struct ns_3d_eye eyes[2];
71};
72
73enum ns_distortion_type
74{
75 NS_DISTORTION_TYPE_INVALID,
76 NS_DISTORTION_TYPE_GEOMETRIC_3D,
77 NS_DISTORTION_TYPE_POLYNOMIAL_2D,
78 NS_DISTORTION_TYPE_MOSHI_MESHGRID,
79};
80
81// The config json data gets dumped in here.
82// In general, `target_builder_north_star.c` sets up tracking, and `ns_hmd.c` sets up distortion/optics.
84{
85 struct xrt_pose head_pose_to_eye[2]; // left, right
86 struct xrt_fov fov[2]; // left,right
87
88
89
90 enum ns_distortion_type distortion_type;
91 union {
92 struct ns_3d_values dist_3d;
93 struct u_ns_p2d_values dist_p2d;
94 struct u_ns_meshgrid_values dist_meshgrid;
95 };
96};
97
98
99/*!
100 * Information about the whole North Star headset.
101 *
102 * @ingroup drv_ns
103 * @implements xrt_device
104 */
105
106struct ns_hmd
107{
108 struct xrt_device base;
109 struct xrt_space_relation no_tracker_relation;
110 const cJSON *config_json;
111 struct ns_optics_config config;
112
113 enum u_logging_level log_level;
114};
115
116/*
117 *
118 * Functions
119 *
120 */
121
122/*!
123 * Get the North Star HMD information from a @ref xrt_device.
124 *
125 * @ingroup drv_ns
126 */
127static inline struct ns_hmd *
128ns_hmd(struct xrt_device *xdev)
129{
130 return (struct ns_hmd *)xdev;
131}
132
133
134/*!
135 * Convert the display UV to the render UV using the distortion mesh.
136 *
137 * @ingroup drv_ns
138 */
139
140void
141ns_3d_display_uv_to_render_uv(struct xrt_vec2 in, struct xrt_vec2 *out, struct ns_3d_eye *eye);
142
143struct ns_optical_system *
144ns_3d_create_optical_system(struct ns_3d_eye *eye);
145
146void
147ns_3d_free_optical_system(struct ns_optical_system **system);
148
149
150#ifdef __cplusplus
151}
152#endif
u_logging_level
Logging level enum.
Definition: u_logging.h:40
void ns_3d_display_uv_to_render_uv(struct xrt_vec2 in, struct xrt_vec2 *out, struct ns_3d_eye *eye)
Convert the display UV to the render UV using the distortion mesh.
Definition: deformation_northstar.cpp:279
static struct ns_hmd * ns_hmd(struct xrt_device *xdev)
Get the North Star HMD information from a xrt_device.
Definition: ns_hmd.h:128
C interface to math library.
Wrapper around OS threading native functions.
Distortion information about an eye parsed from the configuration file.
Definition: ns_hmd.h:50
Definition: ns_hmd.h:69
Information about the whole North Star headset.
Definition: ns_hmd.h:107
Definition: ns_hmd.h:84
Definition: u_distortion_mesh.h:141
Definition: u_distortion_mesh.h:118
A single HMD or input device.
Definition: xrt_device.h:230
Describes a projection matrix fov.
Definition: xrt_defines.h:486
A tightly packed 4x4 matrix of floats.
Definition: xrt_defines.h:560
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
A quaternion with single floats.
Definition: xrt_defines.h:216
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:657
A 2 element vector with single floats.
Definition: xrt_defines.h:250
A 3 element vector with single floats.
Definition: xrt_defines.h:271
Code to generate disortion meshes.
Tiny JSON wrapper around cJSON header.
Basic logging functionality.
Very small misc utils.
Common defines and enums for XRT.
Header defining an xrt display or controller device.