Mouse & Keyboard controled camera

Started by
3 comments, last by Thunder_Hawk 18 years, 4 months ago
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
Advertisement
Check the tutorials on gametutorials.com and ultimategameprogramming.com

edit: yeah, vector math and gluLookAt would do the job
-----"Master! Apprentice! Heartborne, 7th Seeker Warrior! Disciple! In me the Wishmaster..." Wishmaster - Nightwish
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).


Ahh! Gametutorials is payware!! :(

It used to be free
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.
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________

This topic is closed to new replies.

Advertisement