Java Reference
In-Depth Information
Figure 5. Second code segment for KeyBoardNavigation.java
36. private Transform3D setRotation3D(TransformGroup Trans, float angle, Matrix3f rotMat, int mode)
37. { // to set the position after rotation
38.
Transform3D rt3d = new Transform3D();
39.
Trans.getTransform(rt3d);
40.
rotMat.transpose();
41.
rotMat.invert();
42.
rotMat.mul(rotMat, coMatrix(mode, angle));
43.
rt3d.setRotation(rotMat);
44.
Trans.setTransform(rt3d);
45.
return rt3d;
46. }
47.
48. private Transform3D setPosition3D(TransformGroup Trans, Point3f point)
49. { // to set the position after movement
50.
Transform3D t3d = new Transform3D();
51.
Trans.getTransform(t3d);
52.
t3d.setTranslation(new Vector3d(point));
53.
Trans.setTransform(t3d);
54.
return t3d;
55. }
carry out any necessary processing when the behavior has been awoken. In the current
example, the identity of the key pressed is passed as information to the keypressed function,
which will decide if a predefined key has been pressed, and then subsequently modify the
orientation and position of the ViewPlatform accordingly.
navIGatIon usInG mouse utIlIty class
In addition to the keyboard, the mouse and other appropriate input devices can also be
used for navigation. Using the mouse is convenient and requires less training than using
the keyboard, especially in the presence of mouse dragging and clicking based 3D navi-
gational tools on the screen.
In Java 3D, a number of straightforward utility behaviors that allow the mouse to be used
for interaction and navigation are available. These are summarized in Figure 8 and include
classes for translating, zooming, and rotating objects based on mouse movements.
In general, these behavior classes can be used to manipulate visual objects in the man-
ner specified. In particular, they can be used for 3D navigation in the virtual universe.
Note that the three classes have very similar structures, and have constructors, which
Search WWH ::




Custom Search