Monado OpenXR Runtime
ns_hmd.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Interface between North Star distortion and HMD code.
6  * @author Nova King <technobaboo@gmail.com>
7  * @ingroup drv_ns
8  */
9 
10 #pragma once
11 
12 #include "math/m_api.h"
13 #include "util/u_distortion_mesh.h"
14 #include "util/u_json.h"
15 #include "util/u_misc.h"
16 #include "xrt/xrt_defines.h"
17 #include "xrt/xrt_device.h"
18 
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 
25 /*
26  *
27  * Defines
28  *
29  */
30 
31 #define NS_SPEW(c, ...) \
32  do { \
33  if (c->print_spew) { \
34  fprintf(stderr, "%s - ", __func__); \
35  fprintf(stderr, __VA_ARGS__); \
36  fprintf(stderr, "\n"); \
37  } \
38  } while (false)
39 
40 #define NS_DEBUG(c, ...) \
41  do { \
42  if (c->print_debug) { \
43  fprintf(stderr, "%s - ", __func__); \
44  fprintf(stderr, __VA_ARGS__); \
45  fprintf(stderr, "\n"); \
46  } \
47  } while (false)
48 
49 #define NS_ERROR(c, ...) \
50  do { \
51  fprintf(stderr, "%s - ", __func__); \
52  fprintf(stderr, __VA_ARGS__); \
53  fprintf(stderr, "\n"); \
54  } while (false)
55 
56 
57 /*
58  *
59  * Structs
60  *
61  */
62 
63 /*!
64  * Opaque struct for optical system C++ integration
65  *
66  * @ingroup drv_ns
67  */
68 struct ns_optical_system;
69 
70 /*!
71  * Simple UV struct.
72  *
73  * @ingroup drv_ns
74  */
75 struct ns_uv
76 {
77  float u;
78  float v;
79 };
80 
81 /*!
82  * Configuration information about the LMC or Rigel sensor according to the
83  * configuration file.
84  *
85  * @ingroup drv_ns
86  */
87 struct ns_leap
88 {
89  const char *name;
90  const char *serial;
91  struct xrt_pose pose;
92 };
93 
94 /*!
95  * Distortion information about an eye parsed from the configuration file.
96  *
97  * @ingroup drv_ns
98  */
99 struct ns_eye
100 {
103 
104  struct xrt_vec3 screen_forward;
105  struct xrt_vec3 screen_position;
106 
107  struct xrt_pose eye_pose;
108 
109  struct xrt_quat camera_projection;
110 
111  struct xrt_matrix_4x4 sphere_to_world_space;
112  struct xrt_matrix_4x4 world_to_screen_space;
113 
114  struct ns_optical_system *optical_system;
115 };
116 
117 /*!
118  * Information about the whole North Star headset.
119  *
120  * @ingroup drv_ns
121  */
122 struct ns_hmd
123 {
124  struct xrt_device base;
125  struct xrt_pose pose;
126 
127  const char *config_path;
128 
129  struct ns_eye eye_configs[2];
130  struct ns_leap leap_config;
131 
133 
136 };
137 
138 /*!
139  * The mesh generator for the North Star distortion.
140  *
141  * @ingroup drv_ns
142  */
143 struct ns_mesh
144 {
145  struct u_uv_generator base;
146  struct ns_hmd *ns;
147 };
148 
149 
150 /*
151  *
152  * Functions
153  *
154  */
155 
156 /*!
157  * Get the North Star HMD information from a @ref xrt_device.
158  *
159  * @ingroup drv_ns
160  */
161 static inline struct ns_hmd *
162 ns_hmd(struct xrt_device *xdev)
163 {
164  return (struct ns_hmd *)xdev;
165 }
166 
167 /*!
168  * Get the North Star mesh generator from a @ref u_uv_generator.
169  *
170  * @ingroup drv_ns
171  */
172 static inline struct ns_mesh *
173 ns_mesh(struct u_uv_generator *gen)
174 {
175  return (struct ns_mesh *)gen;
176 }
177 
178 /*!
179  * Convert the display UV to the render UV using the distortion mesh.
180  *
181  * @ingroup drv_ns
182  */
183 void
184 ns_display_uv_to_render_uv(struct ns_uv display_uv,
185  struct ns_uv *render_uv,
186  struct ns_eye *eye);
187 
188 struct ns_optical_system *
189 ns_create_optical_system(struct ns_eye *eye);
190 
191 
192 #ifdef __cplusplus
193 }
194 #endif
struct xrt_device * tracker
Definition: ns_hmd.h:132
A 3 element vector with single floats.
Definition: xrt_defines.h:133
A pose composed of a position and orientation.
Definition: xrt_defines.h:231
float ellipse_major_axis
Definition: ns_hmd.h:102
Simple UV struct.
Definition: ns_hmd.h:75
struct ns_optical_system * optical_system
Definition: ns_hmd.h:114
float v
Definition: ns_hmd.h:78
float ellipse_minor_axis
Definition: ns_hmd.h:101
const char * serial
Definition: ns_hmd.h:90
void ns_display_uv_to_render_uv(struct ns_uv display_uv, struct ns_uv *render_uv, struct ns_eye *eye)
Convert the display UV to the render UV using the distortion mesh.
Definition: deformation_northstar.cpp:307
A quaternion with single floats.
Definition: xrt_defines.h:99
The mesh generator for the North Star distortion.
Definition: ns_hmd.h:143
Header defining a xrt HMD device.
Distortion information about an eye parsed from the configuration file.
Definition: ns_hmd.h:99
Code to generate disortion meshes.
const char * config_path
Definition: ns_hmd.h:127
Common defines and enums for XRT.
bool print_debug
Definition: ns_hmd.h:135
A tightly packed 4x4 matrix of floats.
Definition: xrt_defines.h:278
Generator struct for building meshes, can be implemented by drivers for special meshes.
Definition: u_distortion_mesh.h:55
struct ns_optical_system * ns_create_optical_system(struct ns_eye *eye)
Definition: deformation_northstar.cpp:297
Configuration information about the LMC or Rigel sensor according to the configuration file...
Definition: ns_hmd.h:87
Information about the whole North Star headset.
Definition: ns_hmd.h:122
Very small misc utils.
float u
Definition: ns_hmd.h:77
bool print_spew
Definition: ns_hmd.h:134
Tiny JSON wrapper around cJSON header.
A single HMD or input device.
Definition: xrt_device.h:202
const char * name
Definition: ns_hmd.h:89
C interface to math library.
struct ns_hmd * ns
Definition: ns_hmd.h:146