Skip to content

Loading…

MouseState position is relative to cursor position on start #1

Closed
jhauberg opened this Issue · 3 comments

2 participants

@jhauberg

I have a problem where the position of the cursor has its origin ( 0, 0) set to where ever the cursor happens to be on the screen ( the entire screen) when i run my windowed subclass of GameWindow. I was expecting it to have its origin be at either the top-left or lower-left corner of the window.

All I do with the mouse is this, in a typical update loop:

MouseState ms = Mouse.GetState();

System.Diagnostics.Debug.WriteLine(
    String.Format("{0}, {1}", ms.X, ms.Y));

This is happening on Windows 8. I have not tested on OSX.

@andykorth
Owner

I believe this is intended behavior by the original author:

"OpenTK.Input.Mouse, which provides low-level access to mouse motions. It is independent of windows/displays and provides raw (i.e. non-accelerated) values, if possible. Use this for games that require mouse motions not confined to the display, for instance first-person shooters and 3d games with mouse-controlled cameras."

Instead, if you want absolute (instead of delta) coordinates relative to the screen... I think instead you want this:

"GameWindow.Mouse* events, which are equivalent to WinForms/WPF/GTK# mouse events. The values are accelerated by the OS and are reported in window coordinates. Use this for menu/UI navigation and games that require absolute coordinates, for instance and 2d games."

From: http://www.opentk.com/doc/input

(Additionally, OpenTK.Input.Mouse x and y values aren't adjusted by your mouse acceleration curve, and at least on OS X, they don't even come close to corresponding with the screen. Numbers returned as deltas aren't close to pixels)

@andykorth andykorth closed this
@jhauberg

Wow, my bad. I should learn to read! It totally works as I wanted when using GameWindow.Mouse. Thanks for pointing this out!

@andykorth
Owner

No problem, it's quite unclear, I think it should be made more clear that Mouse.GetState().X are actually deltas.

I actually updated the wiki page a little bit to make it more clear a few days ago.. still easy to miss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.