u/json: Add u_json_get_pose

This commit is contained in:
Moses Turner 2022-09-18 08:07:32 -05:00 committed by Jakob Bornecrantz
parent d91975299d
commit b31eb76718
2 changed files with 26 additions and 0 deletions

View file

@ -262,6 +262,23 @@ u_json_get_quat(const cJSON *json, struct xrt_quat *out_quat)
return true; 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 size_t
u_json_get_float_array(const cJSON *json_array, float *out_array, size_t max_size) u_json_get_float_array(const cJSON *json_array, float *out_array, size_t max_size)
{ {

View file

@ -101,6 +101,15 @@ u_json_get_vec3_f64_array(const cJSON *json, struct xrt_vec3_f64 *out_vec3);
bool bool
u_json_get_quat(const cJSON *json, struct xrt_quat *out_quat); 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. * @brief Parse up to max_size floats from a JSON array.
* *