mczhao

10-29-2001, 06:32 PM

I have a model centered in origin, and i want to use mouse to control its transformation, i.e.,left click to control its rotation, right click to control its translation and middle click to control its zooming.

At the beginning of every frame, i added these code:

glPushMatrix();

//Applying transformation

glTranslatef(Position_x,Position_y,Position_z);

glRotatef(Rotate_x,1.0,0.0,0.0);

glRotatef(Rotate_y,0.0,1.0,0.0);

glRotatef(Rotate_z,0.0,0.0,1.0);

glScalef(Scale_x,Scale_y,Scale_z);

DrawScene(); //Draw the model

glPopMatrix(); //Clear the modelview matrix to identity matrix

where Position_x,Position_y,Position_z are modified in the event of RightClick according to the offsets of mouse position. The processing of Rotate_x, Rotate_y, Rotate_z, Scale_x, Scale_y, Scale_z is similar to above.

In most conditions,these code work fine . But i observe that in certain condition, the rotation around y axis is swaped to the rotation around z axis. I don't know how to avoid this problem. Any one can give me some

advice?

Thanks!

At the beginning of every frame, i added these code:

glPushMatrix();

//Applying transformation

glTranslatef(Position_x,Position_y,Position_z);

glRotatef(Rotate_x,1.0,0.0,0.0);

glRotatef(Rotate_y,0.0,1.0,0.0);

glRotatef(Rotate_z,0.0,0.0,1.0);

glScalef(Scale_x,Scale_y,Scale_z);

DrawScene(); //Draw the model

glPopMatrix(); //Clear the modelview matrix to identity matrix

where Position_x,Position_y,Position_z are modified in the event of RightClick according to the offsets of mouse position. The processing of Rotate_x, Rotate_y, Rotate_z, Scale_x, Scale_y, Scale_z is similar to above.

In most conditions,these code work fine . But i observe that in certain condition, the rotation around y axis is swaped to the rotation around z axis. I don't know how to avoid this problem. Any one can give me some

advice?

Thanks!