comparison src/alice/test/topology/fishmodel/alpha/MakeFrame.java @ 109:96674c803853 working

set background
author sugi
date Sun, 15 Jul 2012 20:48:01 +0900
parents a8f77957a477
children aa9fc077c286
comparison
equal deleted inserted replaced
108:5f0010c13631 109:96674c803853
1 package alice.test.topology.fishmodel.alpha; 1 package alice.test.topology.fishmodel.alpha;
2 2
3 import java.awt.GraphicsConfiguration; 3 import java.awt.GraphicsConfiguration;
4 import java.awt.image.BufferedImage;
5 import java.io.File;
6 import java.io.IOException;
4 7
8 import javax.imageio.ImageIO;
9 import javax.media.j3d.Background;
5 import javax.media.j3d.BoundingSphere; 10 import javax.media.j3d.BoundingSphere;
6 import javax.media.j3d.BranchGroup; 11 import javax.media.j3d.BranchGroup;
7 import javax.media.j3d.Canvas3D; 12 import javax.media.j3d.Canvas3D;
8 import javax.media.j3d.DirectionalLight; 13 import javax.media.j3d.DirectionalLight;
14 import javax.media.j3d.ImageComponent2D;
9 15
10 import javax.swing.JFrame; 16 import javax.swing.JFrame;
11 import javax.swing.JPanel; 17 import javax.swing.JPanel;
12 import javax.vecmath.Color3f; 18 import javax.vecmath.Color3f;
19 import javax.vecmath.Point3d;
13 import javax.vecmath.Vector3f; 20 import javax.vecmath.Vector3f;
14 21
15 import com.sun.j3d.utils.universe.SimpleUniverse; 22 import com.sun.j3d.utils.universe.SimpleUniverse;
16 import com.sun.j3d.utils.universe.ViewingPlatform; 23 import com.sun.j3d.utils.universe.ViewingPlatform;
17 24
38 canvas.setBounds(0,0,fSizeX,fSizeY); 45 canvas.setBounds(0,0,fSizeX,fSizeY);
39 cp.add(canvas); 46 cp.add(canvas);
40 47
41 universe = new SimpleUniverse(canvas); 48 universe = new SimpleUniverse(canvas);
42 universe.addBranchGraph(createLight()); 49 universe.addBranchGraph(createLight());
50 universe.addBranchGraph(setBackground());
43 /* 51 /*
44 key = new KeyInput(); 52 key = new KeyInput();
45 canvas.addKeyListener(key); 53 canvas.addKeyListener(key);
46 */ 54 */
47 KIC = new KeyInputCodeSegment(); 55 KIC = new KeyInputCodeSegment();
48 canvas.addKeyListener(KIC); 56 canvas.addKeyListener(KIC);
49 frame.setVisible(true); 57 frame.setVisible(true);
50 58
51 ViewingPlatform camera = universe.getViewingPlatform(); 59 ViewingPlatform camera = universe.getViewingPlatform();
52 camera.setNominalViewingTransform(); 60 camera.setNominalViewingTransform();
61 }
62
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
53 } 80 }
54 81
55 private BranchGroup createLight(){ 82 private BranchGroup createLight(){
56 BranchGroup scene = new BranchGroup(); 83 BranchGroup scene = new BranchGroup();
57 Color3f light_color = new Color3f(1.7f,1.7f,1.7f); 84 Color3f light_color = new Color3f(1.7f,1.7f,1.7f);