mirror of https://github.com/bjornbytes/lovr.git
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:
parent
b6c3a8fa17
commit
89550e55d6
|
@ -572,6 +572,14 @@ static struct ModelData* vrapi_newModelData(Device device, bool animated) {
|
||||||
.skin = ~0u
|
.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
|
// Add the children to the root node
|
||||||
*children++ = 0;
|
*children++ = 0;
|
||||||
*children++ = model->jointCount;
|
*children++ = model->jointCount;
|
||||||
|
@ -598,24 +606,11 @@ static bool vrapi_animate(Device device, struct Model* model) {
|
||||||
|
|
||||||
lovrModelResetPose(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
|
// 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++) {
|
for (uint32_t i = 0; i < ovrHandBone_MaxSkinnable && i < modelData->nodeCount; i++) {
|
||||||
float position[4], orientation[4];
|
float position[4], orientation[4];
|
||||||
vec3_init(position, modelData->nodes[i].transform.properties.translation);
|
vec3_init(position, modelData->nodes[i].transform.properties.translation);
|
||||||
quat_init(orientation, &handPose->BoneRotations[i].x);
|
quat_init(orientation, &handPose->BoneRotations[i].x);
|
||||||
if(i == ovrHandBone_WristRoot) {
|
|
||||||
quat_mul(orientation, orientation, compensate);
|
|
||||||
}
|
|
||||||
lovrModelPose(model, i, position, orientation, 1.f);
|
lovrModelPose(model, i, position, orientation, 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue