Search code examples
opengl3dgeometryinterpolationquaternions

OpenGL ArcBall rotation and animation using interpolation?


In my OpenGL application I need to use ArcBall rotation to rotate objects using mouse.

I relized that I have to go with Quaternions after reading this article - http://www.gamedev.net/page/resources/_/technical/math-and-physics/quaternion-powers-r1095

And I found an easy to use implementation at here - http://www.codeproject.com/KB/openGL/virtualtrackball.aspx

But my problem is I also need to animate my object between saved two status. That is -

State(1)= (Postition X1,Position Y1,Position Z1, Rotation 1);

State(2)= (Postition X2,Position Y2,Position Z2, Rotation 2);

*These 'Rotations' are rotation matrices

And the animation is done in n steps.

Something like shown in this video - http://www.youtube.com/watch?v=rrUCBOlJdt4

If I was using 3 seperate angles for three axises(roll, pitch, yaw) I could easily interpolate the angles. But ,since ArcBall uses rotation Matrix , how can I interpolate the rotations between State 1 and State2 ?

Any suggestions ?


Solution

  • Either use Matrix or Quaternion for rotation representation internally. With roll/pitch/yaw you could interpolate the angles in theory, but this will not work every time - read up on Gimbal lock.

    With Quaternions the rotation interpolation is easy - just interpolate the individual coordinates (just as you would with r/p/y angles), normalizing when necessary. You'd have to then adjust your rendering function to work with quaternions (but I assume you already did that since you mention quaternions youself).

    With Matrixes the interpolation is not so nice, I've struggled with it several years back and all I can remember it that I finally decided to go with quaternions. So I can't advice on this, sorry.