我的斗智尽头!我正在努力减少第一人称射击游戏中的延迟减少,现在只是添加一些推断的情况。 我可以推断位置;获取最后两个位置和速度,然后将速度添加到现有位置(* delta时间)。 但是,我不能做同样的轮换。 默认情况下,角度是欧拉,但我可以(并且确实)将它们转换为四元数,因为它们可能遭受gimball锁定。 我将如何从以前的2个方向推断出新的方向? 我有数据包,2个数据包和当前方向之间的时间。
答案 0 :(得分:4)
我在这里找到了一个很好的答案: http://answers.unity3d.com/questions/168779/extrapolating-quaternion-rotation.html
我根据自己的需要调整了代码,效果很好!
对于两个四元数qa,qb,这将使用相同的公式进行插值和外推。 t是内插/外推量,t = 0.1 = 0.1,从qa-qb开始,t = -1->从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
答案 1 :(得分:1)
如果将两个方向表示为矢量,它们的矢量叉积将为您提供旋转轴,矢量点积可用于查找旋转角度。
然后,您可以使用与计算标量速度相同的方式计算角速度,并使用它计算围绕先前确定的轴的外推旋转。