
OpenGL Rotation Part 2
Hi all!!
This is yet another rotation problem.. Once the image is displayed i m rotating on screen. If i move my move left or right then i captured that and rotate using
glRotated(captured_angleX , 0.0,1.0,0.0);
similarly if i move up or down i rotate using
glRotated(captured_angleY , 1.0,0.0,0.0);
IT WORKS VERY WELL.. But The problem is I want to rotate with respect to Zaxis. How to do it?? If my question is not clear jus ping me i will elaborate the problem statement.

I have not used openGL, but I assume it would be something like this:
glRotated(value , 0.0,0.0,1.0);
I think you have X and Y mixed up as well.
OpenGL rotation

thats ok. But how to calculate that value(Angle)??

I assume that if you want to rotate 90 degrees, value = 90

I think what your asking is, "I am already calculating a given angle of rotation on the X and Y axes based off of mouse movement, how can I also calculate the angle of rotation on the Z axis based off of the same mouse movement?"
Short answer: you can't. Mouse movement is 2 dimensional, and so extracting a 3rd dimension of data from it is extremely difficult to do (if not impossible). Some research has been going on in this field however (research on extracting 3d information from a 2d model) and significant advances have been made at Stanford. Check the link out...it's way cool stuff.
But anyways, back to your question. You basically need to provide a 3rd way for the user to input data. One of the most simple ways is to use keyboard input. Bind two keys on the keyboard to the rotation on the Zaxis. For now let's say we use the keys Q and W. If the user presses Q it will increase the angle of rotation on the Zaxis, and if the user presses W it will decrease the angle of rotation. There are a myriad of other ways you could do it. You could have the user hold down the mouse wheel, and then you could interpret any mouse movement while the mouse wheel is held down as rotating along the Zaxis.
But the basic jist of it is that you can't just do it based off of your current 2dimensional mouse movement data.

Using the mouse wheel for Z rotation would be a bit counterintuitive. I don't quite understand why you care about Z rotation since in most systems this is a roll operation about the z axis. Z rotations are not all that useful or at least I've not found them to be. It may be possible to extract the Z rotation by turning the x and y motions of the mouse into vectors, crossing them, and normalizing. However this will also yield some wacky results. Microsoft has an arcball class that turns mouse movements into a quaternion so you may want to look in their SDK for this sample on how to do it.
Another problem is you are using Euler angles. If you imagine Euler angles as 3 concentric rings mounted about a center point you quickly realize something. There is a point at which all 3 rings can line up with one another. It is at this point you will experience gimbal lock as one axis of rotation is mapped onto another axis. Anything you do on one axis will now affect another axis. There are several ways to overcome this. You can perform axisangle rotations which are very similar in nature to quaternions or you can just use quaternions. The disadvantage to using quaternions is that graphics APIs want their rotations expressed as matrices. So it takes a bit of math to express the quaternion in matrix form. The advantages to quaternions are many. You can use SLERP or spherical linear interpolation which will always smoothly interpolate from one quaternion to another  or more simply one 3D orientation to another. Trying to do this using Euler angles is an exercise in frustration. Euler angles do not LERP well and simply cannot SLERP as easily as quaternions. Quaternions also offer quadratic slerp or SQUAD although my experience with SQUAD is quite limited.
A quick test to determine if you are gimbal locked is to pitch the camera straight up to 90 degrees or PI/4. Now attempt to yaw or rotate about the y axis. If you are not using axis angle rotations you will not yaw but will roll. As you roll you will also find a point at which a rotation about the x axis does not yield the expected results. Problem is that the more you pitch the more the yaw is mapped onto another axis. So at 45 degrees up pitch you are beginning to map onto another axis of rotation. The situation gets out of hand very quickly.

"You could have the user hold down the mouse wheel, and then you could interpret any mouse movement while the mouse wheel is held down as rotating along the Zaxis".. How to do it DavidP????

One More Problem: When i move my mouse along Xaxis or Yaxis at a time my rotation is perfect.. Suppose if i move my mouse diagonally where Both X and Y point changes, my rotation is not working properly.. To be clear the rotation is not clear.. its like dragging the object here and there. Kindly suggest some ideas If any...

Quote:
How to do it DavidP????
Some ifstatements, an event handler, and a couple of boolean variables? I assume it should integrate with whatever method you are using to currently catch your mouse movement.
You might want to make a camera class. Here is a good tutorial:
http://www.flipcode.com/archives/OpenGL_Camera.shtml

lemme try n ping u back...