Problems converting axis angle to quaternion

冷暖自知 提交于 2019-12-11 23:18:22

问题


I have a vector which points from my camera to an object I want to point to, so I want to make a quaternion which rotates the camera so that it points to that vector. So i do this (using glm)

glm::quat rotation=glm::angleAxis(0.0f,vector);

If i understand that function correctly in the case of a vector of, for example, (0.0f,0.0f,-1.0f), the camera should point forward in the depth axis, and with no roll. But i don't know why, in that case it creates this quaternion: x:-0 y:-0 z:-0 w:1 wich does nothing, and the x,y,z values only differ from 0 if the angle parameter passed to angleAxis() is different from 0. Why does this happen? if i pass angle 0, shouldn't it simply create a rotation with only yaw and pitch, and no roll?


回答1:


Already go the answer: (on the gameDev forum, from the user clb)

No, your understanding is off. Angle-axis rotation generates rotation about the given axis, by the given angle. If you don't specify an angle, you'll always get identity back. This is because rotation a zero angle, be it about any axis, of course does not rotate at all.

What you are thinking about is the LookAt rotation. I am not sure what the function signature in glm is, but I'm sure they have a similar function. Use a LookAt rotation to orient one direction vector to face towards another vector.



来源:https://stackoverflow.com/questions/12430311/problems-converting-axis-angle-to-quaternion

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