Java Reference
In-Depth Information
With the important variables declared, the first part of Figure 11 shows the code seg-
ment for the constructor of the pick behavior class in our application. Lines 3 and 4 set the
branchGroup and canvas3D of our behavior object to that of the external one invoking it.
Lines 8 to 10 set or turn on the necessary capabilities of the pickTool. Specifically, picking
will start from the branchGroup and with PickTool.GEOMETRY specified, picking will be
carried out based on the geometries of objects rather than their bounds. Similarly, lines 5
and 6 set the capability of Shape3D to allow for the reading and writing of the appearance
of visual object. Note that the setting of this capability must be performed in the construc-
tor or during initializing. It cannot be carried out in processStimulus() when the object is
already live. This is because capabilities cannot be set or modify for a live node.
Figure 12. Fourth code segment for PickSegmentBehavior.java
1.
public void processStimulus(Enumeration criteria)
2.
{
3.
WakeupCriterion wakeup; AWTEvent []event; int eventID;
4.
5.
while(criteria.hasMoreElements())
6.
{
7.
wakeup = (WakeupCriterion)criteria.nextElement();
8.
if(wakeup instanceof WakeupOnAWTEvent)
9.
{
10.
event = ((WakeupOnAWTEvent)wakeup).getAWTEvent();
11.
for(int i=0; i<event.length; i++)
12.
{
13.
eventID = event[i].getID();
14.
if(eventID == MouseEvent.MOUSE_CLICKED)
15.
{
16.
x = ((MouseEvent)event[i]).getX();
17.
y = ((MouseEvent)event[i]).getY();
18.
findEyeAndEndPos();
19.
pickTool.setShapeSegment(eyepos, endpos);
20.
pickResult = pickTool.pickClosest();
21.
if (pickResult!=null)
22.
{
23.
pickIntersect = pickResult.getClosestIntersection(eyepos);
24.
geo3D = (Shape3D) pickResult.getNode(PickResult.SHAPE3D);
25.
changeAppearance();
26.
}
27.
printInfo(eventID);
28.
}
29.
}
30.
}
31.
this.wakeupOn(allEventsCriterion);
32.
}
33. }
Search WWH ::




Custom Search