samer@1
|
1 /*
|
samer@1
|
2 hello6.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 Now has dynamically creatable views.
|
samer@1
|
9 Have to construct views on BranchGroups so they
|
samer@1
|
10 can be added while universe is live?
|
samer@1
|
11 */
|
samer@1
|
12
|
samer@1
|
13 import samer.core.*;
|
samer@1
|
14 import java.awt.event.*;
|
samer@1
|
15 import javax.media.j3d.*;
|
samer@1
|
16 import javax.vecmath.*;
|
samer@1
|
17
|
samer@1
|
18 public class hello6 extends util implements Agent
|
samer@1
|
19 {
|
samer@1
|
20 // create universe
|
samer@1
|
21 LocalUniverse U=new LocalUniverse();
|
samer@1
|
22 BranchGroup root=new BranchGroup();
|
samer@1
|
23
|
samer@1
|
24 public static void main(String[] arse) { init(); new hello6(); }
|
samer@1
|
25
|
samer@1
|
26 public hello6()
|
samer@1
|
27 {
|
samer@1
|
28 // create scene
|
samer@1
|
29 root.addChild(createSceneGraph());
|
samer@1
|
30 // addBackground(root,new Background(0.1f,0.2f,0.15f));
|
samer@1
|
31 // addLights(root);
|
samer@1
|
32 root.addChild(new FPS(200));
|
samer@1
|
33
|
samer@1
|
34 root.addChild(new Viewer("view"));
|
samer@1
|
35 root.setCapability(Group.ALLOW_CHILDREN_EXTEND);
|
samer@1
|
36 root.setCapability(Group.ALLOW_CHILDREN_WRITE);
|
samer@1
|
37 root.compile();
|
samer@1
|
38
|
samer@1
|
39 U.addGroup(root);
|
samer@1
|
40
|
samer@1
|
41 Shell.registerAgent(this);
|
samer@1
|
42 Shell.exposeCommands(this);
|
samer@1
|
43 }
|
samer@1
|
44
|
samer@1
|
45 public void getCommands(Agent.Registry r) {
|
samer@1
|
46 r.add("view");
|
samer@1
|
47 r.setTarget(null); r.add("start").add("stop");
|
samer@1
|
48 }
|
samer@1
|
49
|
samer@1
|
50 public void execute(String cmd, Environment env) throws Exception
|
samer@1
|
51 {
|
samer@1
|
52 if (cmd.equals("view")) {
|
samer@1
|
53 root.addChild(new Viewer(X.string(env.datum("name"),"view")));
|
samer@1
|
54 }
|
samer@1
|
55 }
|
samer@1
|
56
|
samer@1
|
57 private static TransformGroup createSceneGraph()
|
samer@1
|
58 {
|
samer@1
|
59 Transform3D r=new Transform3D();
|
samer@1
|
60 r.rotX(Math.PI/2);
|
samer@1
|
61 TransformGroup t2=new TransformGroup(r);
|
samer@1
|
62 t2.addChild(yoyoGroup());
|
samer@1
|
63
|
samer@1
|
64 TransformGroup tg = new TransformGroup();
|
samer@1
|
65 addRotator(tg);
|
samer@1
|
66 tg.addChild(t2);
|
samer@1
|
67 return tg;
|
samer@1
|
68 }
|
samer@1
|
69 } |