The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

aux/util: Add get_vec3_f64_array

authored by

Moses Turner and committed by
Jakob Bornecrantz
13f2b3b7 0b2dd35b

+46 -2
+36
src/xrt/auxiliary/util/u_json.c
··· 196 196 } 197 197 198 198 bool 199 + u_json_get_vec3_f64_array(const cJSON *json, struct xrt_vec3_f64 *out_vec3) 200 + { 201 + assert(out_vec3 != NULL); 202 + 203 + if (!json) { 204 + return false; 205 + } 206 + if (!cJSON_IsArray(json)) { 207 + return false; 208 + } 209 + 210 + if (cJSON_GetArraySize(json) != 3) { 211 + return false; 212 + } 213 + 214 + float array[3] = {0, 0, 0}; 215 + const cJSON *item = NULL; 216 + size_t i = 0; 217 + cJSON_ArrayForEach(item, json) 218 + { 219 + assert(cJSON_IsNumber(item)); 220 + array[i] = (float)item->valuedouble; 221 + ++i; 222 + if (i == 3) { 223 + break; 224 + } 225 + } 226 + 227 + out_vec3->x = array[0]; 228 + out_vec3->y = array[1]; 229 + out_vec3->z = array[2]; 230 + 231 + return true; 232 + } 233 + 234 + bool 199 235 u_json_get_quat(const cJSON *json, struct xrt_quat *out_quat) 200 236 { 201 237 assert(out_quat != NULL);
+10 -2
src/xrt/auxiliary/util/u_json.h
··· 70 70 u_json_get_double(const cJSON *json, double *out_double); 71 71 72 72 /*! 73 - * @brief Parse a vec3 from a JSON object. 73 + * @brief Parse an xrt_vec3 from a JSON object. 74 74 * 75 75 * @return true if successful, false if not. 76 76 */ ··· 78 78 u_json_get_vec3(const cJSON *json, struct xrt_vec3 *out_vec3); 79 79 80 80 /*! 81 - * @brief Parse a vec3 from a JSON array. 81 + * @brief Parse an xrt_vec3 from a JSON array. 82 82 * 83 83 * @return true if successful, false if not. 84 84 */ 85 85 bool 86 86 u_json_get_vec3_array(const cJSON *json, struct xrt_vec3 *out_vec3); 87 + 88 + /*! 89 + * @brief Parse an xrt_vec3_f64 from a JSON array. 90 + * 91 + * @return true if successful, false if not. 92 + */ 93 + bool 94 + u_json_get_vec3_f64_array(const cJSON *json, struct xrt_vec3_f64 *out_vec3); 87 95 88 96 /*! 89 97 * @brief Parse a quaternion from a JSON object.