Skip to main content
GameDev.net gamedev.net
🔒 Locked

First person camera

Started by Slushy Oct 30, 2012 at 4:59 PM 1 replies 2.7k views
Original Post
Slushy
Slushy
Hello!
Im trying to create a first person camera, and I've been successful in understanding how to do so thus far. I've read up on alot of vector math and matrix stuff and I know the basics. Although I got a few problems when I try to implement it into my code.

I have 3 main vectors, which are position, direction and up. I am trying to use

glTranslatef(x, y, z);

to update my camera-position, but Im not a 100% sure on what values I want to update it with. If I keep updating with my position vector, like so:

glTranslatef(position.x, position.y, position.z);


I will keep moving in one direction, even if im not pressing any buttons. (Moving in the direction that the results of all three values in the position vector will be.) I've been able to work around this by using

glLoadIdentity();

In the main loop, before I do all the translating. Is this the correct way of doing it? Or do I add another vector and translate with that one? Im a bit of a perfectionst, and I want to do it correctly the first time. So I don't have to relearn!

Thanks! I hope im clear enough on what my problem is, I'll be happy to post my sourcecode if you really need it, I felt like it was a bit unnecessary though.
Faelenor
Faelenor
Yes, you have to reset the matrix to identity before applying a new transformation, otherwise, you're applying the same operation over and over.
Slushy
Slushy

Yes, you have to reset the matrix to identity before applying a new transformation, otherwise, you're applying the same operation over and over.

But I get the feeling that this isnt the most effective way of doing it? Since glLoadIdentity(); moves it back to the origin again. I have to move it back to the position I want it in every single frame. Shouldn't there be a way to only move the camera when I tell it to do so, with my WASD keys?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.