Sign in to follow this  

IDirectInput - Absolute coords mishap?

This topic is 3310 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, [* Please forgive me for the long post *] I don't wish to make this complicated, but I promise all my tests show that the following variables are not good for computing absolute screen coordinates: dims2.lX (or .lY for vertical movement), I have read many threads on this and all keep saying that they use it for correct absolute coords computation, but I am failing to see how it can possibly work.. Here is my setup: - mouse.cpp (VC8 sln from DirectX SDK) - select NONEXCL, FOREGROUND, IMMEDIATE (mouse format is c_dfDIMouse2) In the code, try this:
...
int absx=-777;
INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
...
POINT pt;
pt.x = 0;
pt.y = 0;
ClientToScreen(hDlg, &pt);
SetCursorPos(pt.x, pt.y);
absx = pt.x;
if( FAILED( OnCreateDevice( hDlg ) ) )
...

And replace the following lines:
// The dims structure now has the state of the mouse, so 
// display mouse coordinates (x, y, z) and buttons.
//StringCchPrintf( strNewText, 128, TEXT("(X=% 3.3d, Y=% 3.3d, Z=% 3.3d) B0=%c B1=%c B2=%c B3=%c B4=%c B5=%c B6=%c B7=%c"),
//                     dims2.lX, dims2.lY, dims2.lZ,
//                    (dims2.rgbButtons[0] & 0x80) ? '1' : '0',
...

With:
// The dims structure now has the state of the mouse, so 
// display mouse coordinates (x, y, z) and buttons.
absx = absx + dims2.lX;
StringCchPrintf( strNewText, 128, TEXT("#%d#"), absx);

When you compile and run it you will see that you will never get back to the original absolute screen coord where the mouse starts at 358). Can someone try it and let me know if I AM doing anything wrong ?... (In this sample, I am logging the X coordinate) dims2.lX is a mickey value, we know that, maybe this should be first converted to a pixel coord value before it is added? If so, what's the proper way to this conversion ? Many thanks and sorry for the long post

Share this post


Link to post
Share on other sites
Going a little off topic, but Using DirectInput for keyboard or mouse input is a terrible idea and will just cause you headaches (Like this), and break your app on some machines (Although that's more a keyboard thing rather than a mouse thing).

Back on topic; You can't get absolute mouse coordinates in any way that I'm aware of - DirectInput doesn't work with pixels, it works in mickeys, so it has no concept of where "zero" is.

Share this post


Link to post
Share on other sites

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