samer@1
|
1 /*
|
samer@1
|
2 hello5.java
|
samer@1
|
3
|
samer@1
|
4 Construct universe without using SimpleUniverse
|
samer@1
|
5 utility class - this puts together the view
|
samer@1
|
6 group explicitly.
|
samer@1
|
7
|
samer@1
|
8 */
|
samer@1
|
9
|
samer@1
|
10 import samer.core.*;
|
samer@1
|
11 import javax.media.j3d.*;
|
samer@1
|
12 import javax.vecmath.*;
|
samer@1
|
13
|
samer@1
|
14 public class hello5 extends util implements Agent
|
samer@1
|
15 {
|
samer@1
|
16 Canvas3D canvas;
|
samer@1
|
17
|
samer@1
|
18 public static void main(String[] args) { init(); new hello5(); }
|
samer@1
|
19
|
samer@1
|
20 public hello5()
|
samer@1
|
21 {
|
samer@1
|
22 // create universe
|
samer@1
|
23 LocalUniverse U=new LocalUniverse();
|
samer@1
|
24 BranchGroup root=new BranchGroup();
|
samer@1
|
25
|
samer@1
|
26 // create scene
|
samer@1
|
27 root.addChild(createSceneGraph());
|
samer@1
|
28 // addBackground(root,new Background(0.1f,0.2f,0.15f));
|
samer@1
|
29 // addLights(root);
|
samer@1
|
30
|
samer@1
|
31 // create view bits
|
samer@1
|
32 canvas=new Canvas3D(getGraphicsConfiguration());
|
samer@1
|
33
|
samer@1
|
34 TransformGroup VT=new TransformGroup();
|
samer@1
|
35 ViewPlatform VP=new ViewPlatform();
|
samer@1
|
36 View V=new View();
|
samer@1
|
37
|
samer@1
|
38 {
|
samer@1
|
39 Transform3D t=new Transform3D();
|
samer@1
|
40 t.set(new Vector3d(0.0,0.0,8.0));
|
samer@1
|
41 VT.setTransform(t);
|
samer@1
|
42 }
|
samer@1
|
43
|
samer@1
|
44 addKeyNavigator(VT,readwrite(VT));
|
samer@1
|
45 VT.addChild(VP);
|
samer@1
|
46 V.addCanvas3D(canvas);
|
samer@1
|
47 V.attachViewPlatform(VP);
|
samer@1
|
48 V.setPhysicalBody(new PhysicalBody());
|
samer@1
|
49 V.setPhysicalEnvironment(new PhysicalEnvironment());
|
samer@1
|
50
|
samer@1
|
51 root.addChild(VT);
|
samer@1
|
52 root.compile();
|
samer@1
|
53
|
samer@1
|
54 Shell.registerAgent(this);
|
samer@1
|
55 Shell.exposeCommands(this);
|
samer@1
|
56
|
samer@1
|
57 // setViewPolicy(canvas.getView());
|
samer@1
|
58 expose(canvas,"hello");
|
samer@1
|
59 U.addGroup(root);
|
samer@1
|
60 }
|
samer@1
|
61
|
samer@1
|
62 private static TransformGroup createSceneGraph()
|
samer@1
|
63 {
|
samer@1
|
64 Transform3D r=new Transform3D();
|
samer@1
|
65 r.rotX(Math.PI/2);
|
samer@1
|
66 TransformGroup t2=new TransformGroup(r);
|
samer@1
|
67 t2.addChild(yoyoGroup());
|
samer@1
|
68
|
samer@1
|
69 TransformGroup tg = new TransformGroup();
|
samer@1
|
70 addRotator(tg);
|
samer@1
|
71 tg.addChild(t2);
|
samer@1
|
72 return tg;
|
samer@1
|
73 }
|
samer@1
|
74
|
samer@1
|
75 public void getCommands(Agent.Registry r) { r.add("start").add("stop"); }
|
samer@1
|
76 public void execute(String cmd, Environment env) {
|
samer@1
|
77 if (cmd.equals("start")) { canvas.startRenderer(); }
|
samer@1
|
78 else if (cmd.equals("stop")) { canvas.stopRenderer(); }
|
samer@1
|
79 }
|
samer@1
|
80
|
samer@1
|
81 } |