Problems when moving around in a 3d world

I want to make a simple program that would load a box as a reference point and allow the user to move around with six keys: 2 to look up/down, 2 to look left/right, and 2 more to move forward and backward. First, I tried to make a simple program that would allow the user to move forward and backward. I am using GLUT, so I implemented the following into a keyboard event handler: (T = move forward, V = move backward)

case 'T':
case 't':
	zPos -= 0.05;
	break;
case 'v':
case 'V':
	zPos += 0.05;
	break;

then I put the following into a callback function to render the scene:

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glPushMatrix();
	glTranslatef( 0.0, 0.0, -5.0 );
	glutSolidCube( 1.0 );
glPopMatrix();

glTranslatef( 0.0, 0.0, -zPos );

glutSwapBuffers();

For some weird reason, say I press T a few times, it’ll move forward, but then when I hit V, it’ll keep moving forward to a point before it starts moving backward. The same is true when I flip the order. I am not sure why the controls are unyielding…can someone help me out?

Thank you

[This message has been edited by Big_al482 (edited 05-20-2001).]

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glLoadIdentity();

glTranslatef( 0.0, 0.0, -zPos );

glPushMatrix();
glTranslatef( 0.0, 0.0, -5.0 );
glutSolidCube( 1.0 );
glPopMatrix();

glutSwapBuffers();

make sure you have a default case in your switch statement

I am not sure, but maybe this is because of keyboard stuck? When you press ‘t’ very many times keyboard buffer is filled with a lot of ‘t’, and your program cant process all them fastly (for sure, if you use software rendering). Then you press ‘v’, but your program still process ‘t’. Then, after some time it starts processing ‘v’. Excuse me, if it wasnt clear.