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