comparison 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
comparison
equal deleted inserted replaced
106:c84a2b4a877a 107:a8f77957a477
1 package alice.test.topology.fishmodel.alpha;
2
3 import java.awt.GraphicsConfiguration;
4
5 import javax.media.j3d.BoundingSphere;
6 import javax.media.j3d.BranchGroup;
7 import javax.media.j3d.Canvas3D;
8 import javax.media.j3d.DirectionalLight;
9
10 import javax.swing.JFrame;
11 import javax.swing.JPanel;
12 import javax.vecmath.Color3f;
13 import javax.vecmath.Vector3f;
14
15 import com.sun.j3d.utils.universe.SimpleUniverse;
16 import com.sun.j3d.utils.universe.ViewingPlatform;
17
18 public class MakeFrame {
19
20 int fSizeX = 800;
21 int fSizeY = 800;
22 private Canvas3D canvas;
23 private SimpleUniverse universe;
24 private KeyInput key;
25 private KeyInputCodeSegment KIC;
26
27 public MakeFrame(){
28 JFrame frame = new JFrame();
29 frame.setSize(fSizeX,fSizeY);
30 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
31
32 JPanel cp = new JPanel();
33 cp.setLayout(null);
34 frame.add(cp);
35
36 GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
37 canvas = new Canvas3D(config);
38 canvas.setBounds(0,0,fSizeX,fSizeY);
39 cp.add(canvas);
40
41 universe = new SimpleUniverse(canvas);
42 universe.addBranchGraph(createLight());
43 /*
44 key = new KeyInput();
45 canvas.addKeyListener(key);
46 */
47 KIC = new KeyInputCodeSegment();
48 canvas.addKeyListener(KIC);
49 frame.setVisible(true);
50
51 ViewingPlatform camera = universe.getViewingPlatform();
52 camera.setNominalViewingTransform();
53 }
54
55 private BranchGroup createLight(){
56 BranchGroup scene = new BranchGroup();
57 Color3f light_color = new Color3f(1.7f,1.7f,1.7f);
58 Vector3f light_direction = new Vector3f(0.2f,-0.2f,-0.6f);
59 DirectionalLight light = new DirectionalLight(light_color,light_direction);
60 BoundingSphere bounds = new BoundingSphere();
61 light.setInfluencingBounds(bounds);
62 scene.addChild(light);
63 return scene;
64 }
65
66 public void register(MakeObject obj){
67 BranchGroup group = obj.createBranch();
68 this.universe.addBranchGraph(group);
69 }
70
71 public void registerKObj(MakeObject obj){
72 BranchGroup group = obj.createKeyBranch();
73 this.universe.addBranchGraph(group);
74 }
75
76 public Canvas3D getCanvas(){
77 return this.canvas;
78 }
79
80 public KeyInput getKey(){
81 return this.key;
82 }
83
84 public KeyInputCodeSegment getKeySegment(){
85 return this.KIC;
86 }
87
88 }