Jump to content
Sign in to follow this  
  • entries
    73
  • comments
    131
  • views
    55046

DirectInput and absolute coordinates .

Sign in to follow this  
okonomiyaki

356 views

So it looks like the people who don't like DirectInput say that's it's stupid because it can't do absolute positioning.

Though I'm not going to judge a whole API because of that one feature... it really should do it better.

It does have absolute positioning, but the relative coordinate is basically out of this country from the size of the numbers I'm seeing. The whole point of absolute coordinates is that they are relative to the topleft corner of the window! Or at least some part of the window. I want to know exactly where the cursor is over the window by having the (0,0) point at the topleft corner of the rendering screen. Not the topleft corner of the window. Not some random point across the country.

Apparently this is a lot harder with Windows and DirectInput than I thought. This was so simple in SDL. If I use DirectInput, I just can't get absolute coordinates relative to the top left corner of the window. If I use Windows' cursor functions, I can finally get it but it tends to include the border in its calculations, and I'm not confident that it works in all situations (cursor going outside the window screwing it up, etc?).

This is my final function to get relative and absolute coordinates. If anyone knows of a better way, please tell me!


AXResult AXTaskInput::_UpdateMouseState() {
HRESULT hr;

_LastMouseState = _MouseState;
hr = _DXMouse->GetDeviceState(sizeof(DIMOUSESTATE), (void*)&_MouseState);

if(FAILED(hr)) {
AXAppLog->Write(MESSAGE_SYS, "Failed getting device state (mouse): %s", DXGetErrorString9(hr));
AXAppLog->Write(MESSAGE_SYS, "Attempting to re-acquire.");

hr = _DXMouse->Acquire();
while(hr == DIERR_INPUTLOST)
hr = _DXMouse->Acquire();

if(FAILED(hr)) {
AXAppLog->Write(MESSAGE_SYS, "Failed to re-acquire device (mouse): %s", DXGetErrorString9(hr));
return AXFAILURE;
}
else {
AXAppLog->Write(MESSAGE_SYS, "Successfully re-acquired device (mouse)!");
_DXMouse->GetDeviceState(sizeof(DIMOUSESTATE), (void*)&_MouseState);
}
}

MousedX = _MouseState.lX;
MousedY = _MouseState.lY;

// Do some funky Windows stuff to figure out the position of the cursor
POINT p;
GetCursorPos(&p);
ScreenToClient(AXWindow::Instance().GetHWND(), &p);

MouseX = p.x;
MouseY = p.y;

AXAppLog->Write(MESSAGE_APP, "MousedX: %d MousedY: %d", MousedX, MousedY);
AXAppLog->Write(MESSAGE_APP, "MouseX: %d MouseY: %d", MouseX, MouseY);

return AXSUCCESS;
}

Sign in to follow this  


2 Comments


Recommended Comments

Simple, I looked at the source of the page and overrode some of the CSS styles.

This is exactly what I put in the header of my journal:


<style type="text/css">
.head {background-color: #208090}
.headsmall {background-color: #208090}
.postcell {background-color: #006677}
.altforumcell {background-color: #004455}
.forumcell {background-color: #223339}
</style>


Thought I'd make it a little different [grin]

Share this comment


Link to comment

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
  • 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!