107
|
1 package alice.test.topology.fishmodel.alpha;
|
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
|
88
|
27 int fSizeX = 800;
|
|
28 int fSizeY = 800;
|
85
|
29 private Canvas3D canvas;
|
88
|
30 private SimpleUniverse universe;
|
|
31 private KeyInput key;
|
127
|
32 private KeyInputCodeSegment kics;
|
81
|
33
|
110
|
34 public MakeFrame(String str){
|
|
35 JFrame 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());
|
93
|
51 /*
|
88
|
52 key = new KeyInput();
|
|
53 canvas.addKeyListener(key);
|
93
|
54 */
|
127
|
55 kics = new KeyInputCodeSegment();
|
|
56 canvas.addKeyListener(kics);
|
88
|
57 frame.setVisible(true);
|
81
|
58
|
|
59 ViewingPlatform camera = universe.getViewingPlatform();
|
|
60 camera.setNominalViewingTransform();
|
|
61 }
|
|
62
|
109
|
63 private BranchGroup setBackground(){
|
|
64 BranchGroup scene = new BranchGroup();
|
|
65 BufferedImage img = null;
|
|
66 try {
|
|
67 img = ImageIO.read(new File("../image/image1.jpg"));
|
|
68 } catch (IOException e) {
|
|
69 e.printStackTrace();
|
|
70 }
|
|
71 ImageComponent2D image =
|
|
72 new ImageComponent2D(ImageComponent2D.FORMAT_RGBA8,img);
|
|
73 Background background = new Background(image);
|
|
74 background.setImageScaleMode(Background.SCALE_FIT_ALL);
|
|
75 BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Double.POSITIVE_INFINITY);
|
|
76 background.setApplicationBounds(bounds);
|
|
77 scene.addChild(background);
|
|
78 return scene;
|
|
79
|
|
80 }
|
|
81
|
81
|
82 private BranchGroup createLight(){
|
|
83 BranchGroup scene = new BranchGroup();
|
|
84 Color3f light_color = new Color3f(1.7f,1.7f,1.7f);
|
|
85 Vector3f light_direction = new Vector3f(0.2f,-0.2f,-0.6f);
|
|
86 DirectionalLight light = new DirectionalLight(light_color,light_direction);
|
|
87 BoundingSphere bounds = new BoundingSphere();
|
|
88 light.setInfluencingBounds(bounds);
|
|
89 scene.addChild(light);
|
|
90 return scene;
|
|
91 }
|
|
92
|
89
|
93 public void register(MakeObject obj){
|
|
94 BranchGroup group = obj.createBranch();
|
88
|
95 this.universe.addBranchGraph(group);
|
|
96 }
|
|
97
|
111
|
98 public SimpleUniverse getUniverse(){
|
|
99 return this.universe;
|
92
|
100 }
|
|
101
|
88
|
102 public Canvas3D getCanvas(){
|
|
103 return this.canvas;
|
81
|
104 }
|
|
105
|
88
|
106 public KeyInput getKey(){
|
|
107 return this.key;
|
|
108 }
|
|
109
|
93
|
110 public KeyInputCodeSegment getKeySegment(){
|
127
|
111 return this.kics;
|
81
|
112 }
|
|
113
|
|
114 }
|