annotate examples/java3d/hello11.java @ 8:5e3cbbf173aa tip

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