Mercurial > hg > Members > tatsuki > Alice
diff src/alice/test/topology/aquarium/MakeFrame.java @ 134:53aff28cde6b working
change package
author | sugi |
---|---|
date | Wed, 15 Aug 2012 17:11:57 +0900 |
parents | src/alice/test/topology/fishmodel/alpha/MakeFrame.java@1044a79ce4ef |
children | 87f1a30a8c82 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/topology/aquarium/MakeFrame.java Wed Aug 15 17:11:57 2012 +0900 @@ -0,0 +1,106 @@ +package alice.test.topology.aquarium; + +import java.awt.GraphicsConfiguration; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; +import javax.media.j3d.Background; +import javax.media.j3d.BoundingSphere; +import javax.media.j3d.BranchGroup; +import javax.media.j3d.Canvas3D; +import javax.media.j3d.DirectionalLight; +import javax.media.j3d.ImageComponent2D; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.vecmath.Color3f; +import javax.vecmath.Point3d; +import javax.vecmath.Vector3f; + +import com.sun.j3d.utils.universe.SimpleUniverse; +import com.sun.j3d.utils.universe.ViewingPlatform; + +public class MakeFrame { + + int fSizeX = 800; + int fSizeY = 800; + private Canvas3D canvas; + private SimpleUniverse universe; + private KeyInputCodeSegment kics; + + public MakeFrame(String str){ + JFrame frame = new JFrame(str); + frame.setSize(fSizeX,fSizeY); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JPanel cp = new JPanel(); + cp.setLayout(null); + frame.add(cp); + + GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); + canvas = new Canvas3D(config); + canvas.setBounds(0,0,fSizeX,fSizeY); + cp.add(canvas); + + universe = new SimpleUniverse(canvas); + universe.addBranchGraph(createLight()); + universe.addBranchGraph(setBackground()); + + kics = new KeyInputCodeSegment(); + canvas.addKeyListener(kics); + frame.setVisible(true); + + ViewingPlatform camera = universe.getViewingPlatform(); + camera.setNominalViewingTransform(); + } + + private BranchGroup setBackground(){ + BranchGroup scene = new BranchGroup(); + BufferedImage img = null; + try { + img = ImageIO.read(new File("../image/image1.jpg")); + } catch (IOException e) { + e.printStackTrace(); + } + ImageComponent2D image = + new ImageComponent2D(ImageComponent2D.FORMAT_RGBA8,img); + Background background = new Background(image); + background.setImageScaleMode(Background.SCALE_FIT_ALL); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Double.POSITIVE_INFINITY); + background.setApplicationBounds(bounds); + scene.addChild(background); + return scene; + + } + + private BranchGroup createLight(){ + BranchGroup scene = new BranchGroup(); + Color3f light_color = new Color3f(1.7f,1.7f,1.7f); + Vector3f light_direction = new Vector3f(0.2f,-0.2f,-0.6f); + DirectionalLight light = new DirectionalLight(light_color,light_direction); + BoundingSphere bounds = new BoundingSphere(); + light.setInfluencingBounds(bounds); + scene.addChild(light); + return scene; + } + + public void register(MakeObject obj){ + BranchGroup group = obj.createBranch(); + this.universe.addBranchGraph(group); + } + + public SimpleUniverse getUniverse(){ + return this.universe; + } + + public Canvas3D getCanvas(){ + return this.canvas; + } + + public KeyInputCodeSegment getKeySegment(){ + return this.kics; + } + +}