mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-02-02 20:08:29 +00:00
aux/util: Add get_vec3_f64_array
This commit is contained in:
parent
0b2dd35b60
commit
13f2b3b7c4
|
@ -195,6 +195,42 @@ u_json_get_vec3_array(const cJSON *json, struct xrt_vec3 *out_vec3)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
u_json_get_vec3_f64_array(const cJSON *json, struct xrt_vec3_f64 *out_vec3)
|
||||
{
|
||||
assert(out_vec3 != NULL);
|
||||
|
||||
if (!json) {
|
||||
return false;
|
||||
}
|
||||
if (!cJSON_IsArray(json)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cJSON_GetArraySize(json) != 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float array[3] = {0, 0, 0};
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -70,7 +70,7 @@ bool
|
|||
u_json_get_double(const cJSON *json, double *out_double);
|
||||
|
||||
/*!
|
||||
* @brief Parse a vec3 from a JSON object.
|
||||
* @brief Parse an xrt_vec3 from a JSON object.
|
||||
*
|
||||
* @return true if successful, false if not.
|
||||
*/
|
||||
|
@ -78,13 +78,21 @@ bool
|
|||
u_json_get_vec3(const cJSON *json, struct xrt_vec3 *out_vec3);
|
||||
|
||||
/*!
|
||||
* @brief Parse a vec3 from a JSON array.
|
||||
* @brief Parse an xrt_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 an xrt_vec3_f64 from a JSON array.
|
||||
*
|
||||
* @return true if successful, false if not.
|
||||
*/
|
||||
bool
|
||||
u_json_get_vec3_f64_array(const cJSON *json, struct xrt_vec3_f64 *out_vec3);
|
||||
|
||||
/*!
|
||||
* @brief Parse a quaternion from a JSON object.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue