Help With Camera

Hey evebody, hi to all…
Need some help with “looking”…dont find in any tutorials…i want to understand this point, cause i want to program games… :slight_smile:
Lets supose that i have a character and i want a camera following him…I use gluLookAt() to point the camera behind it…
W - walk him forward…z+= 0.1f;
S - walk him backward…z-=0.1f;

now i want the A and D keys to turn left and right (angle)…
so lets supose that i turn 90º to left…now i want to press W to walk forward…but it walk for other side… weird…

maybe because this…
translate3f(x, y, z);

help me how to fix that, or some tutorial explained well the camera concept…
I think gluLookAt could be the best way…or am i wrong??

Hi Kampos!

I don’t know a lot about this, but I’ll see if I can help you a little.

I don’t have your code, but let me see if I understand you correctly. At the moment you can walk straight forwards and backwards fine. But if you rotate 90 degrees to the left and press W (forward), the camera continues to move like it did before you rotated the camera. AKA, you’re now strafing to the right?

The wall from the right come to me…I know why this happen…its because when i press W its sums Z += 0.1f…So the camera will go to Z axis. Maybe i need to calculate with sen and con but I never used these functions…and dont know where to put…Can you help??

Have you looked at tutorial sites like HeNe. They explain the basics of cameras and movement.
HeNe Camera Tutorial

I don’t know how NeHe goes about it, but it would also be helpful to understand Polar Coordinates.

Essentially you have all the information you need for polar coordinates right now. You have an angle, and r can just be 1 (this will make sense if you watch that video).

The big idea is that ultimately you need a “line of sight” vector to orient your camera correctly with gluLookAt, because part of the set of parameters is the definition of a 3D point you’re looking at. If you can obtain a vector defining the direction you’re looking, you can add the components of that vector to your camera’s current x, y, z location to get the point to look at.

Then, for motion, instead of updating your camera’s position just straight bye the Z axis, or any other axis, update it with the line of sight component for each axis. This way you’re moving in the direction you’re currently facing, not just flat along an axis.

I hope this combined with the links you have makes it clear! If not, ask more questions. :slight_smile: