annotate 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
parents 96674c803853
children ba64a9d76e70
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
107
a8f77957a477 create new model to share fish point
sugi
parents: 105
diff changeset
1 package alice.test.topology.fishmodel.alpha;
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
2
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
3 import java.awt.Image;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
4 import java.awt.MediaTracker;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
5 import java.awt.Toolkit;
109
96674c803853 set background
sugi
parents: 107
diff changeset
6 import java.io.FileNotFoundException;
107
a8f77957a477 create new model to share fish point
sugi
parents: 105
diff changeset
7 //import java.io.File;
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
8
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
9 import javax.media.j3d.Appearance;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
10 import javax.media.j3d.BranchGroup;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
11 import javax.media.j3d.Canvas3D;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
12 import javax.media.j3d.Texture;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
13 import javax.media.j3d.Transform3D;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
14 import javax.media.j3d.TransformGroup;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
15 import javax.vecmath.Vector3f;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
16
109
96674c803853 set background
sugi
parents: 107
diff changeset
17 import com.sun.j3d.loaders.IncorrectFormatException;
96674c803853 set background
sugi
parents: 107
diff changeset
18 import com.sun.j3d.loaders.ParsingErrorException;
96674c803853 set background
sugi
parents: 107
diff changeset
19 import com.sun.j3d.loaders.Scene;
96674c803853 set background
sugi
parents: 107
diff changeset
20 import com.sun.j3d.loaders.objectfile.ObjectFile;
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
21 import com.sun.j3d.utils.geometry.Box;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
22 import com.sun.j3d.utils.image.TextureLoader;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
23
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
24 public class MakeObject {
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
25
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
26 public Vector3f vector;
93
6601f8854126 can KeyInputCodeSegment
sugi
parents: 91
diff changeset
27 Transform3D transform;
6601f8854126 can KeyInputCodeSegment
sugi
parents: 91
diff changeset
28 TransformGroup transform_group;
6601f8854126 can KeyInputCodeSegment
sugi
parents: 91
diff changeset
29 Canvas3D canvas;
6601f8854126 can KeyInputCodeSegment
sugi
parents: 91
diff changeset
30 KeyInput key;
6601f8854126 can KeyInputCodeSegment
sugi
parents: 91
diff changeset
31 KeyInputCodeSegment KIC;
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
32
89
e269cedd8bae Test two fish
sugi
parents: 88
diff changeset
33 public MakeObject(MakeFrame MF){
e269cedd8bae Test two fish
sugi
parents: 88
diff changeset
34 this.canvas = MF.getCanvas();
109
96674c803853 set background
sugi
parents: 107
diff changeset
35 //this.key = MF.getKey();
93
6601f8854126 can KeyInputCodeSegment
sugi
parents: 91
diff changeset
36 this.KIC = MF.getKeySegment();
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
37 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
38
89
e269cedd8bae Test two fish
sugi
parents: 88
diff changeset
39
91
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
40 public BranchGroup createKeyBranch(){
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
41 BranchGroup scene = new BranchGroup();
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
42 Box box = new Box(0.1f,0.1f,0.0f,
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
43 Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance());
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
44 key.transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
45 key.transformGroup.addChild(box);
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
46 scene.addChild(key.transformGroup);
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
47 return scene;
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
48
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
49 }
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
50
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
51 public BranchGroup createBranch(){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
52 BranchGroup scene = new BranchGroup();
109
96674c803853 set background
sugi
parents: 107
diff changeset
53 /*Box box = new Box(0.1f,0.1f,0.0f,
96674c803853 set background
sugi
parents: 107
diff changeset
54 Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance());*/
96674c803853 set background
sugi
parents: 107
diff changeset
55 ObjectFile obj = new ObjectFile(ObjectFile.RESIZE);
96674c803853 set background
sugi
parents: 107
diff changeset
56 Scene S = null;
96674c803853 set background
sugi
parents: 107
diff changeset
57 try{
96674c803853 set background
sugi
parents: 107
diff changeset
58 S = obj.load("../image/galleon.obj");
96674c803853 set background
sugi
parents: 107
diff changeset
59 } catch(FileNotFoundException e){
96674c803853 set background
sugi
parents: 107
diff changeset
60 System.err.println(e);
96674c803853 set background
sugi
parents: 107
diff changeset
61 System.exit(1);
96674c803853 set background
sugi
parents: 107
diff changeset
62 } catch(ParsingErrorException e){
96674c803853 set background
sugi
parents: 107
diff changeset
63 System.err.println(e);
96674c803853 set background
sugi
parents: 107
diff changeset
64 System.exit(1);
96674c803853 set background
sugi
parents: 107
diff changeset
65 } catch(IncorrectFormatException e){
96674c803853 set background
sugi
parents: 107
diff changeset
66 System.err.println(e);
96674c803853 set background
sugi
parents: 107
diff changeset
67 System.exit(1);
96674c803853 set background
sugi
parents: 107
diff changeset
68 }
96674c803853 set background
sugi
parents: 107
diff changeset
69
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
70 transform_group = new TransformGroup();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
71 transform_group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
109
96674c803853 set background
sugi
parents: 107
diff changeset
72 transform_group.addChild(S.getSceneGroup());
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
73 scene.addChild(transform_group);
109
96674c803853 set background
sugi
parents: 107
diff changeset
74 return scene;
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
75 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
76
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
77 private Appearance createAppearance(){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
78 Appearance app = new Appearance();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
79 Image image = null;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
80 Toolkit toolkit = Toolkit.getDefaultToolkit();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
81 //image = toolkit.getImage("image/fish.jpg");
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
82 image = toolkit.getImage("../image/fish.jpg");//jar
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
83 MediaTracker mt = new MediaTracker(canvas);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
84 mt.addImage(image, 0);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
85 mt.checkAll(true);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
86 try {
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
87 mt.waitForID(0);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
89 }catch (InterruptedException e){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
90 e.printStackTrace();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
91
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
92 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
93 Texture texture = new TextureLoader(image,canvas).getTexture();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
94 app.setTexture(texture);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
95 return app;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
96
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
97 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
98
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
99 public void setLocation(float x,float y){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
100 transform = new Transform3D();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
101 vector = new Vector3f(x,y,0.0f);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
102 transform.setTranslation(vector);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
103 transform_group.setTransform(transform);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
104 }
110
aa9fc077c286 remove host from checkFishLocation
sugi
parents: 109
diff changeset
105
aa9fc077c286 remove host from checkFishLocation
sugi
parents: 109
diff changeset
106 public void setLocation(float x,float y,float z){
aa9fc077c286 remove host from checkFishLocation
sugi
parents: 109
diff changeset
107 transform = new Transform3D();
aa9fc077c286 remove host from checkFishLocation
sugi
parents: 109
diff changeset
108 vector = new Vector3f(x,y,z);
aa9fc077c286 remove host from checkFishLocation
sugi
parents: 109
diff changeset
109 transform.setTranslation(vector);
aa9fc077c286 remove host from checkFishLocation
sugi
parents: 109
diff changeset
110 transform_group.setTransform(transform);
aa9fc077c286 remove host from checkFishLocation
sugi
parents: 109
diff changeset
111 }
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
112 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
113