Capturing the Mouse

I was looking around, and I don’t see any obvious way to have Panda capture my mouse. I want to have mouse movements move the camera around, and I don’t want to have my mouse controlling a pointer.

It looks like I can hide the pointer, and use to keep it from getting out of the window, which should give me all I need, but this seems a lot more clunky than most of the features I’ve used thus far in panda. Is there a better way to do this?

Also, I’ve seen a GraphicsWindowInputDevice class mentioned in comments and it sounds like it might have what I want, but I can’t find the actual module to import for this.

donwload the Yet another Roaming ralph example here it has good codeing for this type of camera although this code is a little advanced and maybe had to understand some of it but there is alot of info in the posts! … light=yarr

Yet Another Roaming Ralph uses the method that I mentioned in my first post. If that’s the way to do this in panda, that’s fine.

Yes. The better (more stable, less hacky, less jitter) way to do it would be to put the mouse into MRelative mode and not reset the mouse anymore.
This doesn’t work well on every platform, though.
A unified mouselook system has been planned for a future release.

I’m confused by your MRelative comment, or maybe this just doesn’t work well on my platform (Dell Inspiron 1420 run Ubuntu Gutsy Gibbon with a GeForce 8 Series card… and completely outdated drivers).

Specifically, I don’t understand what you mean by “not reset the mouse anymore” When I set the mouse to MRelative, I still need to move it back to the center of the screen. It doesn’t appear to save me any work at all, aside from not needing to subtract out the screen center position. And the code is almost identical, so I don’t see how it’s less hacky or more stable. I still need to keep track of the actual window size to recenter the pointer, and now I also need to correct for the screensize when I move the mouse (since no matter how big the screen is or what the width/height ratio is, I get a (-1,1) position)

Both methods look just as jittery to me. I’m planning to try and fix the jitter by not parenting the camera directly to the NodePath that I’m rotating with the mouse. Instead I’ll parent it to another NodePath that will smoothly rotate to the position of the first NodePath over 1/20 a second.

Or am I misunderstanding you?

actually relative mouse mode should fixate the cursor in place and let panda recieve all movements

try this code. press F1 after start to reset the smiley.

import sys
from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", "win-size 500 500")
import direct.directbase.DirectStart
from direct.task import Task
from pandac.PandaModules import *

props = WindowProperties()
p = loader.loadModel("smiley")
camera.setPos(0, 0, 200)
base.oldx = 0
base.oldy = 0

def movepointer(task):
    md =
    x = md.getX()
    y = md.getY()
    if x != base.oldx or y != base.oldy:
        print -1 *(base.oldx - x), base.oldy - y
        p.setX(p, (-0.1 *(base.oldx - x)))
        p.setY(p, (base.oldy - y)*0.1)
    base.oldx = x
    base.oldy = y
    return Task.cont

taskMgr.add(movepointer, "foobar")
base.accept("f1", p.setPos, [0, 0, 0])
base.accept("escape", sys.exit)

it should hide the cursor and print the pointer position relative to last frame. and it should move the smiley around, of course. press F1 if you loose him

Actually, with relative mouse mode you can’t really talk about a ‘cursor’ anymore, as the mouse is really not on the screen anymore. Panda just receives relative mouse information from the driver then, meaning that you won’t lose the subpixel accuracy that is lost when resetting the mouse to the center.

Note that relative mouse mode on Linux is only supported in 1.7.0 (or the CVS head) and requires the X11 extension Xxf86dga to be installed.

I want to use mouse look even if mouse buttons are not pressed, how to achieve that?

I still want to be able to capture mouse click events.

Have you tried using the sample code above? It has nothing to do with mouse buttons, which will still come in through the normal channels.


Oh sorry, did not write one important detail, i want to prevent mouse from leaving window (first and third person camera).

If you’re on Linux, MRelative mouse mode should do the trick. If not, you just need to reposition the cursor to the center of the window (or any other place, but that’s the most natural) in every frame.

Yeah, that is what i am doing now, i just thought that there is a way to go around that hack :slight_smile:

Actually, I’m quite convinced that’s how most games do it :stuck_out_tongue:.