将轴角转换为四元数的问题 [英] Problems converting axis angle to quaternion

查看:75
本文介绍了将轴角转换为四元数的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

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

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?

推荐答案

答案已经走:(在gameDev论坛,来自用户clb)

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.

您正在考虑的是 LookAt 旋转.我不确定 glm 中的函数签名是什么,但我确定它们具有类似的功能.使用 LookAt 旋转将一个方向向量定向为面向另一个向量.

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.

这篇关于将轴角转换为四元数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆