From 907305e430d964a2e72b291934a9678a9f4574b9 Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 31 May 2021 14:35:53 -0600 Subject: [PATCH] Fix oculus hand model orientation; - Previously, animate was converting from oculus basis to lovr basis. - Not all hand models are animated. - Instead, apply the compensation in newModel. - This means that both animated and non-animated models have correct orientation. - Verified that regular getPose is returning correct rotation as well. --- src/modules/headset/headset_vrapi.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/modules/headset/headset_vrapi.c b/src/modules/headset/headset_vrapi.c index 80b7071f..ae26416f 100644 --- a/src/modules/headset/headset_vrapi.c +++ b/src/modules/headset/headset_vrapi.c @@ -580,6 +580,14 @@ static struct ModelData* vrapi_newModelData(Device device, bool animated) { .skin = ~0u }; + // Root node transform has a rotation compensation for different coordinate spaces + if (device == DEVICE_HAND_LEFT) { + mat4_rotate(model->nodes[model->rootNode].transform.matrix, M_PI, 0.f, 0.f, 1.f); + mat4_rotate(model->nodes[model->rootNode].transform.matrix, M_PI / 2.f, 0.f, 1.f, 0.f); + } else { + mat4_rotate(model->nodes[model->rootNode].transform.matrix, -M_PI / 2.f, 0.f, 1.f, 0.f); + } + // Add the children to the root node *children++ = 0; *children++ = model->jointCount; @@ -606,24 +614,11 @@ static bool vrapi_animate(Device device, struct Model* model) { lovrModelResetPose(model); - // compensate for vrapi_getPose changing "forward" to be -Z - float compensate[4]; - if (device == DEVICE_HAND_LEFT) { - float q[4]; - quat_fromAngleAxis(compensate, (float) M_PI, 0.f, 0.f, 1.f); - quat_mul(compensate, compensate, quat_fromAngleAxis(q, (float) M_PI / 2.f, 0.f, 1.f, 0.f)); - } else { - quat_fromAngleAxis(compensate, (float) -M_PI / 2.f, 0.f, 1.f, 0.f); - } - // Replace node rotations with the rotations in the hand pose, keeping the position the same for (uint32_t i = 0; i < ovrHandBone_MaxSkinnable && i < modelData->nodeCount; i++) { float position[4], orientation[4]; vec3_init(position, modelData->nodes[i].transform.properties.translation); quat_init(orientation, &handPose->BoneRotations[i].x); - if(i == ovrHandBone_WristRoot) { - quat_mul(orientation, orientation, compensate); - } lovrModelPose(model, i, position, orientation, 1.f); }