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.
This commit is contained in:
bjorn 2021-05-31 14:35:53 -06:00
parent ce3470a6e6
commit 907305e430
1 changed files with 8 additions and 13 deletions

View File

@ -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);
}