问题
Following on from my previous question, I have now managed to rotate my object with quaternions but there is still a small problem and I dont know how to solve it. With the code below my object rotates round the x and y axis. But it always jumps back to the initial position when I switch between x- and y-key. So I never get a rotation from the new position, but always from the one with which the programm started.
Quaternion q1 = quaternion->quat_rotate(anglex,1,0,0);
Quaternion q2 = quaternion->quat_rotate(angley,0,1,0);
quaternion->mult(q1,q2);
quaternion->quat_matrix(Matrix);
glMultMatrixf(Matrix);
object->drawObject(Red,Green,Blue);
I hope you understand what I mean.
回答1:
But it always jumps back to the initial position when I switch between x- and y-key. So I never get a rotation from the new position, but always from the one with which the programm started.
Of course it does. Your code is doing exactly what you are telling it to do. You haven't shown us what Quaternion::mult(Quaterion&q1,Quaterion&q1)
does, but I suspect it replaces the contents of the quaternion instance with the product of q1 and q2. You need to multiply the current orientation by q1*q2 to get the new orientation rather than replace the current orientation with q1*q2.
来源:https://stackoverflow.com/questions/7939770/rotation-with-quaternion-not-quite-right