Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


directinput -- mouse position?

This topic is 5270 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 got the book Beginning Direct X 9 and for directinput with the mouse it only tells how to find out how far the mouse has moved. For my program, I need to know what position the mouse is at. Can someone tell me how to do this?

Share this post

Link to post
Share on other sites
It depends whether you use your own mouse pointer or whether you use the Windows one. If you use the Windows one you simply call an appropiate API function (though I'm too lazy to help you with that I'm sure someone else can). If you have your own mouse pointer you should store its position in vector screen coordinates, and then update it every frame by adding the movement vector from Direct Input (preferably you first multiply it by some user-definable scalar to allow the user to set the mouse sensitivity).

[edited by - Unwise owl on June 10, 2004 9:55:39 AM]

Share this post

Link to post
Share on other sites
You can do it multiple ways:

(1) Check for the WM_MOUSEMOVE windows message. It will give you the mouse coordinates in lparam. This would be good because you only have to update when the user moves their mouse.

(2) Use GetMouseMovePointsEx() to get the last whatever number of points the mouse was at

(3) Simply track the position with DirectInput by adding the position every frame

Method #1 is probably the easiest way to go.

Dustin Franklin
Mircrosoft DirectX MVP

Share this post

Link to post
Share on other sites
That is pretty simple:

Direct Input tell''s you the "Delta" move. So if dxinput returns (0,0), your mouse has not moved, if it says (-5,0) your mouse moved 5 pixels to the left, if it says (0,7) it went 7 pixels down and so on. What you have to do is:

int iMouseX = ScreenWidth/2, iMouseY = ScreenHeight / 2;

... Get your dx info and then:

iMouseX += dx;
iMoyseY += dy;

if you have a 640x480 screen your mouse will start at 320x240. When you move it 5 pixels to the left, the dx will be -5, and dy = 0:

iMouseX += dx -> 320 += -5 ->315

So it goes.

Share this post

Link to post
Share on other sites

  • 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!