Rotation with Quaternion not quite right

无人久伴 提交于 2019-12-24 12:13:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!