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