Jump to content
  • Advertisement
Sign in to follow this  
tommy-t

fps camera trouble

This topic is 3156 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
Advertisement
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
If it is just a movement problem, you need to realize that drawing is not the same as updates.

You need to update your cameras position based on sin/cos of the angles used for your camera drawing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!