Sign in to follow this  
disanti

FPS Camera headaches...

Recommended Posts

Hello, I've been programming my own simple 3d engine with OpenGL and this is the first time I have ever made a FPS camera... Anyway, I made a camera class, the mouse movement works fine but the arrow movement is completely screwed. I've tried using code from gametutorials.com's camera tutorials and it makes it worse, I'm so confused right now that I feel like giving up but I can't do that, I've worked too hard on this engine (made a 3ds max exporter, made a model importer, scene script parser, model code, etc...) If someone could lend me a helping hand, that would be great. Right now my view target is getting a very weird value: Camera Position: 0.000000, 0.000000, 0.000000 Camera Target: -107374176.000000, -107374176.000000, -107374176.000000 If you would like me to post the camera code here I can do that, but it is big. Thanks~ John DiSanti

Share this post


Link to post
Share on other sites
Probably need a little more info to help, but for movement keep in mind that you'll need the world x, y and z axis of your camera. These can be extracted from the camera matrix or camera matrix transpose - typically they'll be the rows or columns of the 3x3 portion of the matrix.

What does your camera do when you move? For example, when you move forward does it move along the world z axis instead of the camera z axis?

Share this post


Link to post
Share on other sites
Ok, when using gluLookAt(...) the camera doesn't move at all. When I use glRotatef(...), the mouse rotation works. When I use glRotatef(...) to rotate the view, I also use glTranslatef(...) afterwards to position the camera. When I press the UP key, the camera will move forward, but if I rotate the camera and press the UP key, it will continue in the old direction not the new one. It is really hard to explain because I've never made one of these before! :S
The camera code is really messy right now because I have mixed so much non-working code from so many tutorials. Tomorrow, if I have time, I will try reprogramming the camera class but I'm very doubtful that will do me anygood.
Thanks~ John DiSanti

Share this post


Link to post
Share on other sites
Maybe you could just post the part of the code where you move. It sounds like you're moving along the world axes instead of the camera axes...

Share this post


Link to post
Share on other sites
Alrighty, here goes:

void pss4_camera::fps_MoveCamera()
{
pss4_vector3f vector = *target - *position;
vector = pss4_Normalize(vector);

position->x += vector.x * speed; // Add the acceleration to the position's X
position->z += vector.z * speed; // Add the acceleration to the position's Z
target->x += vector.x * speed; // Add the acceleration to the target's X
target->z += vector.z * speed; // Add the acceleration to the target's Z
}




Used to be a lot different before I saw any tutorials! ;)

Edit: I should mention that speed is a private member and is set to 1.2f at the start of the game.

Share this post


Link to post
Share on other sites
If you want to strafe (sp?), turn ur camera 90 deg. move forward one space, then rotate back to the way u were facing, this will give the effect that u moved sideways. Sounds like useless info but youd be surprised how long it took me to figure that out...

Share this post


Link to post
Share on other sites
Quote:
Original post by SilverLogic
If you want to strafe (sp?), turn ur camera 90 deg. move forward one space, then rotate back to the way u were facing, this will give the effect that u moved sideways. Sounds like useless info but youd be surprised how long it took me to figure that out...


I've just started learning 3D graphics programming, but for strafing, instead of rotating the camera 90 degrees, moving forward one space, then rotating back 90 degrees, why couldn't you just move all the vertices to the left or right by plugging them in a camera matrix which contains the amount to strafe by along the x axis? Why do you need to rotate? It kind of seems redundant to me.

Thanks,
Taylor Eagy

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Razorpro
Quote:
Original post by SilverLogic
If you want to strafe (sp?), turn ur camera 90 deg. move forward one space, then rotate back to the way u were facing, this will give the effect that u moved sideways. Sounds like useless info but youd be surprised how long it took me to figure that out...


I've just started learning 3D graphics programming, but for strafing, instead of rotating the camera 90 degrees, moving forward one space, then rotating back 90 degrees, why couldn't you just move all the vertices to the left or right by plugging them in a camera matrix which contains the amount to strafe by along the x axis? Why do you need to rotate? It kind of seems redundant to me.

Thanks,
Taylor Eagy


Well you should really just get a vector 90 degrees clockwise or anti-clockwise to your direction vector (use cross product) then translate using this. you cant just move along x,y,z as strafing is relative to your direction.

Share this post


Link to post
Share on other sites
There are certainly ways you could hack strafing into your current camera code. But if you're serious about 3d programming, at some point you'll want to do it right. For that you'll need to get caught up on linear algebra, matrices, etc.

There are many references on the subject (including several here on gamedev). One good one is '3D Math Primer'.

What would be ideal would be to learn about 3x3 rotation matrices, and use one to represent the orientation of your camera. The strafe, up and forward axes can be extracted from this matrix and used for movement. Also, the matrix itself can be converted into OpenGL format and submitted via glMultMatrix().

I won't lie to you - there's a lot of ground to cover to get a functional math library working, including such issues as handedness, row or column vectors, row- or column-major matrices, using quaternions, etc. But it's worth it.

Meanwhile, like the AP said, the normalized cross product of your forward vector and your up vector (if you have access to it) is your strafe vector.

Anyway, I hope some of that helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this