Previously, I was rolling my own selection handling. Since that's a bad idea, I'm trying to setup selection handling of HUD events as demonstrated in the SelectionTest.
Is there a trick to it? With a lot of code omitted, here is what I am doing.
public class MySceneMaker
{
public BranchGroup createScene()
{
BranchGroup result = new BranchGroup();
Sphere sphere = new Sphere( 0.25f, 16, 16, Colorf.WHITE );
StaticTransform.translate( sphere, -5, 5, 0 );
sphere.setName( "Sphere" );
sphere.setUserData( Selectable.class, new BoundingBoxSelectable< Node >( sphere ) );
result.addChild( sphere );
return result;
}
}
public class MyHud extends HUD
{
public MyHud( XithRoot xithRoot )
{
xithRoot.myInputHandler.selectionManager = new SelectionManager();
xithRoot.myInputHandler.selectionManager.bind( xithRoot.branchGroup, xithRoot.firstCanvas );
InputSystem.getInstance().getMouse().addMouseListener( xithRoot.myInputHandler.selectionManager );
xithRoot.myInputHandler.selectionManager.setContextMenuProvider( new HUDContextMenuProvider( this ) );
xithRoot.myInputHandlerselectionManager.addSelectionListener( new SelectionListener()
{
public void selectionChanged( List< Selectable > selection, List< Selectable > selectedContext )
{
for( int i = 0; i < selection.size(); i++ )
{
Selectable selectable = selection.get( i );
Node node = selectable.getNode();
System.out.println( "Selected " + node.getName() );
}
}
public void selectionMoved( List< Selectable > selection, List< Selectable > selectedContext, Vector3f delta )
{
for( int i = 0; i < selection.size(); i++ )
{
Selectable selectable = selection.get( i );
Node node = selectable.getNode();
System.out.println( node.getName() + " moved" );
}
}
} );
addPickMissedListener( SelectionManager.HUD_PICK_MISSED_MASK, xithRoot.myInputHandler.selectionManager );
}
}
I never get the print statements. I think the omitted code can't hurt anything involved here but could include it if it helps.
I don't know if this has any bearing on the problem, but I found that
setCrosshair( createCrossHairTexture() );
setCrosshairVisible( true );
does not work but that
getContentPane().addWidgetCentered( new Image( 32f, 32f, createCrossHairTexture() ) );
does.