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