使用四元数旋转不完全正确 [英] Rotation with Quaternion not quite right
问题描述
从我的上一个问题继续,我现在设法旋转我的对象与四元数,但仍有一个小问题,我不知道如何解决它。使用下面的代码我的对象旋转x和y轴。但是当我在x和y键之间切换时,它总是跳回到初始位置。所以我永远不会从新的位置轮换,但总是从程序开始的一个。
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.
推荐答案
但是当我在x-和y-之间切换时它总是跳回到初始位置,键。所以我永远不会从新的位置轮换,但总是从程序开始的一个。
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 :: mult(Quaterion& q1,Quaterion& q1)
,但是我怀疑它将四元数实例的内容替换为q1和q2。您需要将当前方向乘以q1 * q2以获取新方向,而不是使用q1 * q2替换当前方向。
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.
这篇关于使用四元数旋转不完全正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!