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