Drakemor's picture

Mouse Capture: Wrapping mouse

Hi.

I've downloaded latest SVN and got GameWindow.CursorVisible property.

I hide the cursor and read the XDelta value from Mouse.Move event. Problem is: when i touch the edge of the window (even when my cursor is invisible) I don't get any more XDelta going that direction.

I'm unable to change Mouse.X position to wrap it around the screen (read only) and didn't found any other property to turn wrapping on.

Anyone can help?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
openecho's picture

Hey Drakemor,

I just posted about the exact same thing. I have had a crack at setting the position back to the middle when I hit the edge. I have a custom game window with my own game loop external to OpenTK but a similar method should work by listening the GameWindow.Mouse.Move event and checking the coordinates and doing a wrap.

Let me know if you find a nicer way to do it. My method works great on linux but is slow to wrap on OSX.

Anyway, here is the link with my code http://www.opentk.com/node/2260.

Regards,

John

the Fiddler's picture

Use OpenTK.Input.Mouse instead, which is not confined to the window/display.

Drakemor's picture

@the Fiddler: I am using OpenTK.Input.Mouse, and that's what I'm referring to in first post.

the Fiddler's picture

OpenTK.Input.Mouse does not have XDelta/YDelta properties. It only offers X/Y, which are not confined to the window (you don't need to warp the mouse cursor, they are infinite).

The GameWindow.Mouse.Move events are confined to the window by design.

Drakemor's picture

I see. I have mistaken. I'll look them up. Thanks.

Drakemor's picture

I see. I have mistaken. I'll look them up. Thanks.

openecho's picture

Cool.

I will switch my code to the standard method as well and see how it goes. Might have more luck now I am on the development branch.

Regards,

John

openecho's picture

@the Fiddler

I am on OSX 10.6.6 and I am using the current source forge svn code I compiled last night.

I set the game window to hold the mouse with,

window.CursorVisible = false;

I am reading the Mouse.Move event as you suggest just by listening to it in a standard way.

window.Mouse.Move += new EventHandler<OpenTK.Input.MouseMoveEventArgs> (OnMouseMoveHandler);

and in my listener method,

protected void OnMouseMoveHandler (object sender, OpenTK.Input.MouseMoveEventArgs e)
{
	Console.WriteLine(string.Format("X:{0} Y:{1} XD:{2} YD:{3}", e.X, e.Y, e.XDelta, e.YDelta));
}

The delta's I get are *not* limitless. I get values till I hit the size of the windows and then it stops. I need to reset it to the center when it gets to the edge of the window to use it.

I am not sure if I am missing something or if its not finished? This is one step away from using as the mouse input for a first person control.

Thanks for the great work, I was digging through the native window code for X11 and OSX and I appreciate the quantity of work in OpenTK.

John

As a side note, I had to add,

<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL" />

To get the current trunk to work on OSX. I notice that the current download does not need it. I am not sure what the difference is, but now it works great.

the Fiddler's picture

That's by design: GameWindow.Mouse.Move events are confined to the window.

For infinite coordinates, you need to use OpenTK.Input.Mouse.GetState(). From the documentation:

using OpenTK.Input;
 
MouseState current, previous;
 
void UpdateMouse()
{
    current = Mouse.GetState();
    if (current != previous)
    {
        // Mouse state has changed
        int xdelta = current.X - previous.X;
        int ydelta = current.Y - previous.Y;
        int zdelta = current.Wheel - previous.Wheel;
    }
    previous = current;
}