I am trying to implement a feature when the user clicks a specified shape (trigger) on the screen that an event is triggered. The following code is a class that I have written that implements mouse picking.

class Picker extends PickMouseBehavior
    private PickCanvas pickCanvas;
    private Node trigger;
    private Node shark1;
    private Node shark2;

    public Picker( Canvas3D canvas , BranchGroup root , Bounds bounds ,
                   Node triggerShape , Node sh1 , Node sh2 )
        super( canvas , root , bounds );
        pickCanvas = new PickCanvas( canvas , root );
        trigger = triggerShape;
        shark1 = sh1;
        shark2 = sh2;
print("Created instance of Picker class.");

    private void print( String s )
       System.out.println("@PICKER: " + s );

    public void updateScene(int xpos, int ypos)
print("updateScene() BEGIN;");
                PickResult pickResult = null;		
		pickCanvas.setShapeLocation(xpos, ypos);
		pickResult = pickCanvas.pickClosest();
                Shape3D shape = null;

		if (pickResult != null) 
                    if ( pickResult != null )
                       Node pickedShape = (Primitive) pickResult.getNode(PickResult.PRIMITIVE);
                       String pickedData = (String) pickedShape.getUserData();
                       if ( pickedData.equals( trigger.getUserData() ) )
                           print("Incorrect Shape");
                    print("No shape picked");

In my main code I am instantiating this class and adding it into the scene graph like so..

Picker picker = new Picker( canvas3D , objRoot , bounds , island , shark1 , shark2 );                                    
         objRoot.addChild( picker );         

I have found that the class is instantiated correctly because the output messages in Picker's constructor are working fine.

My problem is that it simply does not work, clicking anywhere in the screen does not call updateScene() whatsoever. Am I doing something wrong? I'm quite new to Java3D and especially picking.


- Jonathon.

10 Years
Discussion Span
Last Post by Ezzaral
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.