Mercurial > hg > Database > Alice
view src/main/java/alice/test/topology/aquarium/MakeObject.java @ 345:8f71c3e6f11d
Change directory structure Maven standard
author | sugi |
---|---|
date | Wed, 16 Apr 2014 18:26:07 +0900 |
parents | |
children | 36d9487bea8b |
line wrap: on
line source
package alice.test.topology.aquarium; import java.awt.Image; import java.awt.MediaTracker; import java.awt.Toolkit; import java.io.FileNotFoundException; import java.net.URL; import javax.media.j3d.Appearance; import javax.media.j3d.BranchGroup; import javax.media.j3d.Texture; import javax.media.j3d.Transform3D; import javax.media.j3d.TransformGroup; import javax.vecmath.Matrix4d; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.Scene; import com.sun.j3d.loaders.objectfile.ObjectFile; import com.sun.j3d.utils.image.TextureLoader; public class MakeObject { private Transform3D transform; private TransformGroup transform_group; private ViewChange canvas; private Matrix4d matrix; private double s; public MakeObject(MakeFrame frame){ this.canvas = frame.getCanvas(); this.s = 0.3; frame.register(this); } public BranchGroup createBranch(){ BranchGroup scene = new BranchGroup(); /*Box box = new Box(0.1f,0.1f,0.0f, Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance());*/ ObjectFile obj = new ObjectFile(ObjectFile.RESIZE); Scene img = null; try{ URL url=getClass().getClassLoader().getResource("TUNA"); img = obj.load(url); } catch(FileNotFoundException e){ System.err.println(e); System.exit(1); } catch(ParsingErrorException e){ System.err.println(e); System.exit(1); } catch(IncorrectFormatException e){ System.err.println(e); System.exit(1); } transform_group = new TransformGroup(); setLocation(-2.0f,-2.0f); //set out of window transform_group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transform_group.addChild(img.getSceneGroup()); scene.addChild(transform_group); return scene; } // no use method public Appearance createAppearance(){ Appearance app = new Appearance(); Image image = null; Toolkit toolkit = Toolkit.getDefaultToolkit(); URL url = getClass().getClassLoader().getResource("fish.jpg"); image = toolkit.getImage(url); MediaTracker mt = new MediaTracker(canvas); mt.addImage(image, 0); mt.checkAll(true); try { mt.waitForID(0); }catch (InterruptedException e){ e.printStackTrace(); } Texture texture = new TextureLoader(image,canvas).getTexture(); app.setTexture(texture); return app; } public void setScale(float size){ s = size; } public void setLocation(float x,float y){ transform = new Transform3D(); matrix = new Matrix4d(s,0,0,x, 0,s,0,y, 0,0,s,0, 0,0,0,1); transform.set(matrix); transform_group.setTransform(transform); } public void setLocation(float x,float y,float z){ transform = new Transform3D(); matrix = new Matrix4d(s,0,0,x, 0,s,0,y, 0,0,s,z, 0,0,0,1); transform.set(matrix); transform_group.setTransform(transform); } }