Sign in to follow this  

fps camera trouble

This topic is 2851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi there, This is my problem. If I rotate the camera to the right and then move the z axe of the camera forwards, the camera not goes forward but everthing goes left. can someone please help me. this is the code that is use
void GL_Camera(){
	glRotatef(CAM_angle_x*10,0,1,0);
	glRotatef(CAM_angle_y*10,1,0,0);
	glTranslatef(CAM_x,CAM_y,CAM_z);
	return;
}

Share this post


Link to post
Share on other sites
You are misunderstanding the use of the glRotate/glTranslate functions.

These functions do not control "the camera" like you think they do. Technically there is no such thing as a camera in opengl. The viewport is always located in eye space at (0,0,0).

When you use glTranslate, you are affecting the position of any object that is drawn after that translate call. If you glTranslate(1,0,0), then draw a box it will be drawn 1 unit to the right of the coordinates you specify. Note that this appears to the user like you have moved the camera 1 unit to the left, as now the camera is left of the box by one unit. The same applies to glRotate, it does not rotate the camera, but rather rotates the world.

To achieve the illusion of a camera, you must transform the scene by the inverse of the camera's transform.

A full-blown explanation is a lot more in depth than I have time for at the moment, but you have a lot more reading to do about understanding the basics of 3D graphics. I suggest you pick up a book from page 1 and start reading, or find some beginner tutorials to explain some basics.

Share this post


Link to post
Share on other sites

This topic is 2851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this