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

Ang*_*nds 5 math networking interpolation angle rotation

我的斗智尽头!我正在努力减少第一人称射击游戏中的延迟减少,现在只是添加一些推断的情况.我可以推断位置; 获取最后两个位置和速度,然后将速度添加到现有位置(*delta时间).但是,我不能做同样的轮换.默认情况下,角度是欧拉,但我可以(并且确实)将它们转换为四元数,因为它们可能遭受gimball锁定.我将如何从以前的2个方向推断出新的方向?我有数据包,2个数据包和当前方向之间的时间.

Oli*_*del 5

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

我根据自己的需要调整了代码,并且效果很好!

对于两个四元数 qa、qb,这将使用相同的公式为您提供内插和外推。t 是内插/外推的量,t of 0.1 = 0.1 of the way from qa->qb, t = -1 -> 从 qa->qb back 外推整个步骤,等等。我使用自写函数来允许使用带有 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
Run Code Online (Sandbox Code Playgroud)


caf*_*caf 1

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

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