Mercurial > hg > Members > tatsuki > Alice
view src/alice/test/topology/movement/FishMovement.java @ 81:02dfb6c72632 working
This is movement test
author | sugi |
---|---|
date | Thu, 24 May 2012 00:20:16 +0900 |
parents | |
children | 5cf20458b9e0 |
line wrap: on
line source
package alice.test.topology.movement; import java.awt.GraphicsConfiguration; import javax.media.j3d.Appearance; import javax.media.j3d.BoundingSphere; import javax.media.j3d.BranchGroup; import javax.media.j3d.Canvas3D; import javax.media.j3d.DirectionalLight; import javax.media.j3d.Transform3D; import javax.media.j3d.TransformGroup; import javax.swing.JFrame; import javax.swing.JPanel; import javax.vecmath.Color3f; import javax.vecmath.Vector3f; import com.sun.j3d.utils.geometry.Box; import com.sun.j3d.utils.universe.SimpleUniverse; import com.sun.j3d.utils.universe.ViewingPlatform; public final class FishMovement { private Vector3f vector = null; private Transform3D transform1 = null; private TransformGroup transform_group = null; private static class instanceHolder{ private static final FishMovement instance = new FishMovement(); } public static FishMovement getInstance() { return instanceHolder.instance; } private FishMovement(){ JFrame frame = new JFrame(); frame.setSize(1000,1000); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel cp = new JPanel(); frame.add(cp); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas = new Canvas3D(config); canvas.setBounds(0,0,1000,1000);//set canvas size cp.add(canvas);//register canvas with ContentPane SimpleUniverse universe = new SimpleUniverse(canvas); frame.setVisible(true); BranchGroup group1 = createBranch(); universe.addBranchGraph(group1); BranchGroup group2 = createLight(); universe.addBranchGraph(group2); ViewingPlatform camera = universe.getViewingPlatform(); camera.setNominalViewingTransform(); } private BranchGroup createBranch(){ BranchGroup scene = new BranchGroup(); transform_group = new TransformGroup(); scene.addChild(transform_group); transform_group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Box box = new Box(0.4f,0.4f,0.8f,Box.GENERATE_TEXTURE_COORDS,createAppearance()); transform_group.addChild(box); setLocation(0.0f,0.0f); return scene; } private Appearance createAppearance() { Appearance app = new Appearance(); /* Image image = null; Toolkit toolkit = Toolkit.getDefaultToolkit(); image = toolkit.getImage("fish1.jpg"); MediaTracker mt = new MediaTracker(); mt.addImage(image, 0); mt.checkAll(true); try { mt.waitForID(0); }catch (InterruptedException e){ e.printStackTrace(); } Texture texture = new TextureLoader(image,this).getTexture(); app.setTexture(texture); */ return app; } 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 setLocation(float x,float y){ transform1 = new Transform3D(); vector = new Vector3f(x,y,0.0f); transform1.setTranslation(vector); transform_group.setTransform(transform1); } public void setLocation(float x,float y,float z){ transform1 = new Transform3D(); vector = new Vector3f(x,y,z); transform1.setTranslation(vector); transform_group.setTransform(transform1); } }