annotate src/alice/test/topology/movement/MakeObject.java @ 88:33a19ca88e43 working

Singleton is removed .
author sugi
date Mon, 04 Jun 2012 16:08:53 +0900
parents
children e269cedd8bae
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
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
27 public MakeObject(Canvas3D C){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
28 this.canvas = C;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
29 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
30
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
31 public MakeObject(Canvas3D C,KeyInput K){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
32 this.canvas = C;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
33 this.key = K;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
34 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
35
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
36 public BranchGroup createBranch(){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
37 BranchGroup scene = new BranchGroup();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
38 Box box = new Box(0.1f,0.1f,0.0f,
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
39 Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance());
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
40
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
41 transform_group = new TransformGroup();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
42 transform_group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
43 transform_group.addChild(box);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
44 scene.addChild(transform_group);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
45
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
46
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
47 /*
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
48 key.transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
49 key.transformGroup.addChild(box);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
50 scene.addChild(key.transformGroup);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
51 */
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
52 return scene;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
53
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 private Appearance createAppearance(){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
57 System.out.println(new File(".").getAbsolutePath());
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
58 Appearance app = new Appearance();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
59 Image image = null;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
60 Toolkit toolkit = Toolkit.getDefaultToolkit();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
61 //image = toolkit.getImage("image/fish.jpg");
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
62 image = toolkit.getImage("../image/fish.jpg");//jar
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
63 MediaTracker mt = new MediaTracker(canvas);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
64 mt.addImage(image, 0);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
65 mt.checkAll(true);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
66 try {
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
67 mt.waitForID(0);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
68
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
69 }catch (InterruptedException e){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
70 e.printStackTrace();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
71
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
72 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
73 Texture texture = new TextureLoader(image,canvas).getTexture();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
74 app.setTexture(texture);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
75 return app;
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
76
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 public void setLocation(float x,float y){
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
80 transform = new Transform3D();
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
81 vector = new Vector3f(x,y,0.0f);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
82 transform.setTranslation(vector);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
83 transform_group.setTransform(transform);
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
84 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
85 }
33a19ca88e43 Singleton is removed .
sugi
parents:
diff changeset
86