Jump to content
  • Advertisement
Sign in to follow this  
Beaverbutt8

OpenGL Mouse & Keyboard controled camera

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

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

Share this post


Link to post
Share on other sites
Advertisement
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).

Share this post


Link to post
Share on other sites
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.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!