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