MouseInput on OSX has an offset

Hello everybody.

I have a small problem here, the image below shows my current small project. The numerated rectangles are made with jme, they are drag’n’dropable and clickable. Everything works nice on my windows machine.

Tomorrow i need to make a small prototype presentation to see if my idea gets approved. For the presentation i have borrowed my sisters macbook. At first try everything seems to work. Beside the gui responds a little slow. Thats however not a problem.

The big problem is that the mouse position has an offset. If i would like to click on the rectange 5, i have to click on the area marked in red.

What could possible cause the problem on osx?



http://i.imgur.com/NRh49.png



http://i.imgur.com/NRh49.png



My selection code if fairly simple:

[java]

if (name.equals(“MoveWiese”)) {

if (keyPressed) {

CollisionResults results = new CollisionResults();

Vector2f click2d = app3d.getInputManager().getCursorPosition();

Vector3f click3d = new Vector3f(app3d.getInputManager().getCursorPosition().x, app3d.getInputManager().getCursorPosition().y, -1000);

Vector3f dir = Vector3f.UNIT_Z;

Ray ray = new Ray(click3d, dir);

app3d.getGuiNode().collideWith(ray, results);

if (results.size() > 0) {

currentMoveSelection = results.getClosestCollision().getGeometry().getParent();

currentMoveSelectionOffset = results.getClosestCollision().getContactPoint().clone().subtractLocal(currentMoveSelection.getWorldTranslation());

System.out.println(“Selection:” + currentMoveSelectionOffset.x + “:” + currentMoveSelectionOffset.y);

}

} else {

if(currentMoveSelection!=null){

((ZFarmerWiesenVisualisierer3dPluginWiesenControl) currentMoveSelection.getControl(ZFarmerWiesenVisualisierer3dPluginWiesenControl.class)).storeData();

}

currentMoveSelection = null;

}

}

[/java]

btw, i have bootcamp’d the macbook and the code works fine on windows. After the presentation tomorrow i will try to reproduce the issue in a testcase. Btw, i am running java 1.6 and a two week old nightly

Good luck with the presentation :slight_smile:

Presentation went pretty good :wink: Approved for the next level…



BTW, here is the testcase, on windows the box is aligned to the mouse cursor, and on mac the box has quite a bit offset…

Could someone please try it, just to see if its a common problem, or a problem with my machine…

[java]

package mygame;



import com.jme3.app.Application;

import com.jme3.app.SimpleApplication;

import com.jme3.app.state.AbstractAppState;

import com.jme3.app.state.AppStateManager;

import com.jme3.material.Material;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.system.AppSettings;

import com.jme3.system.JmeCanvasContext;

import com.jme3.texture.Texture;

import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.Frame;

import javax.swing.JFrame;

import javax.swing.JPanel;



/**

  • test
  • @author normenhansen

    */

    public class Main extends SimpleApplication {



    JFrame frame;

    // JPanel contentPanel=new JPanel();

    JPanel panel3d = new JPanel();

    JmeCanvasContext gfx_context;



    public static void main(String[] args) {

    Main app = new Main();



    app.startGui();

    app.start3d();

    }



    public void start3d() {

    panel3d.setLayout(new BorderLayout());

    AppSettings custom3dSettings = new AppSettings(true);

    custom3dSettings.setUseInput(true);

    custom3dSettings.setWidth(640);

    custom3dSettings.setHeight(480);

    this.setPauseOnLostFocus(false);

    this.setSettings(custom3dSettings);

    this.createCanvas();

    gfx_context = (JmeCanvasContext) this.getContext();

    gfx_context.setSystemListener(this);

    gfx_context.setSettings(custom3dSettings);

    panel3d.add(gfx_context.getCanvas(), BorderLayout.CENTER);

    }



    public void startGui() {

    java.awt.EventQueue.invokeLater(new Runnable() {



    public void run() {



    frame = new JFrame();

    frame.setExtendedState(Frame.MAXIMIZED_BOTH);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setLayout(new BorderLayout());

    frame.add(panel3d, BorderLayout.CENTER);



    JPanel upperPanel = new JPanel();

    Dimension upperPanelSize = new Dimension(200, 200);

    upperPanel.setSize(upperPanelSize);

    upperPanel.setPreferredSize(upperPanelSize);

    frame.add(upperPanel, BorderLayout.NORTH);



    JPanel rightPanel = new JPanel();

    Dimension rightPanelSize = new Dimension(200, 200);

    rightPanel.setSize(rightPanelSize);

    rightPanel.setPreferredSize(rightPanelSize);

    frame.add(rightPanel, BorderLayout.EAST);

    frame.setVisible(true);

    }

    });

    }



    @Override

    public void simpleInitApp() {

    this.inputManager.setCursorVisible(false);

    this.stateManager.attach(new MouseInput());

    }



    public class MouseInput extends AbstractAppState {



    Geometry geo;

    private SimpleApplication app;



    @Override

    public void initialize(AppStateManager stateManager, Application app) {

    super.initialize(stateManager, app);

    this.app = (SimpleApplication) app;

    Box boxshape1 = new Box(Vector3f.ZERO, 10f, 10f, 10f);

    geo = new Geometry("A Textured Box", boxshape1);

    Material mat_tex = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    geo.setMaterial(mat_tex);

    this.app.getGuiNode().attachChild(geo);

    }



    @Override

    public void update(float tpf) {

    geo.setLocalTranslation(app.getInputManager().getCursorPosition().x,app.getInputManager().getCursorPosition().y,1f);

    }

    }

    }



    [/java]

@Normen: I can confirm it works fine (Win7). Can you test this on your MacBook?

Idk, its super-strange with the canvas not showing 50% of the time. I’d say you should use AwtPanels for stuff like this, the canvas just isn’t flexible enough to mix it with swing/awt. Or you make the GUI in Nifty which would then again be more platform compatible.

@normen said:
Idk, its super-strange with the canvas not showing 50% of the time. I'd say you should use AwtPanels for stuff like this, the canvas just isn't flexible enough to mix it with swing/awt. Or you make the GUI in Nifty which would then again be more platform compatible.

But the canvas works in jMP on Mac? Then what is he doing wrong that jMP isn't doing?
@normen said:
Idk, its super-strange with the canvas not showing 50% of the time. I'd say you should use AwtPanels for stuff like this, the canvas just isn't flexible enough to mix it with swing/awt. Or you make the GUI in Nifty which would then again be more platform compatible.


Actually the canvas not showing problem i think its a refresh problem of the gui. I do not have the problem with my program on mac. The only issue i have is that the inputmanager has wrong mousecursor coordinates...

Is the white box in synch with the cursor on your mac? Of course if the canvas shows up...

No its not but the threading of the app doesn’t seem right, you do swing stuff on the main thread (not on the EDT).

@normen said:
No its not but the threading of the app doesn't seem right, you do swing stuff on the main thread (not on the EDT).


Thats true, this could be the issue of the canvas not showing up sometimes. In my application i have the threading correct and the canvas shows up correctly. The mouse issue is still present. I have to do further testing, to track down the issue. Wired behaviour anyway...

InputManager.getCursorPosition() pretty much equals the mouse coordinates we get from LWJGL by using their Mouse class. I can only think of the issue being on the LWJGL side…