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

First PErson

Started by frupert Jul 5, 2004 at 12:27 AM 4 replies 700+ views
Original Post
frupert
frupert
I am making a game that uses first person point of view iOpenGL is there away that I can make the view turn(like when you press left or right arrow) without turning the whole scene like what is done in NeHe's tutorial, I was thinking maybe I could use glLookAt()
fRuPeRt
kburkhart84
kburkhart84
That works perfectly. The problem is that you have to use vectors, and a little trig to figure out the parameters to pass. You must take the player position vector and and to it the vector to wherever he is looking. This vector is found out with trig same as moving. The Up vector parameter in this case probably would be(0,1,0). If you want it third person, you still have to use some trig to position the camera. You have to calculate the angle to find the position of the camera in 3d, but the Up is still the same, and the pointTo vector for the function is the player's position.


RipTorn
RipTorn
use a matrix to represent the player, and load it as the 'camera'..

have a read here, it's a thread in the nehe forum that deals with a problem that really isn't all that disimilar to what your asking (it may sound different but in essense it's the same) - both problems boil down to the need to represent the position and rotation of objects in an accurate and convienient way (Easily the best being a matrix)...

You need to represent the position of your player with a matrix, so you know the position and rotation of the player. That way you can use this information to your advantage, for first person view this would simply be to load the matrix as a camera (load the inverse of the matrix before you do any rendering)...

[edit]

Ok.

on thinking about this, while I feel a matrix is still the best bet it may not be all that intuative to use in this case, since a matrix is more suited to free-form movement than rigid movement of a FPS (limit how far up you can look, etc)...

sorry about that.
kburkhart84
kburkhart84
I do agree that this method works. I just don't like using matrices when OGL already has the matrix stuff done for you. My camera class has a strange technique that actually works. You can use the normal Rotate, Translate functions to position the camera, the call gluLookAt to set it right. This code does it for me.
glRotatef(-pitch, 1, 0, 0);
glRotatef(-yaw, 0, 1, 0);
glRotatef(-roll, 0, 0, 1);
glTranslatef(-Position.x, -Position.y, -Position.z);
gluLookAt(0, 0, 0, 0, 0, -1, 0, 1, 0);

The problem is that like Euler angles, you can run into gimble lock. The solution is to use another method outside, like a quaternion to keep track of the rotations, then grab from the quaternion the euler angles relative to the original axis, no matter how they got to the rotations they are at, they can still be turned into Euler angles. Then use those Euler angles in the camera class(the code above) and the camera will work fine.


kburkhart84
kburkhart84
This camera does basicly what mine does, except that mine takes into account the third degree or rotation, you just have to avoid gimble lock yourself.


Topic Locked

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

Sign in to reply to this topic.