annotate src/alice/test/topology/movement/MakeObject.java @ 91:19f3bd33277d working

add KeyInput
author sugi
date Tue, 05 Jun 2012 00:35:58 +0900
parents e269cedd8bae
children 6601f8854126
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
1 package alice.test.topology.movement;
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;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
6 import java.io.File;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
7
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
8 import javax.media.j3d.Appearance;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
9 import javax.media.j3d.BranchGroup;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
10 import javax.media.j3d.Canvas3D;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
11 import javax.media.j3d.Texture;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
12 import javax.media.j3d.Transform3D;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
13 import javax.media.j3d.TransformGroup;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
14 import javax.vecmath.Vector3f;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
15
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
16 import com.sun.j3d.utils.geometry.Box;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
17 import com.sun.j3d.utils.image.TextureLoader;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
18
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
19 public class MakeObject {
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
20
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
21 public Vector3f vector;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
22 private Transform3D transform;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
23 private TransformGroup transform_group;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
24 private Canvas3D canvas;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
25 private KeyInput key;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
26
89
e269cedd8bae Test two fish
sugi
parents: 88
diff changeset
27 public MakeObject(MakeFrame MF){
e269cedd8bae Test two fish
sugi
parents: 88
diff changeset
28 this.canvas = MF.getCanvas();
e269cedd8bae Test two fish
sugi
parents: 88
diff changeset
29 this.key = MF.getKey();
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
30 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
31
89
e269cedd8bae Test two fish
sugi
parents: 88
diff changeset
32
91
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
33 public BranchGroup createKeyBranch(){
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
34 BranchGroup scene = new BranchGroup();
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
35 Box box = new Box(0.1f,0.1f,0.0f,
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
36 Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance());
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
37 key.transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
38 key.transformGroup.addChild(box);
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
39 scene.addChild(key.transformGroup);
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
40 return scene;
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
41
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
42 }
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
43
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
44 public BranchGroup createBranch(){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
45 BranchGroup scene = new BranchGroup();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
46 Box box = new Box(0.1f,0.1f,0.0f,
91
19f3bd33277d add KeyInput
sugi
parents: 89
diff changeset
47 Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance());
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
48 transform_group = new TransformGroup();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
49 transform_group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
50 transform_group.addChild(box);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
51 scene.addChild(transform_group);
89
e269cedd8bae Test two fish
sugi
parents: 88
diff changeset
52 setLocation(-10,0);//default position
88
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
53 return scene;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
54
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
55 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
56
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
57 private Appearance createAppearance(){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
58 System.out.println(new File(".").getAbsolutePath());
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
59 Appearance app = new Appearance();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
60 Image image = null;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
61 Toolkit toolkit = Toolkit.getDefaultToolkit();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
62 //image = toolkit.getImage("image/fish.jpg");
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
63 image = toolkit.getImage("../image/fish.jpg");//jar
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
64 MediaTracker mt = new MediaTracker(canvas);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
65 mt.addImage(image, 0);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
66 mt.checkAll(true);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
67 try {
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
68 mt.waitForID(0);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
69
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
70 }catch (InterruptedException e){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
71 e.printStackTrace();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
72
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
73 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
74 Texture texture = new TextureLoader(image,canvas).getTexture();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
75 app.setTexture(texture);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
76 return app;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
77
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
78 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
79
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
80 public void setLocation(float x,float y){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
81 transform = new Transform3D();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
82 vector = new Vector3f(x,y,0.0f);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
83 transform.setTranslation(vector);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
84 transform_group.setTransform(transform);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
85 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
86 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
87