Rotating a 3-D object centerd at the origin

How can I rotate an object drawn at the ORIGIN in each of the three axis(x,y, and z)or rotate along a line parallel to each of the axis?

Also can someone give me an example or explain Quanternions, PLEASE?

[This message has been edited by ELIMT (edited 12-03-2001).]

[This message has been edited by ELIMT (edited 12-03-2001).]

[This message has been edited by ELIMT (edited 12-04-2001).]


Quaternions are people from the planet Quatern. They are a very reclusive race and don’t like even being talked about, let alone having examples made of them.

Game Programming Gems and also Gamasutra have some simple examples on Quaternions.

Thanks Kaycee! But I think its the world axis is what I want the object to be rotated about So if you can still help me out much appreciated Thank You.

[This message has been edited by ELIMT (edited 12-05-2001).]

I think I know what you want to do. Are you trying to rotate the object about its axis and not about the world axis?

If so you need to rotate the axis too.


glRotatef(angle_x, 1.0, 0.0, 0.0);

float Matrix[16];
glGetFloatv( GL_MODELVIEW_MATRIX, Matrix );
float VectorY[3] = { 0.0, 1.0, 0.0 };
MatrixMult( matrix, VectorY );
glRotatef(angle_y, VectorY[0], VectorY[1], VectorY[2]);

glGetFloatv( GL_MODELVIEW_MATRIX, Matrix );
float VectorZ[3] = { 0.0, 0.0, 1.0 };
MatrixMult( matrix, VectorZ );


glRotatef(angle_x, 1.0, 0.0, 0.0);
glRotatef(angle_y, VectorY[0], VectorY[1], VectorY[2]);
glRotatef(angle_z, VectorZ[0], VectorZ[1], VectorZ[2]);

Hmmmm, I might have that backwards. If you try this out tho you will see your object always rotating about its own axis.

I know exactly what you’re talking about. I’m doing a class project right now where I’m trying to walk the viewpoint around a sphere centered at the origin. Quaternions are definitely the way to go. Try searching around on the net for some code that implements a trackball and quaternions. I found two files (I don’t have them here or I’d post them) trackball.c and trackball.h that have a nice implementation of the idea. Essentially you pass in two points, then the code finds an axis of rotation and a rotation angle (you can just give it these parameters yourself if you want). The rotation axis and angle are then converted to quaternion notation. The beauty of quaternions is that you can just add rotation to rotation without worrying about the order you apply them. So the code will have an ‘add quaternion’ function that will combine your previous rotation to the new one, and then a function that takes the resulting quaternion and makes a single rotation matrix out of it. This single rotation matrix is what you want to use when transforming your scene. Instead of using glRotate you will use glMultMatrix() with the new rotation matrix as the parameter. It works for me!