0

我有一个向量,它从我的相机指向我想要指向的对象,所以我想制作一个四元数来旋转相机,使其指向该向量。所以我这样做(使用glm)

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

如果我在向量的情况下正确理解该函数,例如(0.0f,0.0f,-1.0f),相机应该在深度轴上指向前方,并且没有滚动。但我不知道为什么,在这种情况下,它会创建这个四元数: x:-0 y:-0 z:-0 w:1 什么都不做,并且 x,y,z 值仅在角度与 0 不同时传递给 angleAxis() 的参数不为 0。为什么会发生这种情况?如果我通过角度 0,它不应该简单地创建一个只有偏航和俯仰而没有滚动的旋转吗?

4

1 回答 1

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.

于 2012-09-16T07:39:07.040 回答