u/json: Add u_json_get_vec3_array.

As seen in Vive driver.
This commit is contained in:
Lubosz Sarnecki 2020-06-26 13:03:19 +02:00
parent efd351f5c1
commit 0bdd1133e4
2 changed files with 45 additions and 0 deletions

View file

@ -146,6 +146,43 @@ u_json_get_vec3(const cJSON *json, struct xrt_vec3 *out_vec3)
return true;
}
bool
u_json_get_vec3_array(const cJSON *json, struct xrt_vec3 *out_vec3)
{
assert(out_vec3 != NULL);
if (!json) {
return false;
}
if (!cJSON_IsArray(json)) {
return false;
}
float array[3];
if (cJSON_GetArraySize(json) != 3) {
return false;
}
const cJSON *item = NULL;
size_t i = 0;
cJSON_ArrayForEach(item, json)
{
assert(cJSON_IsNumber(item));
array[i] = (float)item->valuedouble;
++i;
if (i == 3) {
break;
}
}
out_vec3->x = array[0];
out_vec3->y = array[1];
out_vec3->z = array[2];
return true;
}
bool
u_json_get_quat(const cJSON *json, struct xrt_quat *out_quat)
{

View file

@ -77,6 +77,14 @@ u_json_get_double(const cJSON *json, double *out_double);
bool
u_json_get_vec3(const cJSON *json, struct xrt_vec3 *out_vec3);
/*!
* @brief Parse a vec3 from a JSON array.
*
* @return true if successful, false if not.
*/
bool
u_json_get_vec3_array(const cJSON *json, struct xrt_vec3 *out_vec3);
/*!
* @brief Parse a quaternion from a JSON object.
*