Jump to content


Mouse Trackball rotation


1 reply to this topic

#1 Nyad

    Member

  • Members
  • PipPip
  • 44 posts

Posted 10 February 2008 - 08:43 PM

Hi I am having some trouble with mouse trackball rotation.

I take my initial mouse pos. use gluUnproject to get it's world pos.
then I take my new/current mouse pos and do the same.
By using the dot product I can get the angle and by using the cross product
I can get the axis of rotation.
I am using glRotate, ie rotational matrices and not quaternions.

I do this and it rotates etc.
But now say I have rotated my object and it is in its rotated state.
I now move around and want to rotate it again using the same method as described above, now my axis-of rotation will be different and so will my angle.

I want both of these and any new rotations to be applied to my object.
ie I rotate to pos 1, then to pos 2 and then to pos 3. but each rotation
must be done from the previous state.

So I can't just use my new angle and axis each time without compensating for its current state.

Please help

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 11 February 2008 - 02:26 AM

Nyad said:

So I can't just use my new angle and axis each time without compensating for its current state.

Sure you can. You can just compose the two rotations. If you're using matrices, you just multiply them together. However this will rapidly lead to loss of orthogonality due to roundoff error, so it's a better idea to use quaternions. Keep the current rotation as a quaternion, and in each frame, create a quaternion from the rotation axis and angle and multiply it with the current one. Renormalize as needed, convert to a rotation matrix for rendering and you should be good to go.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users