81
|
1 package alice.test.topology.movement;
|
|
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;
|
88
|
9
|
81
|
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
|
88
|
18 public class MakeFrame {
|
81
|
19
|
88
|
20 int fSizeX = 800;
|
|
21 int fSizeY = 800;
|
86
|
22 private Canvas3D canvas;
|
88
|
23 private SimpleUniverse universe;
|
|
24 private KeyInput key;
|
93
|
25 private KeyInputCodeSegment KIC;
|
81
|
26
|
88
|
27 public MakeFrame(){
|
|
28 JFrame frame = new JFrame();
|
|
29 frame.setSize(fSizeX,fSizeY);
|
|
30 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
81
|
31
|
|
32 JPanel cp = new JPanel();
|
88
|
33 cp.setLayout(null);
|
81
|
34 frame.add(cp);
|
|
35
|
|
36 GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
|
82
|
37 canvas = new Canvas3D(config);
|
88
|
38 canvas.setBounds(0,0,fSizeX,fSizeY);
|
|
39 cp.add(canvas);
|
82
|
40
|
88
|
41 universe = new SimpleUniverse(canvas);
|
|
42 universe.addBranchGraph(createLight());
|
93
|
43 /*
|
88
|
44 key = new KeyInput();
|
|
45 canvas.addKeyListener(key);
|
93
|
46 */
|
|
47 KIC = new KeyInputCodeSegment();
|
|
48 canvas.addKeyListener(KIC);
|
88
|
49 frame.setVisible(true);
|
81
|
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
|
89
|
66 public void register(MakeObject obj){
|
|
67 BranchGroup group = obj.createBranch();
|
88
|
68 this.universe.addBranchGraph(group);
|
|
69 }
|
|
70
|
92
|
71 public void registerKObj(MakeObject obj){
|
|
72 BranchGroup group = obj.createKeyBranch();
|
|
73 this.universe.addBranchGraph(group);
|
|
74 }
|
|
75
|
88
|
76 public Canvas3D getCanvas(){
|
|
77 return this.canvas;
|
81
|
78 }
|
|
79
|
88
|
80 public KeyInput getKey(){
|
|
81 return this.key;
|
|
82 }
|
|
83
|
93
|
84 public KeyInputCodeSegment getKeySegment(){
|
|
85 return this.KIC;
|
81
|
86 }
|
|
87
|
|
88 }
|