PDA

View Full Version : 3D Rotation in every direction



tito_h
05-08-2009, 02:54 AM
I need to implement a 3D-rotation with a fixed object, with mouse interaction. It's like dragging the object, and rotating it in every direction.
For example pointing the mouse in the upper middle of the window and press button and move the mouse down, the object rotates around the x axis, the same but more difficult if the mouse is pointed in the upper right corner, and you are "dragging" the mouse pointer to the middle the object rotates to the lower left corner.

I have tried some solution on my own, but they were not satisfiable. Does anybody know a hint how to solve this?

tia
tio_h

Heiko
05-08-2009, 04:46 AM
You might wanna look into arcball rotation. The principle is more or less the following:

You click somewhere in the screen, the xy position on the screen is translated to an xyz position an a virtual sphere (the arcball). If the xy position of your mouseclick is within the circle that represents the flatten outer border of the virtual sphere there is a z component (sphere: x^2 + y^2 + z^2 = 1). If the xy position of you mouse cursor is outside the sphere the z component is 0 (because x + y > 1 already).

Using this you can calculate the point on the virtual sphere you have clicked on. Now move your mouse and calculate the new position of your mouse cursor on the sphere. Now you have two points on a sphere (start and end), which means you can calculate a rotation of the object.

A more in depth (with more mathematical details) description of this algorithm can probably found quite easy on the internet.

tito_h
05-08-2009, 08:51 AM
thx! that's exactly what i needed!

awhig
06-25-2009, 08:47 AM
Is it similar to Quaternions using slerp interpolation technique?