How to best get Control after ray collision

I posted a contribution earlier, and normen kindly pointed out that there was a better way to do it already in place. That was really helpful, and I’m in the process of integrating Controls into my program.



However, I’m still trying to see if there’s a better way to find the Control I want after I do a collision test. In a strategy game, for instance, when the user clicks on a building, the collision engine from the ray collision returns the exact Geometry that was clicked on. This Geometry may very well be a window pane Geometry, in a window node, in a wall node, in the building node, which has the Control. If what I really want is that Control, is there a better way to find that Control than simply going up the Node tree and testing getControl() on every Node?

Not really no, you could create a map yourself of all geometries that belong to some node. But grabbing the parents and checking for the control is basically costing nothing.

In that case you will have to climb up the tree since picking does give you the leaf node (geometry) of the branch you picked.

Spatial pickedSpatial = pick()

MyControl myControl;

while (myControl is null):

Spatial spat = pickedSpatial

if (spat.getControl(MyControl.class) != null)

myControl = pickedSpatial.getControl(MyControl.class); break;

else

spat = spat.getParent();

end while;

Okay, thanks. I just wanted to make sure there wasn’t already a method or something that I missed that will do it. :slight_smile: