134
|
1 package alice.test.topology.aquarium;
|
81
|
2
|
|
3 import java.awt.GraphicsConfiguration;
|
109
|
4 import java.awt.image.BufferedImage;
|
|
5 import java.io.IOException;
|
146
|
6 import java.net.URL;
|
81
|
7
|
109
|
8 import javax.imageio.ImageIO;
|
|
9 import javax.media.j3d.Background;
|
81
|
10 import javax.media.j3d.BoundingSphere;
|
|
11 import javax.media.j3d.BranchGroup;
|
|
12 import javax.media.j3d.DirectionalLight;
|
109
|
13 import javax.media.j3d.ImageComponent2D;
|
88
|
14
|
81
|
15 import javax.swing.JFrame;
|
|
16 import javax.swing.JPanel;
|
|
17 import javax.vecmath.Color3f;
|
109
|
18 import javax.vecmath.Point3d;
|
81
|
19 import javax.vecmath.Vector3f;
|
|
20
|
|
21 import com.sun.j3d.utils.universe.SimpleUniverse;
|
|
22
|
88
|
23 public class MakeFrame {
|
81
|
24
|
140
|
25 private int fSizeX = 800;
|
|
26 private int fSizeY = 800;
|
141
|
27 private ViewChange canvas;
|
140
|
28 private JFrame frame;
|
|
29 private ObjectList list = new ObjectList();
|
81
|
30
|
170
|
31 public MakeFrame(String str,float x){
|
140
|
32 frame = new JFrame(str);
|
88
|
33 frame.setSize(fSizeX,fSizeY);
|
|
34 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
81
|
35
|
|
36 JPanel cp = new JPanel();
|
88
|
37 cp.setLayout(null);
|
81
|
38 frame.add(cp);
|
|
39
|
|
40 GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
|
170
|
41 canvas = new ViewChange(x,0.01f,config);
|
88
|
42 canvas.setBounds(0,0,fSizeX,fSizeY);
|
|
43 cp.add(canvas);
|
82
|
44
|
141
|
45 canvas.universe.addBranchGraph(createLight());
|
|
46 canvas.universe.addBranchGraph(setBackground());
|
132
|
47
|
140
|
48 canvas.addKeyListener(new KeyInputCodeSegment(this));
|
88
|
49 frame.setVisible(true);
|
81
|
50
|
|
51 }
|
|
52
|
109
|
53 private BranchGroup setBackground(){
|
|
54 BranchGroup scene = new BranchGroup();
|
|
55 BufferedImage img = null;
|
|
56 try {
|
146
|
57 URL url = getClass().getClassLoader().getResource("image1.jpg");
|
|
58 img = ImageIO.read(url);
|
109
|
59 } catch (IOException e) {
|
|
60 e.printStackTrace();
|
|
61 }
|
|
62 ImageComponent2D image =
|
|
63 new ImageComponent2D(ImageComponent2D.FORMAT_RGBA8,img);
|
|
64 Background background = new Background(image);
|
|
65 background.setImageScaleMode(Background.SCALE_FIT_ALL);
|
170
|
66 BoundingSphere bounds = new BoundingSphere(new Point3d(), 10.0);
|
109
|
67 background.setApplicationBounds(bounds);
|
|
68 scene.addChild(background);
|
|
69 return scene;
|
|
70
|
|
71 }
|
|
72
|
81
|
73 private BranchGroup createLight(){
|
|
74 BranchGroup scene = new BranchGroup();
|
|
75 Color3f light_color = new Color3f(1.7f,1.7f,1.7f);
|
170
|
76 Vector3f light_direction = new Vector3f(0.0f,0.0f,-1.0f);
|
81
|
77 DirectionalLight light = new DirectionalLight(light_color,light_direction);
|
170
|
78 BoundingSphere bounds = new BoundingSphere(new Point3d(), 10.0);
|
81
|
79 light.setInfluencingBounds(bounds);
|
|
80 scene.addChild(light);
|
|
81 return scene;
|
|
82 }
|
|
83
|
89
|
84 public void register(MakeObject obj){
|
140
|
85 list.table.add(obj);
|
89
|
86 BranchGroup group = obj.createBranch();
|
141
|
87 this.canvas.universe.addBranchGraph(group);
|
88
|
88 }
|
|
89
|
141
|
90 public ViewChange getCanvas(){
|
88
|
91 return this.canvas;
|
81
|
92 }
|
140
|
93
|
|
94 public JFrame getJFrame(){
|
|
95 return this.frame;
|
|
96 }
|
|
97
|
|
98 public ObjectList getList(){
|
|
99 return this.list;
|
|
100 }
|
|
101
|
81
|
102 }
|