Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectInput Mouse Absolute Coordinate

Started by bagghin Feb 25, 2003 at 9:50 AM 5 replies 1.2k views
Original Post
bagghin
bagghin
I am writing a DInput Wrapper Class that included a functions that the mouse can return the absolute coordinate (X and Y), so what did i do is just Set the axis mode of the mousedevice to Absolute and then reacquire it again, and after GetDeviceState I found that the mouseState coordiante reterieved is not an absolute coordinate, it was some random number, so is there any method to retrieve the absolute coordinate according to the screen resolution? e.g. the centre point of a 1024*768 screen is (512,384) Thanks for your attention!! :>
  

// Set the Axis to Absolute Mode

DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = DIPROPAXISMODE_ABS;
m_pDirectInputMouseDevice->SetProperty(DIPROP_AXISMODE, &dipdw.diph); 

// Acquire the mouse device

m_pDirectInputMouseDevice->Acquire();

// update the current device states, if DIERR_INPUTLOST returned, acquire again

if(m_pDirectInputMouseDevice->GetDeviceState(sizeof(m_MouseState),(LPVOID)&m_MouseState) == DIERR_INPUTLOST)
{
   m_pDirectInputMouseDevice->Acquire();
}

// m_MouseState.lX = Absolute X Coordinate?

// m_MouseState.lY = Absolute Y Coordinate?



  
Rain Down..Rain Down..Come on rain down on me..
DarkPixel
DarkPixel
There's a very simple way. First create all DirectInput stuff
normally without the DIPROPAXISMODE_ABS and dipdw fancy stuff!
And then keep track in your class of two members:
D3DXVECTOR3 m_RelCoord; // Relative coords
D3DXVECTOR3 m_AbsCoord; // Absolute coords

and update them this way :

m_RelCoord.x = mousestate.lX;
m_RelCoord.y = mousestate.lY;
m_RelCoord.z = mousestate.lZ;
m_AbsCoord.x += mousestate.lX;
m_AbsCoord.y += mousestate.lY;
m_AbsCoord.z += mousestate.lZ;

The absolute coords will be given relative to the point (0,0)
whatever resolution you are using !!!

Much simpler hein ?








There is no problem, only solutions...



[edited by - DarkPixel on February 25, 2003 11:10:42 AM]

There is no problem, only solutions...
bagghin
bagghin
Thanks DarkPixel :>

yeah, i have tried that method,
but somehow it needed to initialise the position of m_AbsCoord.x and m_AbsCoord.y, right? it should be the absolute coordinate of the mouse cursor when we acquired the device..

so how could we get that absolute coordinate in the first place?
Rain Down..Rain Down..Come on rain down on me..
bagghin
bagghin
well, by the way,
my cursor is the WNDCLASSEX one,
not the one drawn by myself ;>
Rain Down..Rain Down..Come on rain down on me..
DarkPixel
DarkPixel
You can initialise it as you want. If you want the absolute
coods to be given relative to the point (0,0) you initialise
it to (0,0). DirectInput returns relative coords, right ? These
coords are relative to an unknown origin. When you move to the
right, the relative coords are +certain_amount_of_units on the
x-axis. So if you have your abs coords initialised to (0,0),
when you move the mouse to the right, your absolute coords will
be certain_amount_of_units from the point (0,0) to the right !

I've said that DI gives the coords given relative to an
unknown origin. All you do is to specify the origin !

Just tell me if you don't understand my complicated logic !




There is no problem, only solutions...



[edited by - DarkPixel on February 25, 2003 2:52:39 PM]

There is no problem, only solutions...
bagghin
bagghin
yeah, i got what u mean.
but somehow u need to draw the cursor onto the screen in (0,0) in the first place (D3D stuff),

but i am using the WNDCLASSEX cursor, so the initial cursor coordinate doesn''t really controlled by me. so should i disable this cursor and draw my own cursor instead?

or are there still any other methods to handle the initial coordinates of the WNDCLASSEX cursor?

Thanks thanks. :>
Rain Down..Rain Down..Come on rain down on me..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.