Archived

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

hammerstein_02

DirectInput Mouse Movement

Recommended Posts

Hello, I have just ventured into the world of DirectInput, as I am creating a system of buttons and want to keep track of the mouse.. In the examples I have looked at, the code simply adds the IDx and y variables to the current xMouse, yMouse position vars. But if I use this method.. (setting the xMouse, yMouse to half my screen width/height respectively) I get negative numbers before I even approach my onscreen graphics. Any suggestions as to what I am missing, what I am doing wrong? =*= If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore =*=

Share this post


Link to post
Share on other sites
Are you looking at the Windows cursor or one you are drawing yourself? If it''s the Windows cursor, get rid of it and draw your own, the Windows cursor moves differently.



I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm

Share this post


Link to post
Share on other sites
If I read your problem correct, you should not initialize to the middle of the screen, but to your cursor position. (GetCursorPos)
idX and idY are relative values to your last mouse position and not the cursor position by default.
Do you get negative numbers for the sum of the id''s and mouse positions or just the id''s?

Share this post


Link to post
Share on other sites
I was recently doing something similar and gave up on the DirectInput X/Y and just used the winAPI stuff, and ScreentoClient()....

makes more sense that way as u get all the mouse speed etc from control panel so it doesn''t feel weird to user. Mine is a window app.. spose in diff resolutions it could cause funny results.

Share this post


Link to post
Share on other sites
In my application I get the mouse data like so..

where diMouse is a DIMOUSESTATE structure..


  
App->GetMouseData(diMouse);

xMousePos += diMouse.lX;
yMousePos += diMouse.lY;


the GetMouseData is a member of my cDXWrap class like so


  
bool cDXWrap::GetMouseData(DIMOUSESTATE &mousedata)
{
if(lpMouse->GetDeviceState(sizeof(DIMOUSESTATE),(LPVOID)&mousedata) != DI_OK)
{
try
{
lpMouse->Acquire();

lpMouse->GetDeviceState(sizeof(DIMOUSESTATE),(LPVOID)&mousedata);
}
catch(...)
{
return(false);
}
}

return(true);
}


This has been driving me crazy allllll weekend. And I know the answer is really simple. Please ignore my over the top approach to catching losing the mouse. I was just experimenting. I can''t understand why the coords I get to start with change so drastically.. please help me..



=*=
If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore

=*=

Share this post


Link to post
Share on other sites
The problem is more a problem with concept. DirectInput gives you the Mouse''s low-level data, and not the higher-level Windows cursor data.

What you are getting is the amount of movement which the mouse has made either since the last frame, or since the app started (depending on how you configured DirectInput).

If you want cursor co-ordinates for a Windowed app then DirectInput is not really designed for you - all this functionality is available through the Win32 API. If you do want to know about the mouse has moved, and draw any cursors, etc. yourself then DirectInput is a very efficient way of getting this information.

You have to think of the Windows cursor and your directinput cursor (if you draw one) as two seperate entities - as they are. It is helpful to ''switch off'' the Windows cursor when your app gets focus, and things should all be a little less confusing.

Cheers,
John

Share this post


Link to post
Share on other sites