Java Reference
In-Depth Information
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
1.
public PickingBehavior(Canvas3D canvas3D, BranchGroup branchGroup)
2.
{
3.
pickCanvas = new PickCanvas(canvas3D, branchGroup);
4.
pickCanvas.setTolerance(0.0f);
5.
pickCanvas.setMode(PickCanvas.GEOMETRY_INTERSECT_INFO);
6.
pickCanvas.setMode(PickCanvas.GEOMETRY);
7.
pickCanvas.setMode(PickTool.GEOMETRY);
8.
}
Figure 6. A few line of code in processStimulus for dealing with mouse location inputs
1.
int x_m = ((MouseEvent)event[i]).getX();
2.
int y_m = ((MouseEvent)event[i]).getY();
3.
pickCanvas.setShapeLocation(x_m, y_m);
Search WWH ::




Custom Search