I am still trying to rotate my draw using quaternions and still could’t succeed.

I have two rotations in Euler represantation

glRotatef(angx,1,0,0);
glRotatef(angy,0,1,0);

I create my local rotation quaternion by first converting those eulers to quaternion and then multiplying them. And it doesn’t work. Still I have gimbal lock problem. Here is the code. Can anyone show where I am doing wrong?

You still have a Gimbal Lock Problem because you still use Euler Angles(rti1 and rti2). Converting these to quaternions doesn’t help because it is too late, the “damage” has already been done.

Assuming you want to develop a “virtual trackball” you would probably want to find the rotation axis (perpendicular to both the view-vector and the “mouse-move-vector”) and angle (proportional to the length of the “mouse-move-vector”). Then construct a quaternion (or a matrix) out of that.

If anyone wants to here someone confesses he is a stupid and brainless guy, I can be the one. I am studying on quaternions for about four full days and I get totally lost in it and with my little English, I am still trying to understand these nonsense equations. I say I am still trying to the my best.

But that’s all. What does mouse movement vector mean? Is it that simple you describe in only two sentences? And how does view vector change? How can I know? I read approximately 20 tutorials. Where is it written?

Is it that simple you describe in only two sentences?
Not really I just didn’t go into too much detail since I am not sure where your Euler angles are coming from. I am just going to assume you are trying to do something like this.

If that’s the case then you would have 2 values describing the motion of the mouse (e.g. move the mouse left -> (-20,0) or move the mouse down a tiny bit -> (0,3) or something like that). Now you tack on an additional zero for the z-Axis which means that the mouse obviously didn’t move into the screen. That is what I called the Mouse-Move-Vector.

The view-vector is always going to be (0,0,1) (or (0,0,-1) depending on your convention).

The rotation axis is perpendicular to both of them, so you can just use the cross-product of the two (and normalize that).

The rotation angle is proportional to the length of the Mouse-Move-Vector, so just multiply that with some value that gives a nice feel.

This angle,axis pair can be converted into a quaternion rather easily. But since you are probably interested in a matrix to feed into OpenGL you can do that almost as easily.

Keep in mind that you should do these transformations incrementally. So either don’t LoadIdentity before you MultMatrix, or keep track of the complete current transformation yourself and multiply with that.

If something’s not entirely clear feel free to ask for clarifications.