[SOLVED] How to get screen coordinates of the button in container

Hi,

if i call the getLocalTranslation() method for a Container which is attached guiNode by attachChild() method, it returns (95.62, 691.2, 0.0) and it is true (even i dont know why y.axis grows from down to up, lemur did not must to normalize it?)

anyway if i call the getLocalTranslation() method for a button which is contained, it returns (0,0,0).

edit: button contained by addChild() method just as shown.

How i get contained stuff’s coordinates.

Thanks for be interested.

The answer is ***.getBackground().getGuiControl().getSpatial().getWorldTranslation();

***: your Lemur object.

Blind shot: getWorldTranslation and understand the differences between local and world Coordinate space

i try already this and it returns local translation of container.

I am new here so this might not be of any use. Is your button positioned at the origin of the container?

Then it is at 0,0,0 relative to the parent.

Did you call it before or after the layout has a chance to run?

What are you trying to use this value for?

This is how to click on something, get the thing’s coordinates and see what you clicked on.

		public void onAnalog(String action, float value, int modifier, float tpf){
			float intensity = value;
			//System.out.println("InputState.onAnalog()" + " (action=" + action + ", value=" + value + ", modifier=" + modifier + ", tpf=" + tpf + ")");
			if (action.equals(MAPPING_ROTATE)){
                //System.out.println("onAnalog-mapping_rotate");
				if (camera != null){
					CollisionResults results = new CollisionResults();
                    Vector2f click2d;
                    click2d = inputManager.getCursorPosition();
                    Vector3f click3d = camera.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 0f);
                    Vector3f dir = camera.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 1f);
					Ray ray = new Ray(click3d, dir);
					rootNode.collideWith(ray, results);
                    if (results.size() > 0){
                        Geometry target = results.getClosestCollision().getGeometry();
                        System.out.println("InputState.onAnalog()" + ", target=" + target + ", target's parent=" + target.getParent());
                    }
				}//if cam
			}//end mapping rotate
		}
    };

Is this what you want? Otherwise it’s:

> rootNode
> \Sun (0, 0, 0)- local coordinates and world coordinates are the same
>  \ Earth (150,000,000 km, 0, 0) around Sun; Earth local coordinate = (150,000,000 km, 0, 0), Earth world coordinate = Sun plus Earth = (150,000,000 km, 0, 0)
>   \moon (385,000 km, 0, 0): Moon local coordinates - (385,000, 0, 0), Moon world coordinates (150,385,000, 0, 0)

Not in Lemur… it’s way easier than that.

You just register a CursorListener and you get all of the information you need.

I mean, your way works also but it’s not the best way for many things in Lemur… which is what the OP’s question is about.

Ok. Got it.

No, also whole inner buttons returns 0,0,0

I don’t quite understand what you mean here.

 // --- Main Menu | Start ----
        final Container mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.None)); 
        
        Container main_logoContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.None),
                new ElementId("blankContainer")); 
        mainContainer.addChild(main_logoContainer);
        guiResponsiver.to(main_logoContainer,"w:18%; h:30%; m:0;");
        
        Label main_logo = new Label("Logo");
        main_logoContainer.addChild(main_logo);
        guiResponsiver.to(main_logo,Condition.RELATIVE,"w:100%; h:100%; m:0;");
        
        Container main_buttonContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.None),
                new ElementId("blankContainer"));
        mainContainer.addChild(main_buttonContainer);
        guiResponsiver.to(main_buttonContainer,"w:18%; h:50%; m:0;");
        
        Button main_playButton = new Button(Localizer.getString("main_playButton"));
        main_buttonContainer.addChild(main_playButton);
        guiResponsiver.to(main_playButton,Condition.RELATIVE,"w:100%; h:20%; ");
        
        Button main_settingsButton = new Button(Localizer.getString("main_settingsButton"));
        main_buttonContainer.addChild(main_settingsButton);
        guiResponsiver.to(main_settingsButton,Condition.RELATIVE,"w:100%; h:20%; ");
        
        main_exitButton = new Button(Localizer.getString("main_exitButton"));
        main_buttonContainer.addChild(main_exitButton);
        guiResponsiver.to(main_exitButton,Condition.RELATIVE,"w:100%; h:20%; ");
        
        guiResponsiver.to(mainContainer,"l:7%; t:10%; b:10%;");
        guiNode.attachChild(mainContainer);

And here is result;

An advanced navigation system for my needs.

Just adding things to a container won’t lay them out. Once it’s displayed (updated) it will lay out its children or you can force it to happen.

Navigation for what? That doesn’t really answer the question.

There is already built in focus navigation you can use in Lemur. Anyway, relaying on the positions of buttons seems like a bad design to me since a variety of things you might want to do will change their position later.

Does focus navigation reach buttons which are contained by runtime new opened menus? I try it but i cannot reach my pop-up menu buttons. For example i control buttons of main menu via up and down keys buf if i create a new pop up menu like “yes or no” then i cannot reach these buttons via left and right buttons. Focus never pass from main menu container to pop up container. I guess I could not tell you well but you see I’m in a lot of trouble with this. :smiley:

I thought about this and I took measures accordingly. In fact everything is ready but i dont notice my button coordinates to my navigator class.

The default plug-ins to the focus management system may not handle this case but they are just defaults and you have the ability to plug in your own navigation that is as complicated as you like.

There is another thread about this. [RFC] BigBanana: mouseless navigation - #25 by Pesegato

…where I’ve discussed a different-but-similar situation with another user. Essentially, you can hook in and define on your own what focus traversal points to what and when… just by implementing some interfaces in some controls on your spatials/buttons/etc.

if i finish my own navigator class i dont have to plug in navigations because my navigator will collect whole buttons and navigable spatials in scene and calculate they transitions. Only i need notice the button coordinates to navigator.

It supposed to be a way to obtain that contained buttons coordinates correctly and you are the master :slight_smile:

Wait until the user asks to move to another component and then find out where they are… everything is guaranteed to by right at that point.

I mean, you can force your components to update early but then you are still left with problems if you move things later. Seems very fragile to me.

too bad you already rolled your own key navigation, focus management, etc… because that’s what Lemur already provided. You can move around with cursor, tab/shift-tab, joystick, etc… already wired up.

Also i create my inputOrganizer class based on your inputMapper. I can seperate axis negative and positive inputs at now and i can handle that trigger axis we talked about it. Sometimes I don’t find everything I need with details on user ready packages like your lemur. But that does not mean that Lemur is missing. Lemur is wonderful app and i I wanted it to be in jme core. I am not java developer in professionaly in fact i am molecular biologist. But i love games, java and jme3 (i used unity before and i prefer jme in all matters). So i can better understand your works, jme3 and even java by customizing them in this way.

1 Like