我可以从偏航/俯仰/滚动创建的两个四元数中插入旋转吗?
四元数非常适合在它们之间插值旋转。到目前为止,一切都很好。
如果我有一个网络游戏,将旋转传输为 vector3f 就足够了还是应该使用四元数? 为了使游戏更流畅,我可能必须在最后发送的轮换和当前轮换之间进行插值。
但是我可以在从偏航/俯仰/滚动创建的两个四元数之间插入旋转吗?
Quaternion a = Quaternion.FromYawPitchRoll(x1,y1,z1);
Quaternion b = Quaternion.FromYawPitchRoll(x2,y2,z2);
a.Interpolate(b, value); // will this work correctly?
Quaternions are good for interpolate rotations between them. so far so good.
If I have a networking game, will it suffice to transfer the rotation as vector3f or should I use a quaternion?
To make the game smoother I may have to interpolate between the last sent rotation and the current one.
But can I interpolate rotations between two Quaternions which were created from Yaw/Pitch/Roll?
Quaternion a = Quaternion.FromYawPitchRoll(x1,y1,z1);
Quaternion b = Quaternion.FromYawPitchRoll(x2,y2,z2);
a.Interpolate(b, value); // will this work correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,你可以。欧拉角的问题是万向节锁,即某些方向最终会少一个自由度。当您从欧拉角转换为四元数时,这个问题就解决了。您可以将几乎任何 3D 轴表示形式转换为四元数形式并转换回来,而不会丢失任何信息。矩阵必须是各向同性的(无缩放或剪切),并且向量必须具有单位长度。
四元数之间的线性插值称为slerp。四元数之间的二次插值称为squad。由于四元数只是具有三个虚部的复数,因此适用于实数和向量的相同方程也适用于四元数。只要记住在进行乘法、加法、对数和求幂时使用正确的规则即可。可以想象,虚部 i、j 和 k 一起形成一个轴向量,而实部是一个尺度。
Yes you can. The problem with Euler angles is gimbal lock, that some orientations ends up with one less degree of freedom. When you convert from Euler angles to a quaternion, that problem is solved. You can convert almost any 3D-axis representation into quaternion form and back, without any loss of information. Matrices must be isotropic (no scale or shearing), and vectors must be of unit length.
Linear interpolation between quaternions is called slerp. Quadratic interpolation between quaternions is called squad. Since quaternions are just complex numbers with three imaginary parts, the same equations that work on real numbers and vectors applies to quaternions. Just remember to use the correct rules when doing multiplication, addition, log and exponentiation. It can help to imagine that the imaginary parts i,j and k together form an axis vector, while the real part is a scale.
您可以在四元数之间进行插值。我曾经编写过一个基于四元数的关键帧动画生成器,它从几个特定点为渲染系统生成帧。我无法分享代码,因为它是机密的:-(
在 80 年代的某个时候,SIGGRAPH 会议记录中有一篇关于这个主题的论文。四元数的主要优点是不存在像欧拉角那样的奇点。
啊,这里是参考文献:
Shoemaker, Ken“用四元数曲线动画旋转”,SIGGRAPH '85,旧金山,1985 年 7 月 22-26 日,第 19 卷,第 3 期,1985 ACM 0-89791-166-0/85/007 /0245,第 245-254 页。
You can interpolate between quaternions. I once wrote a quaternion-based keyframe animation generator that generated frames for a rendering systems from a few specific points. I can't share the code because it's classified :-(
There was a paper in the SIGGRAPH proceedings sometime in the 80s about this very topic. The main advantage of quaternions is that there's no singularity like there is with Euler angles.
Ah, here's the reference:
Shoemaker, Ken “Animating Rotation with Quaternion Curves”, SIGGRAPH '85, San Francisco, Jul. 22-26, 1985, vol. 19, No. 3, 1985 ACM 0-89791-166-0/85/007/0245, pp. 245-254.
是和不是。这是一个很好的讨论:
http://number-none.com/product/了解%20Slerp,%20Then%20Not%20Using%20It/
请注意,如何获得四元数并不重要,相同的规则适用。
编辑:我已经在许多项目中使用了本文中提供的源代码,并且可以证明这一点。
Yes and no. Here's a good discussion:
http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/
Note it doesn't really matter how you got the quaternions, the same rules apply.
Edit: I have used the source code presented in the paper on a number of projects and can vouch for it.