fps camera trouble

Started by
3 comments, last by dpadam450 14 years, 1 month ago
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;
}

Sorry for my bad english
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.

[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
which book do you recommend?
Sorry for my bad english
Quote:Original post by tommy-t
which book do you recommend?


The Red Book
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.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement