Moving around in 3d space with input

I am trying to get user input from the client and move around in 3D space. I thought it would be an easy task buy doing something like this

case ‘f’ :
veiwerPos.z += 1;
} break;
case ‘r’:
veiwerPos.z -=1;
} break;
case ‘g’:
veiwerPos.x += 1;
} break;
case ‘h’ :
veiwerPos.x -= 1;
} break;

vgvec2 pos(event->mouseDeltaX, event>mouseDeltaY);
angleX += pos.x;
angleY += pos.y;
if(angleY > 45.0f)
angleY = 45.0f;
if(angleY < -45.0f)
angleY = -45.0f;
axis = pos.Normalize();
glRotatef(angleX, 0, axis, 0);
glRotatef(angleY, axis, 0, 0);
glTranslatef(veiwerPos.x, veiwerPos.y, veiwerPos.z )

I am not saying this works but it is not how I want it to work. If any one that knows what I am doing wrong or can help me out please e-mail me or respond to this post
David Gholami

you have to think of a sphere.
so, i will give you the math, you will write the code:

x = sin(angle_one_in_radians)

z = cos(angle_one_in_radians)

y = cos(angle_one_in_redians)

where angle_one is the angle starting looking down the z-axis and rotating around the y-axis, and angle_two is rotating around the x-axis.

this i called the equation for a sphere, pretty standard stuff, this gets the unit change, you can multiply x and z by any scalar to increase the step amount.

finally it will look like this

for walking forward:

player_pos_x += player_pos_x + (xscalar)
player_pos_z += player_pos_z + (z

walking backward just subtracts tehm.

and for turning:

cam_pos_x += cam_pos_x + (xscalar)
cam_pos_x += cam_pos_x + (z
cam_pos_y += cam_pos_y + (y*scalar)

I’m not sure what the axis = pos.Normalize()means. Normally I would expect something like
glRotatef(angleX, 1.0f, 0.0f, 0.0f);
glRotatef(angleY, 0.0f, 1.0f, 0.0f);
for the x- and y-axis (or maybe in the other order, first yaw then pitch?)

Don’t forget to start with the same matrix all the time, so add glLoadIdentity() before or glPushMatrix(); glPopMatrix() around the transformations. Otherwise the rotations and transformations will concatenate at each loop (far out…).