diff src/alice/test/topology/fishmodel/alpha/MakeFrame.java @ 107:a8f77957a477 working

create new model to share fish point
author sugi
date Tue, 10 Jul 2012 02:30:25 +0900
parents src/alice/test/topology/movement/MakeFrame.java@6601f8854126
children 96674c803853
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fishmodel/alpha/MakeFrame.java	Tue Jul 10 02:30:25 2012 +0900
@@ -0,0 +1,88 @@
+package alice.test.topology.fishmodel.alpha;
+
+import java.awt.GraphicsConfiguration;
+
+import javax.media.j3d.BoundingSphere;
+import javax.media.j3d.BranchGroup;
+import javax.media.j3d.Canvas3D;
+import javax.media.j3d.DirectionalLight;
+
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.vecmath.Color3f;
+import javax.vecmath.Vector3f;
+
+import com.sun.j3d.utils.universe.SimpleUniverse;
+import com.sun.j3d.utils.universe.ViewingPlatform;
+
+public class MakeFrame {
+	
+	int fSizeX = 800;
+	int fSizeY = 800;
+	private Canvas3D canvas;
+	private SimpleUniverse universe;
+	private KeyInput key;
+	private KeyInputCodeSegment KIC;
+	
+	public MakeFrame(){
+		JFrame frame = new JFrame();
+		frame.setSize(fSizeX,fSizeY);
+		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+		
+		JPanel cp = new JPanel();
+		cp.setLayout(null);
+		frame.add(cp);
+		
+		GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
+		canvas = new Canvas3D(config);
+		canvas.setBounds(0,0,fSizeX,fSizeY);
+		cp.add(canvas);
+		
+		universe = new SimpleUniverse(canvas);
+		universe.addBranchGraph(createLight());
+		/*
+		key = new KeyInput();
+		canvas.addKeyListener(key);
+		*/
+		KIC = new KeyInputCodeSegment();
+		canvas.addKeyListener(KIC);
+		frame.setVisible(true);
+		
+		ViewingPlatform camera = universe.getViewingPlatform();
+		camera.setNominalViewingTransform();
+	}
+	
+	private BranchGroup createLight(){
+		BranchGroup scene = new BranchGroup();
+		Color3f light_color  = new Color3f(1.7f,1.7f,1.7f);
+		Vector3f light_direction = new Vector3f(0.2f,-0.2f,-0.6f);
+		DirectionalLight light = new DirectionalLight(light_color,light_direction);
+		BoundingSphere bounds = new BoundingSphere();
+		light.setInfluencingBounds(bounds);
+		scene.addChild(light);
+		return scene;
+	}
+	
+	public void register(MakeObject obj){
+		BranchGroup group = obj.createBranch();
+		this.universe.addBranchGraph(group);
+	}
+	
+	public void registerKObj(MakeObject obj){
+		BranchGroup group = obj.createKeyBranch();
+		this.universe.addBranchGraph(group);
+	}
+	
+	public Canvas3D getCanvas(){
+		return this.canvas;
+	}
+	
+	public KeyInput getKey(){
+		return this.key;
+	}
+	
+	public KeyInputCodeSegment getKeySegment(){
+		return this.KIC;
+	}
+
+}