FPS Camera headaches...

Started by
9 comments, last by Zakwayda 19 years, 6 months ago
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
My game development blog: http://rykerlabs.com
Advertisement
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?
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
My game development blog: http://rykerlabs.com
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...
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.
My game development blog: http://rykerlabs.com
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...
---------------------------------------------think outside the quadLogic GamesI realized I stay on the pc too long when my wireless mouse died after replacing the batteries...twice
Wouldn't you use a different matrix to the camera matrix to move? Otherwise if you look up and press forwards you can fly! Doesn't help you fix it I'm afraid though, sorry!
I hardly know what the camera matrix is, can someone please explain that to me?
My game development blog: http://rykerlabs.com
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
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.

This topic is closed to new replies.

Advertisement