Sign in to follow this  

First person camera

This topic is 1905 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

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
[CODE]
glTranslatef(x, y, z);
[/CODE]
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:
[CODE]
glTranslatef(position.x, position.y, position.z);
[/CODE]

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
[CODE]
glLoadIdentity();
[/CODE]
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.

Share this post


Link to post
Share on other sites
Yes, you have to reset the matrix to identity before applying a new transformation, otherwise, you're applying the same operation over and over.

Share this post


Link to post
Share on other sites
[quote name='Faelenor' timestamp='1351617215' post='4995486']
Yes, you have to reset the matrix to identity before applying a new transformation, otherwise, you're applying the same operation over and over.
[/quote]
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?

Share this post


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