samer@1: /* samer@1: hello6.java samer@1: samer@1: Construct universe without using SimpleUniverse samer@1: utility class - this puts together the view samer@1: group explicitly. samer@1: samer@1: Now has dynamically creatable views. samer@1: Have to construct views on BranchGroups so they samer@1: can be added while universe is live? samer@1: samer@1: immediate mode samer@1: */ samer@1: samer@1: import samer.core.*; samer@1: import samer.core.types.*; samer@1: import samer.tools.*; samer@1: samer@1: import java.awt.event.*; samer@1: import javax.media.j3d.*; samer@1: import javax.vecmath.*; samer@1: samer@1: public class hello11 extends util implements Agent samer@1: { samer@1: // create universe samer@1: LocalUniverse U=new LocalUniverse(); samer@1: BranchGroup root=new BranchGroup(); samer@1: TaskThread tasks=new TaskThread(); samer@1: Geometry geom; samer@1: Appearance app; samer@1: samer@1: public static void main(String[] arse) { samer@1: init(); new hello11(); samer@1: Shell.interpret("expose"); samer@1: } samer@1: samer@1: public hello11() samer@1: { samer@1: // create scene samer@1: geom = yoyoGeometryInfo(128).getGeometryArray(); samer@1: app = pointy2(); samer@1: samer@1: root.addChild(new TransformGroup()); samer@1: root.addChild(new view("view")); samer@1: root.setCapability(Group.ALLOW_CHILDREN_EXTEND); samer@1: root.setCapability(Group.ALLOW_CHILDREN_WRITE); samer@1: root.compile(); samer@1: samer@1: U.addGroup(root); samer@1: samer@1: Shell.registerAgent(this); samer@1: Shell.exposeCommands(this); samer@1: } samer@1: samer@1: public void getCommands(Agent.Registry r) { r.add("view"); } samer@1: samer@1: public void execute(String cmd, Environment env) throws Exception samer@1: { samer@1: if (cmd.equals("view")) { samer@1: root.addChild(new view(X.string(env.datum("name"),"view"))); samer@1: } samer@1: } samer@1: samer@1: samer@1: private class view extends Viewer implements Task samer@1: { samer@1: GraphicsContext3D gc; samer@1: float angle=0; samer@1: Transform3D mt=new Transform3D(); samer@1: VDouble speed; samer@1: samer@1: public view(String name) samer@1: { samer@1: super( name); // great mate samer@1: // lookFrom(new Point3d(0,0,8),new Vector3d(0,1,0)); samer@1: canvas.stopRenderer(); samer@1: tasks.addTask(this); samer@1: samer@1: Shell.push(node); samer@1: speed=new VDouble("speed",0.1); samer@1: Shell.pop(); samer@1: } samer@1: samer@1: public void run() samer@1: { samer@1: mt.rotY(angle+=speed.value); samer@1: gc.clear(); samer@1: gc.setModelTransform(mt); samer@1: gc.draw(geom); samer@1: canvas.swap(); samer@1: } samer@1: samer@1: public void dispose() { samer@1: tasks.removeTask(this); samer@1: super.dispose(); samer@1: } samer@1: samer@1: public void stopping() { Shell.print("view stopping"); } samer@1: public void starting() { samer@1: Shell.print("view starting"); samer@1: if (gc==null) gc = canvas.getGraphicsContext3D(); samer@1: gc.setAppearance(app); samer@1: } samer@1: } samer@1: }