views:

91

answers:

3

I'm trying to achieve an object rotation about 3 axes by incrementing values of rotation angles for axes, and displaying those axes to make next rotation direction predictable for the viewer. But after a few rotations, only rotation about Z-axis is performed in accord with displayed axis. Is there a chance it can be done simply, without poring over quaternions?

glPushMatrix ();
glRotatef (angleX, 1.0, 0.0, 0.0);
glRotatef (angleY, 0.0, 1.0, 0.0);
glRotatef (angleZ, 0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex3f(80.0, 0.0, 0.0);   //x axis
glVertex3f(-80.0, 0.0, 0.0);
glVertex3f(0.0, 80.0,  0.0);  //y axis
glVertex3f(0.0, -80.0,  0.0);
glVertex3f( 0.0, 0.0, 80.0);  //z axis
glVertex3f( 0.0, 0.0, -80.0);
//here is some code for drawing arrows at axes ends
glEnd();
glPopMatrix();

Edit: I have axes like those: http://img841.imageshack.us/i/arrowsx.jpg/ angleX, angleY, angleZ are globals incremented on key press - e.g. after pressing 'A' angleX is incremented by 10, and I expect axis X won't move after that and axes Y and Z will rotate about axis X. But it is true only when I change only one of angle variables. After rotation about more then one axis, when I change, e.g. angleX - all axes from picture will change their positions.

+2  A: 
andand
Thanks, that's a simple solution I was looking for.
majaen
A: 

I did a bit of OpenGL programming in college. It seems like I ran into the same problem, and ended up applying the total sum of each angle each time any given angle was updated.

Joshua Bailey
A: 

Quaternions are not that difficult. You essentially do something like this (it is pretty simple to implement the Quat class) -

Matrix yawMatrix = Quat(yawAxis, m_rx).matrix();
Matrix pitchMatrix = Quat(pitchAxis, m_ry).matrix();
Matrix rotMatrix = Matrix::multiply(yawMatrix, pitchMatrix);

and apply the rotation matrix to the eye point of your camera to rotate it about the target point.

tathagata