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