customIZInG pIckInG behavIor class
Since picking, despite its importance, is still a behavior class, methods, and techniques for
dealing with picking follow the same methodology as those discussed in previous chapters
on behavior objects.
Specifically, code development for a customized picking behavior requires the speci-
fication of a constructor, an initialization method, wakeup criteria and conditions, and an
appropriate processStimulus method for carrying out appropriate processing once certain
specified events have happened.
For picking, the constructor usually has arguments that inform the system of the can-
vas3D and branchgroup of interest. Essentially, the constructor will give rise to an object to
carry out the task of implementing picking behavior using the canvas on the branchgroup
specified. In addition, the capability of the PickTool to be used can be defined.
Figure 5 shows a simple example picking constructor based on the use of PickCanvas
in Java 3D. Using PickCanvas is simple and appropriate for implementing picking behavior
based on the mouse. Under this, the picking shape is set by default to either PickRay with
a tolerance value of zero or PickConeRay with a non-zero tolerance value.
Following the constructor, an appropriate initialize function or method has to be
provided to create the initial data under the picking behavior as well as to specify the
Figure 5. A simple picking behavior constructor based on using PickCanvas
public PickingBehavior(Canvas3D canvas3D, BranchGroup branchGroup)
pickCanvas = new PickCanvas(canvas3D, branchGroup);
Figure 6. A few line of code in processStimulus for dealing with mouse location inputs
int x_m = ((MouseEvent)event[i]).getX();
int y_m = ((MouseEvent)event[i]).getY();
Search WWH ::