C++ projection direction, gluLookAt and etc.

Hey I had a few guestions relating to opengl projection and such things. I new to opengl, but not programming. I have had 4 years of beginner game making (using none other than Game Maker), so I understand tons of concepts but few commands and codes. I currently have a very simple 3d engine going for me here in opengl and I could use some help fixing and improving it.

Question 1: I have a gluPerspective projection set up and I have been messing around with gluLookAt to try to get the camera to turn. First is this the right way to add movement to a project camera. Second how could I setup a complete 360 turn for the projection.

Question 2: Ok after I have a successful camera setup how would I go at getting the camera to move around the world. I am talking about true camera movement and not glTranslate because all that does is move the world around the camera and I can’t have that.

Ah thats about it for now. If you need me to post any codes of mine to help just let me know. Thanks alot.

  1. In my experience, the best way to implement a moving camera is to keep track of 6 variables. The camera center’s x,y and z position and its yaw,pitch and roll. With each keyboard press or mouse movement you can update the necessary parameters. Then, within the main rendering loop, you construct the 4x4 camera matrix based on those 6 parameters and set it as the projection matrix.

And a 360 turn? That means you’re making one full turn and end up where you started…

  1. Everything is relative, ask Einstein :slight_smile: If you scale your world by two and increase your camera movement step size by the same amount you will get exactly the same result. If you move the camera 10 units to the left or you move the world 10 units to the right, you will get the same results. The way you want to implement it is entirely up to you, but I guess you’re looking for the method where you go from object coordinates to world coordinates in a first step and then go from world coordinates to eye space in the next step before applying the projection matrix.

Yes thats exactly what I mean.

Ok I understand what you are saying at first with the 6 variables. But my question is after I have these variables how do I set them to have any change on the camera projection. The second half I don’t understand as well about the camera matrix.

For the second answer; so moving the camera is possible? I currently have a simple move moving around the camera thing, but I see some problems with the concept of it. I was just wondering if its possible to move the camera where I would look into; any commands or codes?

Oh and if it matters I am using GLUT to render the window for me.

This is what I currently have for a simple direction code ( it doesn’t work very well…):


glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     
     gluLookAt(cord_x,cord_y+5,cord_z,yaw,pitch,0.0,0.0,1.0,0.0);

//drawing scene

Wait looking back I think I figured something out. Can I move the camera using gluLookAt. In my code about I put variable for coordinates but forgot about them. Could I just use these variables to move the camera around?