如何从之前的两个数据包推断出新的四元数旋转?

发布于 2025-01-06 05:47:16 字数 207 浏览 1 评论 0原文

我已经无计可施了!我正在致力于减少第一人称射击游戏中的延迟,现在只需添加一些外推法即可。 我可以推断位置;获取最后两个位置及其速度,然后将速度添加到现有位置(* 增量时间)。 但是,我不能对旋转做同样的事情。 默认情况下,角度是欧拉角,但我可以(并且确实)将它们转换为四元数,因为它们可能会受到万向节锁定的影响。 我如何从之前的两个方向推断出新的方向? 我在数据包、2 个数据包和当前方向之间有时间。

I'm at my wits end here! I'm working on lag-reduction in my First Person Shooter, and now it's just a case of adding some extrapolation.
I can extrapolate position; getting the last two positions and the velocity from them, then adding the velocity to the existing position (* delta time).
However, i cannot do the same for rotation.
By default, the angles are Euler, but i can (and do) convert them to quaternions as they can suffer gimball lock.
How would i extrapolate a new orientation from 2 previous orientations?
I have time between packets, 2 packets and current orientation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空心空情空意 2025-01-13 05:47:16

我在这里找到了一个很好的答案:
http://answers.unity3d.com/questions/168779/extrapolating-quaternion -rotation.html

我根据我的需要调整了代码,它工作得很好!

对于两个四元数 qa、qb,这将使用相同的公式进行插值和外推。 t是插值/外推的量,从qa->qb的方式t为0.1=0.1,t=-1->q从 qa->qb 推断出整个步骤,等等。
我使用自写函数来允许在 opencv cv::Mat 中使用四元数/axisAngle,但我可能会选择 Eigen

Quat qc = QuaternionMultiply(qb, QuaternionInverse(qa)); // rot is the rotation from qa to qb     
AxisAngle axisAngleC = QuaternionToAxisAngle(qc); // find axis-angle representation

double ang = axisAngleC.angle; //axis will remain the same, changes apply to the angle

if (ang > M_PI) ang -= 2.0*M_PI; // assume rotation to take the shortest path
ang = fmod(ang * t,2.0*M_PI);   // multiply angle by the interpolation/extrapolation factor and remove multiples of 2PI

axisAngleC.angle = ang;

return QuaternionMultiply(AxisAngleToQuaternion(axisAngleC),qa); // combine with first rotation

I found a good answer here:
http://answers.unity3d.com/questions/168779/extrapolating-quaternion-rotation.html

I adapted the code to my needs and it works quite well!

For the two quaternions qa, qb, this will give you interpolation and extrapolation using the same formula. t is the amount of interpolation/extrapolation, t of 0.1 = 0.1 of the way from qa->qb, t = -1 -> extrapolate a whole step from qa->qb back, etc.
I used selfwritten functions to allow the use of quaternions/axisAngle with opencv cv::Mat but I would probably choose Eigen for that instead

Quat qc = QuaternionMultiply(qb, QuaternionInverse(qa)); // rot is the rotation from qa to qb     
AxisAngle axisAngleC = QuaternionToAxisAngle(qc); // find axis-angle representation

double ang = axisAngleC.angle; //axis will remain the same, changes apply to the angle

if (ang > M_PI) ang -= 2.0*M_PI; // assume rotation to take the shortest path
ang = fmod(ang * t,2.0*M_PI);   // multiply angle by the interpolation/extrapolation factor and remove multiples of 2PI

axisAngleC.angle = ang;

return QuaternionMultiply(AxisAngleToQuaternion(axisAngleC),qa); // combine with first rotation
夏末 2025-01-13 05:47:16

如果将两个方向表示为向量,则它们的向量叉积将为您提供旋转轴,并且向量点积可用于查找旋转角度。

然后,您可以按照与计算标量速度相同的方式计算角速度,并使用它来计算围绕先前确定的轴的外推旋转。

If you represent the two orientations as vectors, the vector cross product of them will give you the axis of rotation and the vector dot product can be used to find the angle of rotation.

You can then calculate an angular velocity in the same way as you calculated the scalar velocity, and use it to calculate the extrapolated rotation around the axis determined earlier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文