RayCast Gui Node

Hi i have some problems with collision to guiNode

       ray.setOrigin(new Vector3f(exe.getInputManager().getCursorPosition().getX(),exe.getInputManager().getCursorPosition().getY(),0f));
    ray.setDirection(
            new Vector3f(exe.getInputManager().getCursorPosition().getX(),exe.getInputManager().getCursorPosition().getY(),1.f).normalize());

when i use thiis coordinates in never collides objects

 oasisElderManageTantumTaxLaw.getNode().setLocalTranslation(appSettings.getWidth()/2, appSettings.getHeight()/2, 1);
    oasisElderManageTantumTaxLaw.getNode().setLocalScale(appSettings.getWidth()/10,appSettings.getHeight()/10,0.1f);

when i use 3d ray cast it works fine ,but in guiNode it never works properly .
I had allready a suggestion to use lemur , but i really need to do it without external code,
soo i just need to know some rule or alse that may help me to get proper coordinates from mouse position to ray cast in guiNode

dont use raycast on guiNode.

raycast is prepared for rootNode only as i know. guiNode is special.

if you want calculate when something is inside guiNode, just check screenPosition x/y and check if its in bound of your gui element.

Myself for my universal gui i needed to create rootNode listener for 3d guis and guiNode listener for 2d.

Ray collision with the GUI node works just fine. Direction will always be the same, though.

Your direction is not a direction vector since a direction vector wouldn’t also have position. new Vector3f(0, 0, -1) is the correct direction vector for the screen. Z goes out of the screen.

You can do it up from z=0 but you will encounter everything backwards.

But JME is “external code”. Do you “need” to do it or just “want” to do it? Is this for a school assignment or for learning?

Either way, the code for how Lemur constructs its Ray is right there online:

…where range[1] is a Z value calculated to be above everything.

1 Like

Ray collision with the GUI node works just fine. Direction will always be the same, though.

Vector3f(0, 0, -1) is the correct direction vector for the screen. Z goes out of the screen.

Wow, fight this gui raycast for hours, searching on forum and seen someone having problem too and provided same answer, while you just solve it :slight_smile:

so just need different direction.

2 Likes

I’m morally and psicologically in need of :smiley: .
Thanx for answer it should work now :slight_smile:

Thanks for help :slight_smile:

Yeah. All of this works fine in Lemur… so you can always look there. Even if you are reinventing your own wheel it’s never wrong to check out other peoples’ wheels from time to time for ideas. :slight_smile:

yeah, i felt like i invent own wheel, but thats just one aspect of gui i need to have different(at least i thought i had). but there’s still something i dont seen in other guis i need :slight_smile: