How can I get one wire sphere to stay stationary while another one translates?
Here is my code right now:
void animate ()
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
glColor3f (1.0, 0.0, 0.0);
glutWireSphere (1.0, 20, 20);
glColor3f (0.0, 1.0, 0.0);
glPushMatrix ();
glTranslatef (0, 0.01, 0);
glutWireSphere (0.2, 20, 20);
glPopMatrix ();
glPopMatrix();
glFlush ();
glSwapBuffers ();
glutTimerFunc (10, animate);
}
Currently all that happens is that both spheres are stationary. The behavior I want is to have the larger red sphere to stay still while the smaller green sphere slowly translates up. What am I doing wrong?
Problem here is you are translating on the y-axis by the same amount each frame. Your matrix is set to identity each frame, so your smaller green sphere is always at
(0.0,0.01,0.0).Try keeping track of the position, and increment.