Java Reference
In-Depth Information
Figure 3. Code segment for KeyBoardUtil.java
1.
public class KeyBoardUtil 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 branch graph
8.
9.
TransformGroup viewTrans = new TransformGroup();
10.
viewTrans = universe.getViewingPlatform().getViewPlatformTransform();
11.
12.
KeyNavigatorBehavior keyNav = new KeyNavigatorBehavior(viewTrans);
13.
keyNav.setSchedulingBounds(new BoundingSphere());
14.
objRoot.addChild(keyNav);
15.
16.
objRoot.addChild(new ColorCube(0.1f));
17.
objRoot.addChild(createFloor());
18.
19.
objRoot.compile(); /// Java 3D to perform optimization on this scene graph
20.
21.
return objRoot;
22.
}
23.
24.
public void init()
25.
{
26.
setLayout(new BorderLayout());
27.
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
28.
29.
Canvas3D canvas3D = new Canvas3D(config);
30.
add("Center", canvas3D);
31.
universe = new SimpleUniverse(canvas3D);
32.
33.
BranchGroup scene = createSceneGraph(universe,canvas3D);
34.
TransformGroup joy = new TransformGroup();
35.
36.
// Move ViewPlatform back a bit so the objects can be viewed.
37.
universe.getViewingPlatform().setNominalViewingTransform();
38.
universe.addBranchGraph(scene);
39.
}
Essentially, two types of movement, translation, and rotation are involved. Mathemati-
cally, we will need to incorporate two types of transformation matrix in the program code.
For rotation, which includes turning left or right, or pitching up or down, the transformation
can be described by
Search WWH ::




Custom Search