Java Reference
In-Depth Information
Firstly, Figure 9 shows the overall code segment structure of the picking behavior class
to be developed for this application. As can be seen, there is a constructor, an initialize()
method, a processStimulus() method, a findEyeAndEndPos() method for determining the
two end points of PickSegment, a changeAppearance() method to change the appearance
of the picked object, and a printInfo() method to give relevant message information on the
picking process.
Figure 10 shows the second code segment, listing all the important variables that will be
used. Lines 1 and 2 declare suitable wakeup criteria variables that will be used. Specifically,
line 2 declares a WakeupOr variable, while line 1 gives rise to a WakeupCriterion variable
array. The array has only one element, because the only event of interest corresponds to a
mouse click in this example.
Lines 4 and 5 declare BranchGroup and Canvas3D variables that will correspond to
the branchGroup and canvas3D of the scene for the picking behavior. Lines 7 to 9 declare
Shape3D, Appearance and TransparencyAttributes variables for the purpose of changing the
appearance of the picked visual objects. In lines 11 to 14, relevant variables for the picking
class are declared. The variables from lines 16 to 20 are for use in the findEyeAndEndPos()
method to determine the starting and ending point of the pick segment. Lastly, x and y in
lines 22 to 23 serve as stores for the mouse position on the image plate and will also be
used in determining the two end points of the pick segment.
Figure 9. First code segment for PickSegmentBehavior.java
1.
public class SimplePickingSegmentBehavior extends Behavior
2.
{
3.
public SimplePickingSegmentBehavior(Canvas3D canvas3D, BranchGroup branchGroup)
4.
{
// constructor of SimplePickingSegmentBehavior class }
5.
6.
public void initialize()
7.
{
// initialize method }
8.
9.
public void processStimulus(Enumeration criteria)
10.
{
// actions to be taken this behavior class is triggered }
11.
12.
private void findEyeAndEndPos()
13.
{
// set the start and end position of PickSegment }
14.
15.
private void changeAppearance()
16.
{
// used by processStimulus to change transparency attributes of picked object }
17.
18.
private void printInfo(int eventID)
19.
{
// print out relevant information messages
}
20. }
Search WWH ::




Custom Search