Java Reference
In-Depth Information
Similar to other utility classes, using the mouse behavior classes is quite straightforward
and requires the following steps:
Create an appropriate MouseBehavior object.
Set the target transform group.
Define bounds for the MouseBehavior object.
Add the MouseBehavior object to the scene graph.
The code segment listed in Figure 9 exemplifies instances where the three mouse be-
havior classes are used for navigational. Note that MouseBehavior.INVERT_INPUTS is
selected and the target transform group is the ViewPlatform transform.
Figure 9. Code segment for MouseInteractionUtil.java
1.
public class MouseInteractionUtil extends Applet
2.
{
3.
SimpleUniverse universe = null;
4.
5.
public BranchGroup createSceneGraph(SimpleUniverse universe, Canvas3D c)
6.
{
7.
BranchGroup objRoot = new BranchGroup(); // create root of the branch graph
8.
9.
TransformGroup viewTrans = new TransformGroup();
10.
viewTrans = universe.getViewingPlatform().getViewPlatformTransform();
11.
12.
MouseRotate Rotate = new MouseRotate(MouseBehavior.INVERT_INPUT); // rotate
13.
Rotate.setTransformGroup(viewTrans);
14.
Rotate.setSchedulingBounds(new BoundingSphere());
15.
objRoot.addChild(Rotate);
16.
17.
MouseTranslate Translate = new MouseTranslate(MouseBehavior.INVERT_INPUT); // translate
18.
Translate.setTransformGroup(viewTrans);
19.
Translate.setSchedulingBounds(new BoundingSphere());
20.
objRoot.addChild(Translate);
21.
22.
MouseZoom Zoom = new MouseZoom(MouseBehavior.INVERT_INPUT); // zoom
23.
Zoom.setTransformGroup(viewTrans);
24.
Zoom.setSchedulingBounds(new BoundingSphere());
25.
objRoot.addChild(Zoom);
26.
27.
objRoot.addChild(new ColorCube(0.1f));
28.
objRoot.addChild(createFloor());
29.
30.
objRoot.compile(); // Java optimization
31.
return objRoot;
32.
}
Search WWH ::




Custom Search