comparison examples/java3d/hello5.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 hello5.java
3
4 Construct universe without using SimpleUniverse
5 utility class - this puts together the view
6 group explicitly.
7
8 */
9
10 import samer.core.*;
11 import javax.media.j3d.*;
12 import javax.vecmath.*;
13
14 public class hello5 extends util implements Agent
15 {
16 Canvas3D canvas;
17
18 public static void main(String[] args) { init(); new hello5(); }
19
20 public hello5()
21 {
22 // create universe
23 LocalUniverse U=new LocalUniverse();
24 BranchGroup root=new BranchGroup();
25
26 // create scene
27 root.addChild(createSceneGraph());
28 // addBackground(root,new Background(0.1f,0.2f,0.15f));
29 // addLights(root);
30
31 // create view bits
32 canvas=new Canvas3D(getGraphicsConfiguration());
33
34 TransformGroup VT=new TransformGroup();
35 ViewPlatform VP=new ViewPlatform();
36 View V=new View();
37
38 {
39 Transform3D t=new Transform3D();
40 t.set(new Vector3d(0.0,0.0,8.0));
41 VT.setTransform(t);
42 }
43
44 addKeyNavigator(VT,readwrite(VT));
45 VT.addChild(VP);
46 V.addCanvas3D(canvas);
47 V.attachViewPlatform(VP);
48 V.setPhysicalBody(new PhysicalBody());
49 V.setPhysicalEnvironment(new PhysicalEnvironment());
50
51 root.addChild(VT);
52 root.compile();
53
54 Shell.registerAgent(this);
55 Shell.exposeCommands(this);
56
57 // setViewPolicy(canvas.getView());
58 expose(canvas,"hello");
59 U.addGroup(root);
60 }
61
62 private static TransformGroup createSceneGraph()
63 {
64 Transform3D r=new Transform3D();
65 r.rotX(Math.PI/2);
66 TransformGroup t2=new TransformGroup(r);
67 t2.addChild(yoyoGroup());
68
69 TransformGroup tg = new TransformGroup();
70 addRotator(tg);
71 tg.addChild(t2);
72 return tg;
73 }
74
75 public void getCommands(Agent.Registry r) { r.add("start").add("stop"); }
76 public void execute(String cmd, Environment env) {
77 if (cmd.equals("start")) { canvas.startRenderer(); }
78 else if (cmd.equals("stop")) { canvas.stopRenderer(); }
79 }
80
81 }