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.
Translate center to origin, rotate, translate back to center:
glTranslate(-xcenter, -ycenter, -zcenter);
glTranslate(xcenter, ycenter, zcenter);
The order order of operations might need to be reversed as follows:
glTranslatef(xcenter, ycenter, zcenter); // move back to focus of gluLookAt
glRotatef(.....whatever.....); // rotate around center
glTranslatef(-xcenter, -ycenter, -zcenter); //move object to center
Thanks dorbie and marshats.
The code worked perfectly.