Windows MRelative problem

Hi,

In my code I use MRelative mode for mouselook, in order to avoid reseting the mouse to the screen center every frame. On Linux, when I enable this mouse mode the mouse never leaves the window, which is exactly what I need and expect. However, on Windows that’s no the case. The cursor seems unaffected by the setting. It leaves the window and moves normally, exactly the same way as MAbsolute.

It’s same code, so my question is: is it some difference between how MRelative is supposed to work on each of these systems, or is it a bug?

Here’s the code I use for mouselook.

def enableMouseLook(self):
    props = WindowProperties()
    props.setMouseMode(WindowProperties.MRelative)
    props.setCursorHidden(True)
		
    mouse = base.win.getPointer(0)
    self.mousePrevX = mouse.getX()
    self.mousePrevY = mouse.getY()
		
    base.win.requestProperties(props)

def updateMouse(self):
    mouse = base.win.getPointer(0)
    x = mouse.getX() - self.mousePrevX
    y = mouse.getY() - self.mousePrevY
			
    h = x * (8.0 / 45.0)
    base.cam.setH(base.cam.getH() - h)
    
    p = y * (1.2 / 4.5)
    p = base.cam.getP() - p
    if p < 90.0 and p > -90.0:
        base.cam.setP(p)
    
    self.mousePrevX = mouse.getX()
    self.mousePrevY = mouse.getY()

I’m not sure if we support MRelative on Windows. However, that’s not such a big deal because I think Windows remembers the sub-pixel offset when you move the cursor.

It does. The movement is smooth.

However, there’s actually more then just the mouselook. Although, it would be swell if I could use the same code for that under Windows and Linux.

The other reason I’m asking for this requires more explaining, so I didn’t want to elaborate in the first post. I’ve made a system for, let’s call it, interactive surfaces, which is basically something like the virtual screens in Doom3. It allows me to display functional DirectGUI as a texture on any surface in a 3D scene (I intend to release this code as a snippet soon).

To make it functional I use the normal base.mouseWatcherNode, and thus the normal mouse, to move the virtual cursor on the texture. The thing is, when the mouse is used to move the cursor on a virtual screen I naturally don’t want the real cursor to leave the game window.

Obviously, that’s no problem in fullscreen mode, but I want to support windowed mode as well (even if only for the sake of development). And reseting the mouse position to the screen center is just not an option here, or it would require a lot more voodoo involving the VirtualMouse (which, as far as I know, is not nearly as precise as the normal MouseAndKeyboard thing).

MRelative on Linux solves this problem and saves me headaches, so a way to use that (or achieve the same result) under Windows would be really cool. In fact, it would just be cool if this stuff worked the same way on every platform, to always give expected and coherent results. If possible, obviously.

Still, if there is another way to constrain the cursor to the window I’d be happy to know it (I know this is generally not advised, but this is a special case).

I think you’ll have to go the route that involves a lot more voodoo. I don’t know of any other general solution at the moment.

David

Thanks for clearing that for me. I guess I’ll just stick to fullscreen for Windows for now and get to the voodoo some time in the future.

Still, would there be chance for a behavior similar to Linux’s MRelative to be implemented for Windows?

Maybe we could set up a fallback MRelative for systems that don’t really support it, that internally just repositions the mouse every frame?

Sounds reasonable. I’d kind of like to have a higher-level Panda implementation of this kind of support, but maybe just emulating MRelative across all platforms is good enough.

David