Java Reference
In-Depth Information
The second part in the code segment of Figure 11 shows the initialize method for the
initial wakeup of our behavior. Specifically, as only mouse click event is of interest, the
array allEvents[] only has 1 element corresponding to a MOUSE_CLICKED event.
Figure 12 shows the code segment for the processStimulus method that will carry out
the necessary processing when the behavior is triggered. The method starts with checking
whether a mouse click event has indeed result in the trigger. If this is the case, the code
segment within the first if statement will be executed. The execution includes the use of
PickSegment with appropriate starting and ending points to define a ray segment and to
pick visual objects. In particular, the findEyeAndEndPos() method is used to determine the
start and end point of the pick segment, after which pickTool is set to PickSegment. With
the newly selected pickTool, the system will carry out picking to find the nearest object in
the picked region and have the result stored in pickResult. A null pickResult means that
the operation has resulted in nothing. Otherwise, a visual object has been picked and its
appearance will be changed. Note that PickIntersect will give the Shape3D obtained from
the picking operation.
Snapshots of the result from the code segments in Figures 9 to 12 are shown in Figure
13. A 3 by 3 array of trapeziums are placed at different distance from the viewing plat-
form. The appearance attribute of a particular trapezium can be changed by clicking at
the trapezium with a mouse, and the trapezium will change from translucent to opaque or
the other way round.
Note that it is not necessary to be within a trapezium for it to be selected. Clicking
outside the trapezium may also select the object as the picking behavior is set to pick by
object geometries rather than bounds. The left and middle diagrams in Figure 13 illustrate
the changes that occurred when the relevant trapeziums are selected using mouse clicks.
The right diagram, however, show that the third row of visual objects cannot be selected.
Figure 13. Result from
First Row Clicked
Second Row Clicked
Third Row Clicked
Search WWH ::

Custom Search