Jump to content
  • Advertisement
Sign in to follow this  
ivandotnet

OpenGL Mouse Look in OpenGL

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

I am trying to implement Mouse Look like those u get in First Person Shooters. I am trying to use the following to implement it: void MouseMotionCallBack(int x, int y) { xrot = (windowwidth/2 - x) * (-1)/10; gluLookAt(0.0, 0.0, 5.0, xrot, 0.0, 0.0, 0.0, 1.0, 0.0); glutPostRedisplay(); } so that the gluLookAt reference will move in the x-direction according to xrot. However, whenever i click and move my mouse, the object which i draw in render() dissapears. Can anyone tell me how to implement Mouse Look correctly? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
right now your only changing the x term of the "lookat" vector, your gonna want to make a basic camera setup with position, lookat, and up vec. What your trying to do is rotate about the up axis in your case (left to right)

so start by positioning (0, 0, 5),
setting your look at (0, 0, -4)
and your up (0, 1, 0)

then each frame calc your dir vec (were to point)
dir vec = look at - position
Normalize(dir vec) (make it length of one)

now this dir vec is what you want to rotate (left or right) by the scaled down amount that the mouse moved (the smaller the better to start, not too small, this will act as your angle)now you can rotate this dir vector any number of ways, quternions make this rather quick and painless, there are other ways, bottom line you have to do some math. once you have the new rotated dir vec

look at = position + new dir

then feed these pos, lookat and up into glulookat each frame. Look up how to rotate vectors about an axis if you dont know how.

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!