Rotating an Object around its center.

Hi,

My program creates array of voxels of any scanned object. What I want is to rotate the object around its center.

Right now my code displays the object but when I rotate it, it is rotated around some point which cause the object to go outside the window. I rather want to rotate the object around its center, so that I could see its all parts in the window. I have already calculated the center of the object and I have put center of interest in gluLookAt function as center of the object.

Can anyone please help me out to solve this problem.

Thanks

Translate center to origin, rotate, translate back to center:

glMatrixMode(GL_MODLEVIEW);
glPushMatrix();
glTranslate(-xcenter, -ycenter, -zcenter);
glRotate(…whatever…);
glTranslate(xcenter, ycenter, zcenter);
DrawObject();
glPopMatrix();

The order order of operations might need to be reversed as follows:


glMatrixMode(GL_MODLEVIEW);
glPushMatrix();
glTranslatef(xcenter, ycenter, zcenter); // move back to focus of gluLookAt
glRotatef(.....whatever.....); //  rotate around center
glTranslatef(-xcenter, -ycenter, -zcenter); //move object to center
DrawObject();
glPopMatrix();

Thanks dorbie and marshats.

The code worked perfectly.