Jump to content
  • Advertisement
Sign in to follow this  
wangxu

How can i use the directinput mouse device to get the absolute coordination?

This topic is 2499 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 search the web and found that people say i can do like that:

define global var g_x,g_y;


hr = g_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &dims2 );

g_x+=dims2.lX;
g_y+=dims2.lY;

the g_x,g_y are the absolute value;but i just can`t absolute value from that,for example,at the begining of my program,the g_x,g_y are 100,100 on a "special point",after i moved the mouse for a while,and move back to the "special point",the coordination will not be 100,100,it changed a lot!!why??how can i get the absolute coordination??just the getcursorpos??
thx!!!!!

Share this post


Link to post
Share on other sites
Advertisement
Hi,

AFAIK, you cannot retrieve absoule mouse coordinates via DInput. It gives you relative coordinates (i.e. deltaX and deltaY values, which are the subtraction between previous frame's screen coordinates and the current one's).

GetCursorPos() is enough for this task.

hth.
-R

Share this post


Link to post
Share on other sites
Hidden
You actually can get the absolute mouse coordinates. All you have to do is get the mouse coordinates at the beginning, then always keep track of them.

Share this post


Link to post
You can't get the cursor position directly with direct input (but you could do it by keeping track of the mouse position, although the coordinates will not be in pixels), but what i usually do to get the mouse pos, is use GetCursorPos() like programci said, which gets the cursor position in pixels on your monitor, then call ScreenToClient() which translates the coordinates from the screen to your client window

a problem about keeping track with direct input, is the coords will probably be off (different than the cursor) after you move the mouse to the edge of the screen. the cursor will stay at the edge of the screen even while your are still moving the mouse, and direct input will keep changing the coords. directinput does not take the cursor into consideration, only the actual mouse.

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!