samer@1
|
1 /*
|
samer@1
|
2 hello7.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 all on the same
|
samer@1
|
9 view platform. Left and right eye views available!
|
samer@1
|
10 */
|
samer@1
|
11
|
samer@1
|
12 import samer.core.*;
|
samer@1
|
13 import java.awt.event.*;
|
samer@1
|
14 import javax.media.j3d.*;
|
samer@1
|
15 import javax.vecmath.*;
|
samer@1
|
16
|
samer@1
|
17 import samer.core.Node;
|
samer@1
|
18
|
samer@1
|
19 public class hello7 extends util implements Agent
|
samer@1
|
20 {
|
samer@1
|
21 // create universe
|
samer@1
|
22 LocalUniverse U=new LocalUniverse();
|
samer@1
|
23 BranchGroup root=new BranchGroup();
|
samer@1
|
24 ViewPlatform VP=new ViewPlatform();
|
samer@1
|
25
|
samer@1
|
26 public static void main(String[] arse) { init(); new hello7(); }
|
samer@1
|
27
|
samer@1
|
28 public hello7()
|
samer@1
|
29 {
|
samer@1
|
30 // create scene
|
samer@1
|
31 root.addChild(createSceneGraph());
|
samer@1
|
32 // addBackground(root,new Background(0.1f,0.2f,0.15f));
|
samer@1
|
33 // addLights(root);
|
samer@1
|
34
|
samer@1
|
35 { // view platform placement
|
samer@1
|
36 TransformGroup VT=new TransformGroup();
|
samer@1
|
37 Transform3D t=new Transform3D();
|
samer@1
|
38
|
samer@1
|
39 t.lookAt(new Point3d(0,16,20), new Point3d(0,0,0),new Vector3d(0,1,0));
|
samer@1
|
40 t.invert();
|
samer@1
|
41 VT.setTransform(t);
|
samer@1
|
42
|
samer@1
|
43 // !!! all key navigators seem to be slaved!
|
samer@1
|
44 addKeyNavigator(VT,readwrite(VT));
|
samer@1
|
45 VT.addChild(VP);
|
samer@1
|
46 root.addChild(VT);
|
samer@1
|
47 }
|
samer@1
|
48 // setCapability(ALLOW_DETACH);
|
samer@1
|
49 // setCapability(ALLOW_CHILDREN_WRITE);
|
samer@1
|
50 // compile();
|
samer@1
|
51
|
samer@1
|
52
|
samer@1
|
53 // add two Views on same platform
|
samer@1
|
54 new view("left",VP);
|
samer@1
|
55 new view("right",VP);
|
samer@1
|
56
|
samer@1
|
57 // root.setCapability(Group.ALLOW_CHILDREN_EXTEND);
|
samer@1
|
58 // root.setCapability(Group.ALLOW_CHILDREN_WRITE);
|
samer@1
|
59 root.compile();
|
samer@1
|
60
|
samer@1
|
61 U.addGroup(root);
|
samer@1
|
62
|
samer@1
|
63 Shell.registerAgent(this);
|
samer@1
|
64 Shell.exposeCommands(this);
|
samer@1
|
65 }
|
samer@1
|
66
|
samer@1
|
67 public void getCommands(Agent.Registry r) {
|
samer@1
|
68 r.add("view");
|
samer@1
|
69 r.setTarget(null); r.add("start").add("stop");
|
samer@1
|
70 }
|
samer@1
|
71
|
samer@1
|
72 public void execute(String cmd, Environment env) throws Exception
|
samer@1
|
73 {
|
samer@1
|
74 if (cmd.equals("view")) {
|
samer@1
|
75 new view(X.string(env.datum("name"),"view"),VP);
|
samer@1
|
76 }
|
samer@1
|
77 }
|
samer@1
|
78
|
samer@1
|
79 private static TransformGroup createSceneGraph()
|
samer@1
|
80 {
|
samer@1
|
81 Transform3D r=new Transform3D();
|
samer@1
|
82 // r.rotX(Math.PI/2);
|
samer@1
|
83 TransformGroup t2=new TransformGroup(r);
|
samer@1
|
84 t2.addChild(yoyoGroup());
|
samer@1
|
85
|
samer@1
|
86 TransformGroup tg = new TransformGroup();
|
samer@1
|
87 addRotator(tg);
|
samer@1
|
88 tg.addChild(t2);
|
samer@1
|
89 return tg;
|
samer@1
|
90 }
|
samer@1
|
91
|
samer@1
|
92 public class view extends View implements Agent
|
samer@1
|
93 {
|
samer@1
|
94 Node node;
|
samer@1
|
95 Canvas3D canvas;
|
samer@1
|
96 Shell.Window win;
|
samer@1
|
97
|
samer@1
|
98 public view(String name, ViewPlatform VP)
|
samer@1
|
99 {
|
samer@1
|
100 node = new Node(name);
|
samer@1
|
101 Shell.push(node);
|
samer@1
|
102
|
samer@1
|
103 // create view bits
|
samer@1
|
104 canvas=new Canvas3D(getGraphicsConfiguration());
|
samer@1
|
105 //if (name.equals("left")) canvas.setMonoscopicViewPolicy(Canvas3D.LEFT_EYE);
|
samer@1
|
106 //else if (name.equals("right")) canvas.setMonoscopicViewPolicy(Canvas3D.RIGHT_EYE);
|
samer@1
|
107
|
samer@1
|
108 addCanvas3D(canvas);
|
samer@1
|
109 setPhysicalBody(new PhysicalBody());
|
samer@1
|
110 setPhysicalEnvironment(new PhysicalEnvironment());
|
samer@1
|
111 setWindowEyepointPolicy(View.RELATIVE_TO_WINDOW);
|
samer@1
|
112 //setWindowResizePolicy(View.VIRTUAL_WORLD);
|
samer@1
|
113 setFrontClipDistance(Shell.getDouble("front",1));
|
samer@1
|
114 setBackClipDistance(Shell.getDouble("back",10));
|
samer@1
|
115
|
samer@1
|
116 if (name.equals("left")) setMonoscopicViewPolicy(LEFT_EYE_VIEW);
|
samer@1
|
117 else if (name.equals("right")) setMonoscopicViewPolicy(RIGHT_EYE_VIEW);
|
samer@1
|
118
|
samer@1
|
119 attachViewPlatform(VP);
|
samer@1
|
120
|
samer@1
|
121 Shell.pop();
|
samer@1
|
122
|
samer@1
|
123 win=Shell.getWindow(name);
|
samer@1
|
124 win.container().add(canvas);
|
samer@1
|
125 win.expose();
|
samer@1
|
126 win.addWindowListener(new WindowAdapter() {
|
samer@1
|
127 public void windowClosing(WindowEvent e) { dispose(); }
|
samer@1
|
128 });
|
samer@1
|
129
|
samer@1
|
130 Shell.registerAgent(this);
|
samer@1
|
131 }
|
samer@1
|
132
|
samer@1
|
133 public void dispose()
|
samer@1
|
134 {
|
samer@1
|
135 // stopView();
|
samer@1
|
136 Shell.deregisterAgent(this);
|
samer@1
|
137 win.dispose();
|
samer@1
|
138 }
|
samer@1
|
139
|
samer@1
|
140 protected void finalize() { Shell.trace("finalizing view "+this); }
|
samer@1
|
141
|
samer@1
|
142 public void getCommands(Agent.Registry r) { r.add("start").add("stop"); }
|
samer@1
|
143 public void execute(String cmd, Environment env) {
|
samer@1
|
144 if (cmd.equals("start")) { startView(); }
|
samer@1
|
145 else if (cmd.equals("stop")) { stopView(); }
|
samer@1
|
146 }
|
samer@1
|
147 }
|
samer@1
|
148 } |