[Solved] How can I check if the GUI elements is not clicked?

I want to check if a lemur or other gui node is between the mouse pointer and landscape then do something.

using ray cast? and the gui node?
It’s not working:

// Convert screen click to 3d position
        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();
        // Aim the ray from the clicked spot forwards.
        Ray ray = new Ray(click3d, dir);
        // Reset results list.
        CollisionResults results = new CollisionResults();

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

    if (results.size() > 0) {

        Geometry guiSelectedGeo = results.getClosestCollision().getGeometry();

        if (guiSelectedGeo != null) {
            System.out.println("gui node name: " + tools.get_parent_node(guiSelectedGeo).getName());

            app.getRootNode().collideWith(ray, results);

            try {
                globalVars.click3d = results.getClosestCollision().getContactPoint();
                System.out.println("" + tools.get_parent_node(results.getClosestCollision().getGeometry()).getName());
                run_for_multislected(globalVars.click3d.x, globalVars.click3d.z);
            } catch (Exception e) {
                globalVars.click3d = null;
            }
        }
    }

You are using a world space array to collide with the screen. The screen is in 2D space where the pixel coordinate is a screen coordinate. So to collide with the screen just make a ray from the screen coordinate with negative Z. new Ray(new Vector3f(click2d.x, click2.y, 1000), new Vector3f(0, 0, -1)) or whatever.

But here’s where I ask what you are really trying to do… because Lemur’s built in scene picking stuff will already hit the GUI first.

3 Likes

I dived into this thread just for this

1 Like

I used a controller to check vehicle selection, when a vehicle selected then move it by another click on the landscape by choose a target pos.
what was the problem? a selected vehicle has a gui option and some buttons on it, when it was selected the gui options shown, clicking on gui moves the vehicle too…

But for example, you could add a CursorListener to your terrain and get the clicks that way. Then if the UI is in front it will get the click first.

I don’t know if it’s practical for your scene but it would have solved the problem already.

2 Likes