mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 11:06:18 +00:00
u/json: Add u_json_get_vec3_array.
As seen in Vive driver.
This commit is contained in:
parent
efd351f5c1
commit
0bdd1133e4
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue