Mouse Picking without cursor

Is there some way to use the built in mouse picking mechanics from lemur without using a cursor? Which means I always want to pick in the center, in camera direction.

Sort of maybe… it’s not quite as pretty as I’d like maybe.

The only reason Lemur isn’t processing mouse input when the cursor is inactive is because you’ve disabled it by calling GuiGlobals (lemur 1.14.0 API)

If you leave that set to true and disable the mouse cursor on JME’s InputManager then Lemur will still try to process the mouse… which JME is now constantly resetting to the middle of the screen as I recall.

That should work in theory.

Alternately, all of the logic of picking is actually done with the PickEventSession class. MouseAppState is really just a dumb pass-through for this that polls it regularly.

You could set up your own (create it and add just your 3D scene root to it) for doing fly-cam style crosshair picking. Just call:
http://jmonkeyengine-contributions.github.io/Lemur/javadoc/Lemur/com/simsilica/lemur/event/PickEventSession.html#cursorMoved(int,%20int)
with the center location once per frame and:
http://jmonkeyengine-contributions.github.io/Lemur/javadoc/Lemur/com/simsilica/lemur/event/PickEventSession.html#buttonEvent(int,%20int,%20int,%20boolean)

for button events.

The first approach I suggested is the easiest… you’ll just have to make sure to manage the cursor visibility state carefully if you re-enable for UI picking… and note that the gui node will get picked too even though the cursor is disabled but you shouldn’t have anything clickable in the center of the screen then anyway.

The second approach is probably the ‘right way’ and can be easily managed with your own app state that can be enabled/disabled… because you’d want to disable yours if you ever re-enabled Lemur’s. You could take a look at MouseAppState to get an idea of how to write one. You’d just be passing a different position instead of grabbing the cursor position.

2 Likes

I guess that solves your problem
https://wiki.jmonkeyengine.org/doku.php/jme3:beginner:hello_picking
no?

No. This is in the Lemur category because he wants to use Lemur picking which already has listeners, state management, etc… it’s WAAAAAY beyond anything you’d get manually doing picking.

I already tried that. I checked the cursor position and it is not reset to the center of the screen every frame.
The thing is, it doesn’t even work with the cursor enabled. I changed the log level to trace, and it says that the direction for the scene ray is [nan, nan, nan].

I already had look at these classes, but as it doesn’t work with the cursor enabled, I have to solve that problem first

You mean with the GuiGlobals.setCursorEnabled(true)? Yeah, definitely have to solve that first as it should work just fine.

Can you provide more information like the actual logs and such? Also, your camera setup and so on. Sounds like maybe there is a funny camera somewhere or your main scene has an unexpected setup or something.

Well I did some testing, and it turns out that if I set the near plane of the camera to 0.01 and the far plane to 1000000 mouse picking stops working, with smaller values it works.

Yeah, those values will mess up rendering also as they probably screwed up the camera matrix.

Edit: and would certainly hose a normal z-buffer

1 Like

Ah thats where this flickering came from…

1 Like