Custom mouselook with JOGL

Hi!

I need to modify the way of handling the mouse moves in TUER as many people find it slow. TUER is a (tiny) First Person Shooter. In order to center the cursor when it is near an edge of the screen, I use an instance of java.awt.Robot. The problem is that I assumed that when you call robot.mouseMove(x,y), it generates a single event…but that’s not the case, it’s incremental, it may generate 3 events if required, it may even generate the required event when I expect that it has already been done. Is it possible to reduce this delay? bobjob told me that he doesn’t have this problem in his FPS but he uses LWJGL and then JInput, he said that has helped him. Does JOGL contain something that might help me?

How can I do to reliably center the cursor and avoid mixing events coming from the robot and events coming from the player? I want to call getSource() on the event when MouseListener.mouseMoved(MouseEvent me) is called and then treat each event type differently. Has someone already had this problem? How did you solve it? If I only do nothing when the robot generates an event, is it enough?

My source code can be freely downloaded (watch the URL below) and the class that uses Robot is “main.GameMouseMotionController”.

P.S: I use JOGL but I don’t “troll” people using JPCT or LWJGL. I have used JOGL for my game since the start, I don’t want to “waste” some time in changing of OpenGL binding even though LWJGL is more than only an OpenGL binding.

Hi

no

simple move the mouse in the mouse motion event handler to the screen center.

if(mouse centered)
robot triggered event -> ignore
else
user triggered event -> do something useful with it

…or use jinput

Ignoring robot triggered is not enough but I’m close to the aim thanks to you.

You never have to ignore the Robot! (if you use screen-coordinates)


public Point getDelta(Window window)
{
   Rectangle r = window.getBounds();
   int xCenter = r.x + r.width/2;
   int yCenter = r.y + r.height/2;

   Point pointer = MouseInfo.getPointerInfo().getLocation();
   int xPointer = pointer.x;
   int yPointer = pointer.y;

   int xDelta = xPointer - xCenter;
   int yDelta = yPointer - yCenter;

   if(xDelta == 0 && yDelta == 0) 
     return new Point(0,0); // robot caused this OR user did not do anything

   robot.moveTo(xCenter, yCenter);

   return new Point(xDelta, yDelta);
}

I wrote this code without compiling nor checking whether this idea actually works.

Give it a try.

You’re right because if I totally ignore the robot, the computed shift between the old and the new position is false.

It works perfectly. Thank you very very very very very much, I’m really grateful and very happy! I’m falling asleep. You’re really an expert! It is so simple and no need of JInput!!

No prob!

I used the approach proposed by bienator a few years ago, then switched from JOGL to LWJGL and used Mouse.setGrabbed(…) ever after. I can only say that because of the unpredictability of the MouseEvents, it’s kinda guessing which MouseEvent came from the Robot and which from the User (even the OS doesn’t know…) so it was a bit jerky and AFAIK didn’t work on Linux for some reason.

All those problems vanish with this idea I just came up with, and I thank you for testing it and proving it actually works.

just to restore my honor :stuck_out_tongue: my awt fallback code looks almost identical to your. I tried to answer his question this way because I interpreted it like he asked additionally to the mouse view question how to separate user events from robot events.