Mouse & Keyboard controled camera
Hey Guys,
How can i program i camera in opengl ( im using c++, compiler dev c++ ) so that it's view is controlled by the camera, and it's movement by the keys.
For example, in an FPS game ( which i am developing )
I move the mouse to the right, and the camera view turns to the right. Then, when i press the up or down key, i go forward or backward in that direction.
I suspect that there are is some vector math involved here.
Thanks :)
MIke
Check the tutorials on gametutorials.com and ultimategameprogramming.com
edit: yeah, vector math and gluLookAt would do the job
edit: yeah, vector math and gluLookAt would do the job
Quote:
I suspect that there are is some vector math involved here.
Yup, but it's not too bad. You will need sin and cos along the way more than likely. For the FPS style game, I would just use gluLookAt() function and store within your camera class the LookAt vector and the position vector. The mouse needs to rotate the lookat vector and the position needs to be changed according to the lookat to make it easier. Use trigonometry to rotate the lookat when you move the mouse, then when you move forward, just add the position and lookat vectors multiplying by a value dependant on how fast you want ot move and the time passed since last frame(at least for time based movement).
Check out this tutorial on a quaterion camera on NeHe's site.
This code uses quaternions so it might not be the best if you're trying to learn how to make your first camera class. However, if you simply are looking to get the job done, then this code could be easily modified for your purposes.
This code uses quaternions so it might not be the best if you're trying to learn how to make your first camera class. However, if you simply are looking to get the job done, then this code could be easily modified for your purposes.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement