From b31eb7671818638d1d3d2bae2ad207cd61bd8ccd Mon Sep 17 00:00:00 2001 From: Moses Turner Date: Sun, 18 Sep 2022 08:07:32 -0500 Subject: [PATCH] u/json: Add u_json_get_pose --- src/xrt/auxiliary/util/u_json.c | 17 +++++++++++++++++ src/xrt/auxiliary/util/u_json.h | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/src/xrt/auxiliary/util/u_json.c b/src/xrt/auxiliary/util/u_json.c index e1efa7a6a..98cc1e4b6 100644 --- a/src/xrt/auxiliary/util/u_json.c +++ b/src/xrt/auxiliary/util/u_json.c @@ -262,6 +262,23 @@ u_json_get_quat(const cJSON *json, struct xrt_quat *out_quat) return true; } +// note: you should be using "position" and "orientation" and lower-case xyz(w) +bool +u_json_get_pose(const cJSON *json, struct xrt_pose *out_pose) +{ + struct xrt_pose tmp; + + bool good = true; + good = good && u_json_get_vec3(u_json_get(json, "position"), &tmp.position); + good = good && u_json_get_quat(u_json_get(json, "orientation"), &tmp.orientation); + + if (good) { + *out_pose = tmp; + } + return good; +} + + size_t u_json_get_float_array(const cJSON *json_array, float *out_array, size_t max_size) { diff --git a/src/xrt/auxiliary/util/u_json.h b/src/xrt/auxiliary/util/u_json.h index bac339854..a2d51e1db 100644 --- a/src/xrt/auxiliary/util/u_json.h +++ b/src/xrt/auxiliary/util/u_json.h @@ -101,6 +101,15 @@ u_json_get_vec3_f64_array(const cJSON *json, struct xrt_vec3_f64 *out_vec3); bool u_json_get_quat(const cJSON *json, struct xrt_quat *out_quat); +/*! + * @brief Parse a pose from a JSON object, composed of a vec3 named "position" and a quat named "orientation". + * + * @return true if successful, false if not. + */ +bool +u_json_get_pose(const cJSON *json, struct xrt_pose *out_pose); + + /*! * @brief Parse up to max_size floats from a JSON array. *