From 865f8b97d01251594a9cfc98b44151d8d270ee2d Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 18 Oct 2008 03:08:28 -0400 Subject: [PATCH] Add keyboard navigation. Signed-off-by: Edward Z. Yang --- .../mit/ezyang/gravity/GravitySimulatorView.java | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/edu/mit/ezyang/gravity/GravitySimulatorView.java b/src/edu/mit/ezyang/gravity/GravitySimulatorView.java index 6b38c38..0bfb2a9 100644 --- a/src/edu/mit/ezyang/gravity/GravitySimulatorView.java +++ b/src/edu/mit/ezyang/gravity/GravitySimulatorView.java @@ -4,6 +4,7 @@ package edu.mit.ezyang.gravity; +import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior; import org.jdesktop.application.Action; import org.jdesktop.application.SingleFrameApplication; import org.jdesktop.application.FrameView; @@ -52,26 +53,28 @@ public class GravitySimulatorView extends FrameView { universe = new SimpleUniverse(canvas); BranchGroup root = new BranchGroup(); - TransformGroup rotateGroup = new TransformGroup(); + BoundingSphere bounding = new BoundingSphere(new Point3d(0f,0f,0f), 1000.0f); + + // key navigation + TransformGroup vpTrans = universe.getViewingPlatform().getViewPlatformTransform(); + KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans); + keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0)); + root.addChild(keyNavBeh); + universeRoot = new BranchGroup(); universeRoot.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); universeRoot.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); - processCommand("add cube"); - - //processCommand("clear"); - //processCommand("add sphere"); + TransformGroup rotateGroup = new TransformGroup(); rotateGroup.addChild(universeRoot); rotateGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); rotateGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); - BoundingSphere bounding = new BoundingSphere(new Point3d(0f,0f,0f), 1000.0f); - DirectionalLight light = new DirectionalLight(new Color3f(1.8f, 0.2f, 0.2f), new Vector3f(4.0f, -7.0f, 7.0f)); light.setInfluencingBounds(bounding); rotateGroup.addChild(light); - AmbientLight ambLight = new AmbientLight(new Color3f(1f, 1f, 1f)); + AmbientLight ambLight = new AmbientLight(new Color3f(.6f, .6f, .6f)); ambLight.setInfluencingBounds(bounding); rotateGroup.addChild(ambLight); @@ -96,20 +99,24 @@ public class GravitySimulatorView extends FrameView { controlGroup.addChild(rotateGroup); root.addChild(controlGroup); universe.addBranchGraph(root); + ViewingPlatform platform = universe.getViewingPlatform(); platform.setNominalViewingTransform(); + viewTransformGroup = platform.getMultiTransformGroup().getTransformGroup(0); viewTransform = new Transform3D(); viewTransform.setTranslation(new Vector3f(0.0f,0.0f,10.0f)); viewTransformGroup.setTransform(viewTransform); - //universe.getViewer().getView().setFieldOfView(60f); + canvasPanel.add(canvas); + processCommand("add cube"); + } /** * Processes a command from the command line box, modifying Universe. - * @param command to execute + * @param command Command line to execute. */ public void processCommand(String command) { send(command); -- 2.11.4.GIT