a simple question on glTranslate

Hi, I have drawn a cube resting on a 3 dimensional rectangle and I want to use glTranslate to move the whole object(cube+rectangle) via keyboard presses, how do I make it so that the cube doesn’t move and only the whole object moves? thanks.

Hi !

You use glPushMatrix and glPopMatrix to do hierarchical transformations.

glPushMatrix();
transform entire object here
glPushMatrix();
transform before cube
render cube
glPopMatrix();
glPushMatrix();
transform before rectangle
render rectangle
glPopMatrix();
glPopMatrix();

This way you save do local transformations to modify a single triangle or whatever and also transform the entire shape if you want to.

Mikael

Hi, they moved uniformly for awhile but doesn’t not always stay together when moving. For example, the cube would just be couple of points behind the rectange after a long movement down the plain.