3D Rotation in every direction

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

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.

thx! that’s exactly what i needed!

Is it similar to Quaternions using slerp interpolation technique?