How can I extrapolate the rotation of a new quaternion from two previous packages?

I am here here! I'm working on reducing the backlog in my first-person shooter, and now this is just a case of adding some extrapolation. I can extrapolate the position; getting the last two positions and speed from them, then adding speed to the existing position (* delta time). However, I cannot do the same for rotation. Angles are Euler by default, but I can (and do) convert them to quaternions, as they may suffer from gimball blocking. How would I extrapolate a new orientation from the two previous orientations? I have time between packages, 2 packages and current orientation.

+5
source share
2 answers

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 very well!

For two quaternions qa, qb this will give you interpolation and extrapolation using the same formula. t is the amount of interpolation / extrapolation, t 0.1 = 0.1 the path from qa-> qb, t = -1 → extrapolate the entire step from qa-> qb back, etc. I used self-tuning functions to enable the use of the / axisAngle quaternions with opencv cv :: Mat, but I would probably choose Eigen for this 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
+4
source

, , .

angular , , .

+1

All Articles