annotate examples/java3d/hello10.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 hello10.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 picking
samer@1 13 */
samer@1 14
samer@1 15 import samer.core.*;
samer@1 16 import java.awt.event.*;
samer@1 17 import javax.media.j3d.*;
samer@1 18 import javax.vecmath.*;
samer@1 19
samer@1 20 public class hello10 extends util implements Agent
samer@1 21 {
samer@1 22 // create universe
samer@1 23 LocalUniverse U=new LocalUniverse();
samer@1 24 BranchGroup root=new BranchGroup();
samer@1 25
samer@1 26 public static void main(String[] arse) { init(); new hello10(); }
samer@1 27
samer@1 28 public hello10()
samer@1 29 {
samer@1 30 Viewer v=new Viewer("view");
samer@1 31
samer@1 32 // v.lookFrom(new Point3d(0,0,8),new Vector3d(0,1,0));
samer@1 33
samer@1 34 // create scene
samer@1 35 root.addChild(createSceneGraph());
samer@1 36 root.addChild(v);
samer@1 37 root.setCapability(Group.ALLOW_CHILDREN_EXTEND);
samer@1 38 root.setCapability(Group.ALLOW_CHILDREN_WRITE);
samer@1 39
samer@1 40 /*
samer@1 41 tg.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
samer@1 42 PickRotateBehavior pr=new PickRotateBehavior(objroot, canvas, bounds);
samer@1 43 objroot.addChild(pickRotate);
samer@1 44 */
samer@1 45
samer@1 46 root.compile();
samer@1 47
samer@1 48 U.addGroup(root);
samer@1 49
samer@1 50 Shell.registerAgent(this);
samer@1 51 Shell.exposeCommands(this);
samer@1 52 }
samer@1 53
samer@1 54 public void getCommands(Agent.Registry r) {
samer@1 55 r.add("view");
samer@1 56 r.setTarget(null); r.add("start").add("stop");
samer@1 57 }
samer@1 58
samer@1 59 public void execute(String cmd, Environment env) throws Exception
samer@1 60 {
samer@1 61 if (cmd.equals("view")) {
samer@1 62 root.addChild(new Viewer(X.string(env.datum("name"),"view")));
samer@1 63 }
samer@1 64 }
samer@1 65
samer@1 66 private static TransformGroup createSceneGraph()
samer@1 67 {
samer@1 68 Transform3D r=new Transform3D();
samer@1 69 //r.rotX(Math.PI/2);
samer@1 70 r.setScale(0.5);
samer@1 71 TransformGroup t2=new TransformGroup(r);
samer@1 72 t2.addChild( yoyoGroup(
samer@1 73 yoyoGeometryInfo(12).getGeometryArray(),
samer@1 74 wireframe2(),
samer@1 75 pointy()));
samer@1 76
samer@1 77 TransformGroup tg = new TransformGroup();
samer@1 78 // addRotator(tg);
samer@1 79 mouseRotate(tg);
samer@1 80 mouseTranslate(tg);
samer@1 81 mouseZoom(tg);
samer@1 82 tg.addChild(t2);
samer@1 83 return tg;
samer@1 84 }
samer@1 85 }