Java AWT Move mouse automatically without triggering MouseMotionListener

I'm making a game with JOGL. I made a GLJPanel, and got everything set up. However, I have trouble with the camera rotation. Here's my mouse listener:
panel3D.addMouseMotionListener(new MouseMotionAdapter() {
final int[] pos = new int[]{panel3D.getLocationOnScreen().x + panel3D.getWidth() / 2, panel3D.getLocationOnScreen().y + panel3D.getHeight() / 2};

@Override
public void mouseMoved(MouseEvent e) {
panel3D.rot[0] += e.getX() - pos[0];
panel3D.rot[1] += e.getY() - pos[1];
pos[0] = e.getX();
pos[1] = e.getY();

panel3D.rot[1] %= 90;

try {
Point point = panel3D.getLocationOnScreen();
new Robot().mouseMove(point.x + panel3D.getWidth() / 2, point.y + panel3D.getHeight() / 2);
} catch (AWTException ex) {
throw new RuntimeException(ex);
}
}
});
panel3D.addMouseMotionListener(new MouseMotionAdapter() {
final int[] pos = new int[]{panel3D.getLocationOnScreen().x + panel3D.getWidth() / 2, panel3D.getLocationOnScreen().y + panel3D.getHeight() / 2};

@Override
public void mouseMoved(MouseEvent e) {
panel3D.rot[0] += e.getX() - pos[0];
panel3D.rot[1] += e.getY() - pos[1];
pos[0] = e.getX();
pos[1] = e.getY();

panel3D.rot[1] %= 90;

try {
Point point = panel3D.getLocationOnScreen();
new Robot().mouseMove(point.x + panel3D.getWidth() / 2, point.y + panel3D.getHeight() / 2);
} catch (AWTException ex) {
throw new RuntimeException(ex);
}
}
});
As you can see, it should work fine. However, the Robot class re-calls this MML with inverted mouse X and Y, so the camera just snaps back with the mouse. Is there a way to fix this?
7 Replies
JavaBot
JavaBot10mo ago
This post has been reserved for your question.
Hey @The Typhothanian! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
The Typhothanian
The TyphothanianOP10mo ago
nope tried that
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
The Typhothanian
The TyphothanianOP10mo ago
hmm That would work thank you
JavaBot
JavaBot10mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot10mo ago
Post Closed
This post has been closed by <@801145088830210129>.
Want results from more Discord servers?
Add your server