Mercurial > hg > jslab
comparison examples/java3d/hello11.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 hello6.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. | |
9 Have to construct views on BranchGroups so they | |
10 can be added while universe is live? | |
11 | |
12 immediate mode | |
13 */ | |
14 | |
15 import samer.core.*; | |
16 import samer.core.types.*; | |
17 import samer.tools.*; | |
18 | |
19 import java.awt.event.*; | |
20 import javax.media.j3d.*; | |
21 import javax.vecmath.*; | |
22 | |
23 public class hello11 extends util implements Agent | |
24 { | |
25 // create universe | |
26 LocalUniverse U=new LocalUniverse(); | |
27 BranchGroup root=new BranchGroup(); | |
28 TaskThread tasks=new TaskThread(); | |
29 Geometry geom; | |
30 Appearance app; | |
31 | |
32 public static void main(String[] arse) { | |
33 init(); new hello11(); | |
34 Shell.interpret("expose"); | |
35 } | |
36 | |
37 public hello11() | |
38 { | |
39 // create scene | |
40 geom = yoyoGeometryInfo(128).getGeometryArray(); | |
41 app = pointy2(); | |
42 | |
43 root.addChild(new TransformGroup()); | |
44 root.addChild(new view("view")); | |
45 root.setCapability(Group.ALLOW_CHILDREN_EXTEND); | |
46 root.setCapability(Group.ALLOW_CHILDREN_WRITE); | |
47 root.compile(); | |
48 | |
49 U.addGroup(root); | |
50 | |
51 Shell.registerAgent(this); | |
52 Shell.exposeCommands(this); | |
53 } | |
54 | |
55 public void getCommands(Agent.Registry r) { r.add("view"); } | |
56 | |
57 public void execute(String cmd, Environment env) throws Exception | |
58 { | |
59 if (cmd.equals("view")) { | |
60 root.addChild(new view(X.string(env.datum("name"),"view"))); | |
61 } | |
62 } | |
63 | |
64 | |
65 private class view extends Viewer implements Task | |
66 { | |
67 GraphicsContext3D gc; | |
68 float angle=0; | |
69 Transform3D mt=new Transform3D(); | |
70 VDouble speed; | |
71 | |
72 public view(String name) | |
73 { | |
74 super( name); // great mate | |
75 // lookFrom(new Point3d(0,0,8),new Vector3d(0,1,0)); | |
76 canvas.stopRenderer(); | |
77 tasks.addTask(this); | |
78 | |
79 Shell.push(node); | |
80 speed=new VDouble("speed",0.1); | |
81 Shell.pop(); | |
82 } | |
83 | |
84 public void run() | |
85 { | |
86 mt.rotY(angle+=speed.value); | |
87 gc.clear(); | |
88 gc.setModelTransform(mt); | |
89 gc.draw(geom); | |
90 canvas.swap(); | |
91 } | |
92 | |
93 public void dispose() { | |
94 tasks.removeTask(this); | |
95 super.dispose(); | |
96 } | |
97 | |
98 public void stopping() { Shell.print("view stopping"); } | |
99 public void starting() { | |
100 Shell.print("view starting"); | |
101 if (gc==null) gc = canvas.getGraphicsContext3D(); | |
102 gc.setAppearance(app); | |
103 } | |
104 } | |
105 } |