The open source OpenXR runtime
0
fork

Configure Feed

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

d/hydra: Fix orientation problems

probably wrong in some subtle way, but whatever

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2469>

+19 -2
+19 -2
src/xrt/drivers/hydra/hydra_driver.c
··· 276 276 hydra_device_parse_controller(struct hydra_device *hd, uint8_t *buf) 277 277 { 278 278 struct hydra_controller_state *state = &hd->state; 279 + 279 280 static const float SCALE_MM_TO_METER = 0.001f; 280 281 static const float SCALE_INT16_TO_FLOAT_PLUSMINUS_1 = 1.0f / 32768.0f; 281 282 static const float SCALE_UINT8_TO_FLOAT_0_TO_1 = 1.0f / 255.0f; 283 + 282 284 state->pose.position.x = hydra_read_int16_le(&buf) * SCALE_MM_TO_METER; 283 285 state->pose.position.z = hydra_read_int16_le(&buf) * SCALE_MM_TO_METER; 284 286 state->pose.position.y = -hydra_read_int16_le(&buf) * SCALE_MM_TO_METER; ··· 286 288 // the negatives are to fix handedness 287 289 state->pose.orientation.w = hydra_read_int16_le(&buf) * SCALE_INT16_TO_FLOAT_PLUSMINUS_1; 288 290 state->pose.orientation.x = hydra_read_int16_le(&buf) * SCALE_INT16_TO_FLOAT_PLUSMINUS_1; 289 - state->pose.orientation.y = -hydra_read_int16_le(&buf) * SCALE_INT16_TO_FLOAT_PLUSMINUS_1; 290 - state->pose.orientation.z = -hydra_read_int16_le(&buf) * SCALE_INT16_TO_FLOAT_PLUSMINUS_1; 291 + state->pose.orientation.y = hydra_read_int16_le(&buf) * SCALE_INT16_TO_FLOAT_PLUSMINUS_1; 292 + state->pose.orientation.z = hydra_read_int16_le(&buf) * SCALE_INT16_TO_FLOAT_PLUSMINUS_1; 291 293 292 294 //! @todo the presence of this suggest we're not decoding the 293 295 //! orientation right. 294 296 math_quat_normalize(&state->pose.orientation); 297 + 298 + struct xrt_quat fixed = { 299 + .x = state->pose.orientation.x, 300 + .y = -state->pose.orientation.z, 301 + .z = state->pose.orientation.y, 302 + .w = state->pose.orientation.w, 303 + }; 304 + 305 + struct xrt_quat adjustment = {.x = 0, .y = 1, .z = 0, .w = 0}; 306 + math_quat_rotate(&fixed, &adjustment, &fixed); 307 + 308 + adjustment = (struct xrt_quat){.x = 0, .y = 0, .z = 1, .w = 0}; 309 + math_quat_rotate(&fixed, &adjustment, &fixed); 310 + 311 + state->pose.orientation = fixed; 295 312 296 313 state->buttons = hydra_read_uint8(&buf); 297 314