Made another test.
I suspect it is the input cursor is not right.
The guiViewPort resolution is doubled, while the input cursor not. When use a Ray(cursor.x, cursor.y, -1) will get false results.
Here is the test code.
import com.jme3.app.FlyCamAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.input.event.MouseMotionEvent;
import com.jme3.material.Material;
import com.jme3.material.Materials;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Quad;
import com.jme3.system.AppSettings;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.event.*;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class CheckerDemo extends SimpleApplication {
static int WIDTH = 1280;
static int HEIGHT = 720;
static int SIZE = 80;// (1280, 720) = 80 * (16, 9)
public static void main(String[] args) {
AppSettings settings = new AppSettings(true);
settings.setResolution(WIDTH, HEIGHT);
settings.setResizable(true);
CheckerDemo app = new CheckerDemo();
app.setSettings(settings);
app.setShowSettings(false);
app.start();
}
@Override
public void simpleInitApp() {
GuiGlobals.initialize(this);
// stateManager.getState(MouseAppState.class);
stateManager.detach(stateManager.getState(FlyCamAppState.class));
// guiNode.scale(2f);//hard code to suite the retina screen
// create 16*9 quads as a checkerboard.
Mesh mesh = new Quad(SIZE, SIZE);
for (int y=0; y<9; y++) {
for (int x=0; x<16; x++) {
ColorRGBA color;
if ((x + y) % 2 == 0) {
color = new ColorRGBA(1f - x / 16f, y / 9f, 1f, 1f);
} else {
color = new ColorRGBA(x / 16f, 1f - y / 9f, 1f, 1f);
}
Material mat = new Material(assetManager, Materials.UNSHADED);
mat.setColor("Color", color);
Geometry geom = new Geometry("#("+x+","+y+")", mesh);
geom.setMaterial(mat);
geom.move(x * SIZE * 2f, y * SIZE * 2f, 0);
geom.scale(2f);
guiNode.attachChild(geom);
MouseEventControl.addListenersToSpatial(geom, new DefaultMouseListener() {
@Override
protected void click( MouseButtonEvent event, Spatial target, Spatial capture ) {
Vector2f cursor = inputManager.getCursorPosition();
System.out.printf("geom:%s, cursor:%s, cam:%s\n", target.getName(), cursor, guiViewPort.getCamera());
}
@Override
public void mouseEntered(MouseMotionEvent event, Spatial target, Spatial capture ) {
Material m = ((Geometry)target).getMaterial();
m.setColor("Color", ColorRGBA.Yellow);
}
@Override
public void mouseExited( MouseMotionEvent event, Spatial target, Spatial capture ) {
Material m = ((Geometry)target).getMaterial();
m.setColor("Color", color);
}
});
}
}
}
}
Console output
geom:#(6,2), cursor:(1111.0, 346.0), cam:Camera[location=(0.0, 0.0, 0.0)
, direction=(0.0, 0.0, 1.0)
res=2560x1440, parallel=true
near=1.0, far=2.0]
I turned PickEventSession.debug on, here is the lemur debug log:
16:10:49.972 [jME3 Main] DEBUG c.s.l.e.PickEventSession:156 - cursorMoved(1111, 346, scroll=0) capture:null
16:10:49.973 [jME3 Main] DEBUG c.s.l.e.PickEventSession:156 - getPickRay(RootEntry[viewport=com.jme3.renderer.ViewPort@4b86805d, root=Gui Node (Node), layer=gui], (1111.0, 346.0))
16:10:49.973 [jME3 Main] DEBUG c.s.l.e.PickEventSession:156 - Creating GuiBucket ray.
16:10:49.973 [jME3 Main] DEBUG c.s.l.e.PickEventSession:156 - Picking against:RootEntry[viewport=com.jme3.renderer.ViewPort@4b86805d, root=Gui Node (Node), layer=gui] with:Ray [Origin: (1111.0, 346.0, 1.0), Direction: (0.0, 0.0, -1.0)]
16:10:49.973 [jME3 Main] DEBUG c.s.l.e.PickEventSession:156 - Collision geometry:#(6,2) (Geometry)
16:10:49.973 [jME3 Main] DEBUG c.s.l.e.PickEventSession:156 - Hit:#(6,2) (Geometry)
Then I make it into rootNode.
cursor
geom:#(4,3), cursor:(1003.0, 524.0)