Friday, 6 September 2013

3D hierarchical quaternion rotation is wrong when it is out the range of 90 to -90 (GLM)

3D hierarchical quaternion rotation is wrong when it is out the range of
90 to -90 (GLM)

I've been lost in this problem for a long time. I am doing a character
animation system using OpenGL. My bone system is based on quaternion. A
local rotation quaternion rotate is stored and updated by the following
function (rot is the update rotation):
rotate = rot * rotate;
updateTransform(this);
Then iteratively update the global transform from this bone to the end
effector.
glm::mat4 T = glm::translate(bone->offset);
glm::mat4 R = glm::toMat4(bone->rotate); //glm::rotate(bone->euler.x,
glm::vec3(1, 0, 0)) * glm::rotate(bone->euler.z, glm::vec3(0, 0, 1)); //*
glm::rotate(bone->euler.y, glm::vec3(0, 1, 0))
glm::mat4 S = glm::scale(bone->scale);
glm::mat4 localTransform = T * R * S;
if(bone->getID()!=0)
{
bone->globalTransform = bone->getParent()->globalTransform *
localTransform;
}
else
{
bone->globalTransform = localTransform;
}
for (uint i = 0 ; i < bone->getChildren().size() ; i++) {
updateTransform(bone->getChildren()[i]);
}
Now here comes the problem. The rotation is messed up when a joint's
parent global rotation is bigger than 90 or smaller than -90 on x axis or
z axis. For instance, the hip to upperarm are in their default poses
(y-axis positive direction). The forearm is rotating good. However, if I
put a 180 rotation on the upperarm. The forearm wouldn't rotate correctly
any more.
In another words, when the global rotation goes into the y-axis negative
direction, the child rotation will not work.
Sorry for my bad english, I am very welling to explain the problem more if
there is unclear point. As I already spent so much time on this problem, I
highly appreciate any help answers or tutorial!

No comments:

Post a Comment