How to dynamically extend PickCanvas object for MouseListener click event in a Java Applet (using Java3D)?

310 Views Asked by At

I am developing a Java applet using Java3D. It starts up with a BranchGroup object (containing a set of points) which is added to a Locale object. A PickCanvas is created starting from the Locale and a class implementing MouseListener is constructed starting from said PickCanvas.

Mouse clicks are being detected correctly at this stage. The issue I am having is that whenever I start adding more points to my applet (by creating a new BranchGroup object for each set of points that is loaded and then appending this object to my initial Locale object) mouse clicks are not being registered when newly added points are selected.

I probably do something wrong when I refresh the PickCanvas of my MouseListener implementing object after adding new BranchGroup objs. How can I make it so that points that are added in branchgroups after startup are picked by mouse clicks?

Here's how the locale, the first branchgroup and mouselistener are created:

setLayout(new BorderLayout());
GraphicsConfiguration gc = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(gc);
Utm_Coord_3d observerPoint = new Utm_Coord_3d();
BranchGroup scene=loadPoints(geoPathID, startSequenceID, endSequenceID, observerPoint);
Locale mLocale = new Locale(simpleU);
mLocale.addBranchGraph(scene);
PickCanvas pickCanvas = new PickCanvas(canvas3D, mLocale);
pickCanvas.setMode(PickCanvas.BOUNDS);
MouseMethodsPoints myMouseEventListener = new MouseMethodsPoints(simpleU, viewT3D, pickCanvas);
canvas3D.addMouseListener(myMouseEventListener);
canvas3D.addMouseMotionListener(myMouseEventListener);
canvas3D.addMouseWheelListener(myMouseEventListener);
KeyMethodsPoints myKeyEventListener = new KeyMethodsPoints(canvas3D, simpleU, viewT3D, geoPathID, startSequenceID, endSequenceID, tiltX, scene,mLocale, myMouseEventListener);
canvas3D.addKeyListener(myKeyEventListener);
canvas3D.requestFocus();

And finally this is how I add branchgroups to the locale object updating the pickcanvas:

BranchGroup newBranchGroup=MainPoints.loadPoints(geoPathID, upperBound+1, upperBound+nFilesLoaded, null);
newBranchGroup.compile();
mLocale.addBranchGraph(newBranchGroup);         
PickCanvas pickCanvas = new PickCanvas(canvas3D,mLocale);       
pickCanvas.setMode(PickCanvas.BOUNDS);
mMouseMethodsPoints.setPickCanvas(pickCanvas);

Where setPickCanvas() sets pickCanvas in the MouseListener implementing class object. I even tried creating a new MouseMethodsPoints object every time I add a branchgroup but clicks would still find no points in the areas of the new branchgroups.

Thank you for your time!

0

There are 0 best solutions below