Trig question with OpenGL?

I’m trying to model true 3d movement.
For example, if I’m walking on a flat ground in my 3d world, I could use:

if(GetAsyncKeyState(VK_UP)) {
x += sin(angle * (3.14 / 180)) * walkSpeed;
z += cos(angle * (3.14 / 180)) * walkSpeed;

if(GetAsyncKeyState(VK_DOWN)) {
x -= sin(angle * (3.14 / 180)) * walkSpeed;
z -= cos(angle * (3.14 / 180)) * walkSpeed;

to calculate my new X and Z positions.

This isn’t the problem. In this method my “Y” value is always constant. I want to allow movement in the “Y” direction based on a “lookAround” (up and down on the Y Axis) angle I’ve calculated.

I can’t seem to get the trig to figure out this value. I can look up, but I’m always moving forward as if I’m looking forward. I want to move in the direction the camera appears to be looking. So if I point my gun at a 45 degree angle upwards, I want the bullet to move on the proper trajectory. X,Y, and Z… Any suggestions? Thanks again…

Here is the code that I use to move my camera :

/*
f is your walkspeed
*/

void r_Camera::moveForward (float _f)
{
translate(float(cos(rotation_y * degree2radian + halfPI)) * _f, 0.0f, float(sin(rotation_y * degree2radian + halfPI)) * _f);
}

void r_Camera::strafeLeft (float _f)
{
translate(float(cos(rotation_y * degree2radian)) * _f, 0.0f, float(sin(rotation_y * degree2radian)) * _f);
}

Hope it can help you

Thank you but that didn’t tell me how to calculate the new Y value…Y is not a constant.

Try this…

if (up_Is_Pressed)
{
X_Pos += (float)sin(Look_Left_Right * OneDegree) * 5;
if (Fly_Enabled)
Y_Pos += (float)tan(Look_Up_Down * OneDegree) * 5;
Z_Pos += (float)cos(Look_Left_Right * OneDegree) * 5;
}

It’s not the most portable way of doing it, but give it a try.