Sign in to follow this  

How to read mouse motion

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

Hi, I'm making a 3D first person shooter. Simply, I need to know how to handle input from the mouse. From what I understand the clicking of the mouse keys isn't a problem to handle (handled the same way as keyboard input with VK_MOUSER or something like that). On the other hand, I don't know how to read the "motion" of the mouse. If I knew how to get the data, I'm sure it'd be fairly simple for me to figure out how to convert it into an appropriate amount of rotation in the game. (Windows of course, and I'm working in Visual Studio 6.0). I'm assuming it'll e handled somewhere in the WndProc function, if that's what it was called, where the other inputs are handled in NeHe's tutorials.

Share this post


Link to post
Share on other sites
The event WM_MOUSEMOVE is what you are looking for. I believe LOWORD and HIWORD provide the coords that you need.

Alternatively, check out DirectInput. With this, you will get more accurate and easier to achieve input message.

Share this post


Link to post
Share on other sites
K, I guess I can use that.

Just wondering, is there no OpenGL thing to handle this? I'm guessing no...

Since I'm a bit short on time, anybody got instructions on quickly converting mouse movement to rotation?

I'm guessing I store the previous coordinates and then the "velocity" of the mouse is considered a tangent to the line of sight. If I set a certain radius, where the mouse is "virtually" located in front of the camera, i can calculate the angular velocity and with that get the rotation. Is that right?



More importantly, since this will be a first person shooter, will this work with mouse motion? I mean, will the mouse be able to leave the client window? If so, how do I stop it from doing this?

Share this post


Link to post
Share on other sites
Quote:
Original post by SilencedViolence
Just wondering, is there no OpenGL thing to handle this? I'm guessing no...


no. OpenGL is a graphics API.

Quote:
Original post by SilencedViolence
Since I'm a bit short on time, anybody got instructions on quickly converting mouse movement to rotation?


[google]: Nehe OpenGL tutorial.

Quote:
Original post by SilencedViolence
More importantly, since this will be a first person shooter, will this work with mouse motion? I mean, will the mouse be able to leave the client window? If so, how do I stop it from doing this?


Each frame you read the new coordinate, calculate the delta, and then move the mouse back to the center of the screen. Search http://msdn.microsoft.com for the appropriate functions and such.

-me

Share this post


Link to post
Share on other sites
Heh thanks guys... in the end I'm just using the arrow keys to pitch and yaw since the deadline is today and half of the collision functions are still bugged.

But, I will use this in further versions of the game, and it really means a lot to me, so thanks again.

Share this post


Link to post
Share on other sites

This topic is 4213 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this