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.File;
|
|
6 import java.io.IOException;
|
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.Canvas3D;
|
|
13 import javax.media.j3d.DirectionalLight;
|
109
|
14 import javax.media.j3d.ImageComponent2D;
|
88
|
15
|
81
|
16 import javax.swing.JFrame;
|
|
17 import javax.swing.JPanel;
|
|
18 import javax.vecmath.Color3f;
|
109
|
19 import javax.vecmath.Point3d;
|
81
|
20 import javax.vecmath.Vector3f;
|
|
21
|
|
22 import com.sun.j3d.utils.universe.SimpleUniverse;
|
|
23 import com.sun.j3d.utils.universe.ViewingPlatform;
|
|
24
|
88
|
25 public class MakeFrame {
|
81
|
26
|
140
|
27 private int fSizeX = 800;
|
|
28 private int fSizeY = 800;
|
141
|
29 //private Canvas3D canvas;
|
|
30 private ViewChange canvas;
|
88
|
31 private SimpleUniverse universe;
|
140
|
32 private JFrame frame;
|
|
33 private ObjectList list = new ObjectList();
|
81
|
34
|
110
|
35 public MakeFrame(String str){
|
140
|
36 frame = new JFrame(str);
|
88
|
37 frame.setSize(fSizeX,fSizeY);
|
|
38 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
81
|
39
|
|
40 JPanel cp = new JPanel();
|
88
|
41 cp.setLayout(null);
|
81
|
42 frame.add(cp);
|
|
43
|
|
44 GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
|
141
|
45 //canvas = new Canvas3D(config);
|
|
46 canvas = new ViewChange(3.0f,0.01f,config);
|
88
|
47 canvas.setBounds(0,0,fSizeX,fSizeY);
|
|
48 cp.add(canvas);
|
82
|
49
|
141
|
50
|
|
51 canvas.universe.addBranchGraph(createLight());
|
|
52 canvas.universe.addBranchGraph(setBackground());
|
132
|
53
|
140
|
54 canvas.addKeyListener(new KeyInputCodeSegment(this));
|
88
|
55 frame.setVisible(true);
|
81
|
56
|
141
|
57 //ViewingPlatform camera = universe.getViewingPlatform();
|
|
58 //camera.setNominalViewingTransform();
|
81
|
59 }
|
|
60
|
109
|
61 private BranchGroup setBackground(){
|
|
62 BranchGroup scene = new BranchGroup();
|
|
63 BufferedImage img = null;
|
|
64 try {
|
|
65 img = ImageIO.read(new File("../image/image1.jpg"));
|
|
66 } catch (IOException e) {
|
|
67 e.printStackTrace();
|
|
68 }
|
|
69 ImageComponent2D image =
|
|
70 new ImageComponent2D(ImageComponent2D.FORMAT_RGBA8,img);
|
|
71 Background background = new Background(image);
|
|
72 background.setImageScaleMode(Background.SCALE_FIT_ALL);
|
|
73 BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Double.POSITIVE_INFINITY);
|
|
74 background.setApplicationBounds(bounds);
|
|
75 scene.addChild(background);
|
|
76 return scene;
|
|
77
|
|
78 }
|
|
79
|
81
|
80 private BranchGroup createLight(){
|
|
81 BranchGroup scene = new BranchGroup();
|
|
82 Color3f light_color = new Color3f(1.7f,1.7f,1.7f);
|
|
83 Vector3f light_direction = new Vector3f(0.2f,-0.2f,-0.6f);
|
|
84 DirectionalLight light = new DirectionalLight(light_color,light_direction);
|
|
85 BoundingSphere bounds = new BoundingSphere();
|
|
86 light.setInfluencingBounds(bounds);
|
|
87 scene.addChild(light);
|
|
88 return scene;
|
|
89 }
|
|
90
|
89
|
91 public void register(MakeObject obj){
|
140
|
92 list.table.add(obj);
|
89
|
93 BranchGroup group = obj.createBranch();
|
141
|
94 this.canvas.universe.addBranchGraph(group);
|
140
|
95
|
88
|
96 }
|
|
97
|
111
|
98 public SimpleUniverse getUniverse(){
|
|
99 return this.universe;
|
92
|
100 }
|
|
101
|
141
|
102 public ViewChange getCanvas(){
|
88
|
103 return this.canvas;
|
81
|
104 }
|
140
|
105
|
|
106 public JFrame getJFrame(){
|
|
107 return this.frame;
|
|
108 }
|
|
109
|
|
110 public ObjectList getList(){
|
|
111 return this.list;
|
|
112 }
|
|
113
|
81
|
114 }
|