How to rotate an object around 3 axis with the mouse?????

Hi there,
i got a tricky one…
How do i rotate an object around its 3 axis WITH a mouse?:wink:
What i did is:
I got a mouselistener running and convert the incoming integer values for x and y of the mouse into float values.
Then i scaled that values down by multiplying them with 0.01 to get values i can use with glRotatef.
(mrot+n are my float values , while mov+n are my integers i got from my mouse.

    mrotx = (movx * 0.01f);
    mroty = (movy * 0.01f);
    mrotz = (movx/2)+ (movy/2);

Therefore a mouse got no 3rd axis, i helped myself by creating an float mrotz from the x and y values.
I know, dirty.

Then i rotate the whole scene by passing the values through:
gl.glRotatef(mrotz, mrotx, 0f, 0f);
gl.glRotatef(mrotz, 0f, mroty, 0f);
gl.glRotatef(mrotx, 0f, 0f, mrotz);

So, when i move the mouse, i got an rotation like an drunken elk. ;D
It actually rotates around 3 axis, but lously;-)) :persecutioncomplex:

Does anyone of you got an code snippet for an cool and realistic rotation around the z Axis or how could i simulate this with my two x and y values from the mouse?

I actually want to rotate an whole scen of an rotating planet with moving cloudsphere, incl. an sourounding moon. The scene itself runs smoothly by the way, no probs there.
Thanks very much,
elnormeo

Firstly, are you sure you need to rotate the scene around all 3 axes? z rotation is typically a roll rotation, and from the description of your scene may not be needed.

Second, if you need your z rotation, then keep in mind that you are mapping a 2d space into a 3d space… so you need to mentally partition the 2d movement space into 3d rotations. You need to imagine exactly what results you want from what mouse motion.

Third, your (arbitrary) mrtoz is going to be dramatically greater than the x and y rots. It is going to be 2 orders of magnitude greater than mrotz and mroty in the case of diagonal movement.

Finally, you are misusing glRotatef(). You should really be passing a normalized vector to the x,y,z parameters. However, it claims to normalize for you. Anyway you are also rotating around the wrong vectors in all cases: (mrotz around x, mrotz around y, and mrotx around z). mroty isn’t even getting used.

I would recommend just doing away with mrotz and doing pure pitch and yaw, which is highly typical:

gl.glRotatef(mrotx, 0, 1, 0);
gl.glRotatef(mroty, 1, 0, 0);

Thank you;-)
I came to the conclusion of missusing my glRotatef to…during the night!..
I changed it now. Looks much better;-)
elnormeo

Check out using “arcball” interface. Here’s an example Java impl:

http://www.java-tips.org/other-api-tips/jogl/arcball-rotation-nehe-tutorial-jogl-port.html