# rotating 3D object around the center

I have object moving from A to B on x-axis and there is no translation of object apart from it. Now, while moving, i want to rotate it around y-axis and the motion should change accordingly, i mean if i rotate it right when moving from -x to +x axis, it should move towards near plane. I have variable in gltranslatef which is modified in the loop after that i have glscalef to scale whole object which is made of hierarchical structure. Now i tried following code to achieve the expected result but its not working properly

   glTranslatef(move, 0, 0);

// If I comment these 3 lines, it does not affect the output
glTranslatef(-move, 0, 0);
glRotatef(rotate,0,1,0);
glTranslatef(move, 0, 0);

glScalef(0.2, 0.2, 1.0);


Transformations (scale,rotation, translation) are applied in the reverse order of their invocation and transformations do not change the object's position or orientation but the coordinates system that will be used to render it. Imagine the 3D coordinates system as 3 axis ( X,Y,Z ) perpendicular to each other. In case your object lies along the X axis, if you rotate the coordinates around the Y axis, your object will come towards the near or far plane because it lies in a position on the X axis. If you want to rotate the object around itself, you should place it in the center of the coordinates system.

glTranslatef(move, 0, 0);