directinput -- mouse position?

Started by
2 comments, last by jimiwa 19 years, 10 months ago
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?
Advertisement
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]
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
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
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.

This topic is closed to new replies.

Advertisement