# Thread: Move the camera to the direction it points

1. ## Move the camera to the direction it points

Hi
This may be a very basic question, but I do not know how to do this.
I am trying to make a fps type camera and I am using following code to move and setting orientation of the camera

Code :
```glMatrixMode( GL_MODELVIEW );

glRotatef(rollValue, 0, 0, 1);	// roll
glRotatef(yawValue, 0, 1, 0);	// yaw
glRotatef(pitchValue, 1, 0, 0); // pitch
glTranslatef(x, y, .z); // to move

// then draw shapes```

The problem is I can move the camera but not to the direction it points to.
Could you please tell me how to do that?

2. ## Re: Move the camera to the direction it points

there are basically two ways, the first one is to use basic trigonometry like this

#define PI_OVER_180 0.017453292519943295769236907684886

x=((float)sin(-yawValue/PI_OVER_180)*forward)-((float)sin(+(yawValue+90)/PI_OVER_180)*strafe);
y=((float)sin(pitchValue/PI_OVER_180)*forward)+up;
z=(-((float)cos(-yawValue/PI_OVER_180)*forward))-((float)cos(+(yawValue+90)/PI_OVER_180)*strafe);

or you could get the modelview matrix and then multiply it with the vector you wish to move in (with the fourth value being 0) and get the result directly.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•