The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

u/json: Add u_json_get_pose_permissive

To parse poses from non-Monado configs with non-standard member names.

authored by

Moses Turner and committed by
Jakob Bornecrantz
48e8894b b31eb767

+46
+36
src/xrt/auxiliary/util/u_json.c
··· 278 278 return good; 279 279 } 280 280 281 + bool 282 + u_json_get_pose_permissive(const cJSON *json, struct xrt_pose *out_pose) 283 + { 284 + struct xrt_pose tmp; 285 + 286 + const char *position_names[] = {"position", "translation", "location", "pos", "loc"}; 287 + const char *orientation_names[] = {"orientation", "rotation", "rot"}; 288 + 289 + bool found_position = false; 290 + 291 + for (uint32_t i = 0; i < ARRAY_SIZE(position_names); i++) { 292 + found_position = u_json_get_vec3(u_json_get(json, position_names[i]), &tmp.position); 293 + if (found_position) { 294 + break; 295 + } 296 + } 297 + if (!found_position) { 298 + return false; 299 + } 300 + 301 + bool found_orientation = false; 302 + 303 + for (uint32_t i = 0; i < ARRAY_SIZE(orientation_names); i++) { 304 + found_orientation = u_json_get_vec3(u_json_get(json, orientation_names[i]), &tmp.position); 305 + if (found_orientation) { 306 + break; 307 + } 308 + } 309 + if (!found_orientation) { 310 + return false; 311 + } 312 + 313 + 314 + return true; 315 + } 316 + 281 317 282 318 size_t 283 319 u_json_get_float_array(const cJSON *json_array, float *out_array, size_t max_size)
+10
src/xrt/auxiliary/util/u_json.h
··· 111 111 112 112 113 113 /*! 114 + * @brief Parse a pose from a JSON object, composed of 115 + * a vec3 named "position", "translation", "location", "pos", or "loc" 116 + * and a quat named "orientation". "rotation", or "rot" 117 + * 118 + * @return true if successful, false if not. 119 + */ 120 + bool 121 + u_json_get_pose_permissive(const cJSON *json, struct xrt_pose *out_pose); 122 + 123 + /*! 114 124 * @brief Parse up to max_size floats from a JSON array. 115 125 * 116 126 * @return the number of elements set.