Mercurial > hg > jslab
diff examples/java3d/hello11.java @ 1:5df24c91468d
Oh my what a mess.
author | samer |
---|---|
date | Fri, 05 Apr 2019 16:26:00 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/java3d/hello11.java Fri Apr 05 16:26:00 2019 +0100 @@ -0,0 +1,105 @@ +/* + hello6.java + + Construct universe without using SimpleUniverse + utility class - this puts together the view + group explicitly. + + Now has dynamically creatable views. + Have to construct views on BranchGroups so they + can be added while universe is live? + + immediate mode + */ + +import samer.core.*; +import samer.core.types.*; +import samer.tools.*; + +import java.awt.event.*; +import javax.media.j3d.*; +import javax.vecmath.*; + +public class hello11 extends util implements Agent +{ + // create universe + LocalUniverse U=new LocalUniverse(); + BranchGroup root=new BranchGroup(); + TaskThread tasks=new TaskThread(); + Geometry geom; + Appearance app; + + public static void main(String[] arse) { + init(); new hello11(); + Shell.interpret("expose"); + } + + public hello11() + { + // create scene + geom = yoyoGeometryInfo(128).getGeometryArray(); + app = pointy2(); + + root.addChild(new TransformGroup()); + root.addChild(new view("view")); + root.setCapability(Group.ALLOW_CHILDREN_EXTEND); + root.setCapability(Group.ALLOW_CHILDREN_WRITE); + root.compile(); + + U.addGroup(root); + + Shell.registerAgent(this); + Shell.exposeCommands(this); + } + + public void getCommands(Agent.Registry r) { r.add("view"); } + + public void execute(String cmd, Environment env) throws Exception + { + if (cmd.equals("view")) { + root.addChild(new view(X.string(env.datum("name"),"view"))); + } + } + + + private class view extends Viewer implements Task + { + GraphicsContext3D gc; + float angle=0; + Transform3D mt=new Transform3D(); + VDouble speed; + + public view(String name) + { + super( name); // great mate + // lookFrom(new Point3d(0,0,8),new Vector3d(0,1,0)); + canvas.stopRenderer(); + tasks.addTask(this); + + Shell.push(node); + speed=new VDouble("speed",0.1); + Shell.pop(); + } + + public void run() + { + mt.rotY(angle+=speed.value); + gc.clear(); + gc.setModelTransform(mt); + gc.draw(geom); + canvas.swap(); + } + + public void dispose() { + tasks.removeTask(this); + super.dispose(); + } + + public void stopping() { Shell.print("view stopping"); } + public void starting() { + Shell.print("view starting"); + if (gc==null) gc = canvas.getGraphicsContext3D(); + gc.setAppearance(app); + } + } +} \ No newline at end of file