Detect Mouse Movement Manually

What’s the best way to detect mouse movement (up, down, left, right) manually?

Mouse clicks are are easy because they are tied to a button, but what is the handle for detecting if a person move their mouse to the left or to the right (up or down)?

I’m already getting some code ideas, but was wondering if P3D provides away for detecting this already.

Panda provides only the raw mouse position information each frame. You’ll have to write the code to determine the gestures yourself.

David

Can you modify the default mouse behavior? For instance, stopping the right click from zooming in/out, stopping the middle click from allowing world rotation and last, invert the mouse movement?

That’s the behavior implemented by Panda’s Trackball object. You can turn that off (with base.disableMouse()), and then implement the behavior you want yourself.

David

I’ve been concentrating on getting the screen to rotate when the mouse is moved left or right, like in first person shooter games. I have succeeded in doing this, however…

I just can’t seem to stop the “jittery” look on rotations. When taking long rotations, this bad effect isn’t noticed; just on the shorter rotations.

My camera is updating after all movement has been calculated. I know that does play a role in it. Also, my rotation is placed against the globalClock.getDt().

You would think rotation would be liquid smooth… IDK. It’s worst when my actor Node is doing a strife movement and I start to rotate.

self.Pobj.setH(self.Pobj.getH()+float(Perc)*globalClock.getDt())

—Additional-------------

Normal rotation not using the mouse position is fine, so I’m wondering if there’s some form of time offset when accessing mouse pos info, which causes movement/rotation sync to break ingame?

Alright, so a few days ago I implemented this mouse rotation you’re talking about. Firstly, as was said, you have to turn the default mouse behavior off:

base.disableMouse()

Then, what I do is create a task - read more on them in the manual. The task is called every frame and the code goes like this:

if base.mouseWatcherNode.hasMouse(): # always check if the mouse is inside the window
      deltaX = base.mouseWatcherNode.getMouseX()  # mouse distance from the center
      deltaY = base.mouseWatcherNode.getMouseY()
      self.rotationHorizontal += -1 * self.mouseSensitivity * deltaX
      self.rotationVertical += self.mouseSensitivity * deltaY
      camera.setHpr(self.rotationHorizontal,self.rotationVertical,0)

# move the cursor to the center of the window
base.win.movePointer(0,base.win.getProperties().getXSize()/2,base.win.getProperties().getYSize()/2)

The mouse cursor always stays in the center of the screen so you can rotate infinitely. In each frame you check how far from the center of the window the mouse has moved, you rotate the camera and move the mouse to the center again. There may be some optimizations done in the code, like keeping the degrees in 0-360 range and so on. You may also want to hide your cursor:

props = WindowProperties()
props.setCursorHidden(True)
base.win.requestProperties(props)

Hope this helps.

I took a closer look at things and it seems the world does not “pop” when just rotating the camera standing still. It’s when movement is involved, specially a strife movement while going around in a circular motion.

It really looks like a redraw issue to be honest. It appears as if the graphics card is straining to draw the frames but the fps is 60, so that’s not the case.

This is weird stuff…

I ran the old game far cry, which has a similar mouse control and sure enough… That same old “jitter” was there while doing a moving rotation and manipulating the mouse.

I guess high detail graphics kind of hide that effect, which could be the reason I never noticed it before. I am assuming it’s something down in the graphics pipeline on the gc side of things.

Colleagues of mine gave me a suggestion; slow down the strife movement along with the camera rotation speeds.

That suggestion worked because things look a lot better now during movement. Good deal, because developing a commercial title with horrid camera motion is an instant fail. :smiley:

Work mates also taught me how to bake high detail with Blender instead of doing it from stratch. I didn’t even think that kind of thing was possible in Blender, but more power to me, all the same. I’m already loving the SM guys. :laughing:

A quick addition, if I may: you should be able to make mouse positions relative by default by setting the “mouse mode” to “relative” when you request your window properties. With this set, you should be able to omit the code that moves the mouse cursor back to the screen’s centre.

Relevant code:

props = WindowProperties()
props.setMouseMode(WindowProperties.MRelative)
# Set any other properties that you may want, such as hiding the cursor
base.win.requestProperties(props)