// Java 3D Test Applet // KeyNavigatorTest.java // Copyright (c) 1999 ENDO Yasuyuki // mailto:yasuyuki@javaopen.org // http://www.javaopen.org/j3dbook/index.html import java.applet.*; import java.awt.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.SimpleUniverse; import com.sun.j3d.utils.universe.PlatformGeometry; import com.sun.j3d.utils.behaviors.keyboard.*; public class KeyNavigatorTest extends Applet { private SimpleUniverse universe = null; public KeyNavigatorTest() { GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas = new Canvas3D(config); this.setLayout(new BorderLayout()); this.add(canvas, BorderLayout.CENTER); universe = new SimpleUniverse(canvas); universe.getViewingPlatform().setNominalViewingTransform(); universe.getViewer().getView().setBackClipDistance(100.0); BranchGroup scene = createSceneGraph(); universe.addBranchGraph(scene); } private BranchGroup createSceneGraph() { BranchGroup root = new BranchGroup(); BoundingSphere bounds = new BoundingSphere( new Point3d(), 100.0 ); TransformGroup viewtrans = universe.getViewingPlatform().getViewPlatformTransform(); KeyNavigatorBehavior keybehavior = new KeyNavigatorBehavior(viewtrans); keybehavior.setSchedulingBounds(bounds); PlatformGeometry vp = new PlatformGeometry(); vp.addChild(keybehavior); universe.getViewingPlatform().setPlatformGeometry(vp); root.addChild(createFloor()); return root; } // チェッカー模様の床を作る private BranchGroup createFloor() { BranchGroup bg = new BranchGroup(); int roop = 100; Point3f[] vertices = new Point3f[roop * roop]; float start = -100.0f; float x = start; float z = start; float step = 2.0f; int[] indices = new int[(roop - 1)*(roop - 1) * 4]; int n = 0; Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f[] colors = { white, black }; int[] colorindices = new int[indices.length]; for (int i=0; i