Object picking

Is there any way to pick and object, I mean, to have a list of all objects rendered in a part of the screen. I need the ability to select objects with the mouse and I have no idea how to do that with jME3.



Thank you.



P.S.: In the meanwhile, some way to keep trak of the mouse location?

Look into this tutorial https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_picking. To cast rays from arbitrary positions on the screen (This is not done in that tutorial, it always shoots rays from the center) you have to implement one RawInputListener and add it to the Application (in its inputManager). In the RawInputListener implementation create two fields x and y and in the onMouseMotionEvent set them to be the current x and y of the cursor (get it from the MouseMotionEvent instance given as parameter) then in the onMouseButtonEvent cast rays from the [x,y] position. Look here to see how to use Camera.getWorldCoordinates to build the ray in world space.

2 Likes