Mercurial > hg > Members > tatsuki > Alice
view src/alice/test/topology/fishmodel/alpha/MakeObject.java @ 110:aa9fc077c286 working
remove host from checkFishLocation
author | sugi |
---|---|
date | Sun, 15 Jul 2012 21:32:48 +0900 (2012-07-15) |
parents | 96674c803853 |
children | ba64a9d76e70 |
line wrap: on
line source
package alice.test.topology.fishmodel.alpha; import java.awt.Image; import java.awt.MediaTracker; import java.awt.Toolkit; import java.io.FileNotFoundException; //import java.io.File; import javax.media.j3d.Appearance; import javax.media.j3d.BranchGroup; import javax.media.j3d.Canvas3D; import javax.media.j3d.Texture; import javax.media.j3d.Transform3D; import javax.media.j3d.TransformGroup; import javax.vecmath.Vector3f; 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.geometry.Box; import com.sun.j3d.utils.image.TextureLoader; public class MakeObject { public Vector3f vector; Transform3D transform; TransformGroup transform_group; Canvas3D canvas; KeyInput key; KeyInputCodeSegment KIC; public MakeObject(MakeFrame MF){ this.canvas = MF.getCanvas(); //this.key = MF.getKey(); this.KIC = MF.getKeySegment(); } public BranchGroup createKeyBranch(){ BranchGroup scene = new BranchGroup(); Box box = new Box(0.1f,0.1f,0.0f, Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance()); key.transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); key.transformGroup.addChild(box); scene.addChild(key.transformGroup); return scene; } 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 S = null; try{ S = obj.load("../image/galleon.obj"); } 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(); transform_group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transform_group.addChild(S.getSceneGroup()); scene.addChild(transform_group); return scene; } private Appearance createAppearance(){ Appearance app = new Appearance(); Image image = null; Toolkit toolkit = Toolkit.getDefaultToolkit(); //image = toolkit.getImage("image/fish.jpg"); image = toolkit.getImage("../image/fish.jpg");//jar 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 setLocation(float x,float y){ transform = new Transform3D(); vector = new Vector3f(x,y,0.0f); transform.setTranslation(vector); transform_group.setTransform(transform); } public void setLocation(float x,float y,float z){ transform = new Transform3D(); vector = new Vector3f(x,y,z); transform.setTranslation(vector); transform_group.setTransform(transform); } }