I’m using the code from the sdk tutorial for mouse picking but it’s not working.
Vector2f click2d = app.getInputManager().getCursorPosition();
Vector3f click3d = app.getCamera().getWorldCoordinates(
new Vector2f(click2d.x, click2d.y), 0f).clone();
Vector3f dir = app.getCamera().getWorldCoordinates(
new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d).normalizeLocal();
ray = new Ray(click3d, dir);
gameManager.collision.collideWith(ray, results);
This always returns zero results. However it works fine if I use the camera direction for the ray like in a first person shooter.
ray = new Ray(gameManager.cameraManager.camera.getLocation(), gameManager.cameraManager.camera.getDirection());
What am I doing wrong here ?
Disregard , something was bugged in the SDK. I restarted it and it worked fine.
pspeed
June 5, 2016, 12:48am
3
Note: Lemur has mouse picking built into it and it works in 3D or 2D… with any JME Spatial. Could be easier in the long run depending on what you will do with it.
Example here:
Lemur has a robust picking subsystem that uses JME’s standard ray collision code. In this Lemur Gem, I add simple mouse picking to the app already built in Lemur Gem #1 and Lemur Gem #2
When you initialize Lemur’s GuiGlobals, it automatically adds the MouseAppState that does scene picking. It also adds the guiNode and rootNode to the pickable scene roots automatically. This demo uses that automatic setup. It is also possible to use the MouseAppState without the rest of Lemur but for simplic…
Isn’t Lemur’s just for GUI picking ? I’m picking spatials from my scene.
No… as I said directly already:
pspeed:
it works in 3D
pspeed:
with any JME Spatial
More to the point, you could simply click on the Lemur Gems 3 and see that it is being used to pick 3D objects in a scene.
…but maybe never mind.