Mercurial > hg > jslab
diff examples/java3d/hello8.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/hello8.java Fri Apr 05 16:26:00 2019 +0100 @@ -0,0 +1,149 @@ +/* + hello8.java + + Construct universe without using SimpleUniverse + utility class - this puts together the view + group explicitly. + + Stereo pairs using 2 views in one window + */ + +import samer.core.*; +import java.awt.event.*; +import java.awt.*; +import javax.media.j3d.*; +import javax.vecmath.*; + +public class hello8 extends util implements Agent +{ + // create universe + LocalUniverse U=new LocalUniverse(); + BranchGroup root=new BranchGroup(); + ViewPlatform VP=new ViewPlatform(); + + public static void main(String[] arse) { init(); new hello8(); } + + public hello8() + { + // create scene + root.addChild(createSceneGraph()); + // addBackground(root,new Background(0.1f,0.2f,0.15f)); + // addLights(root); + + { // view platform placement + TransformGroup VT=new TransformGroup(); + Transform3D t=new Transform3D(); + + t.lookAt(new Point3d(0,16,20), new Point3d(0,0,0),new Vector3d(0,1,0)); + t.invert(); + VT.setTransform(t); + + // !!! all key navigators seem to be slaved! + addKeyNavigator(VT,readwrite(VT)); + VT.addChild(VP); + root.addChild(VT); + } + // setCapability(ALLOW_DETACH); + // setCapability(ALLOW_CHILDREN_WRITE); + // compile(); + + + // add two Views on same platform + new stereoview(VP); + + // 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"); + r.setTarget(null); r.add("start").add("stop"); + } + + public void execute(String cmd, Environment env) throws Exception + { + if (cmd.equals("view")) new stereoview(VP); + } + + private static TransformGroup createSceneGraph() + { + Transform3D r=new Transform3D(); + // r.rotX(Math.PI/2); + // r.setScale(0.5); + TransformGroup t2=new TransformGroup(r); + t2.addChild(yoyoGroup()); + + TransformGroup tg = new TransformGroup(); + addRotator(tg); + tg.addChild(t2); + return tg; + } + + class stereoview implements Agent + { + eyeview left,right; + Shell.Window win; + + + public stereoview(ViewPlatform VP) + { + left=new eyeview(VP); + right=new eyeview(VP); + + left.setMonoscopicViewPolicy(View.LEFT_EYE_VIEW); + right.setMonoscopicViewPolicy(View.RIGHT_EYE_VIEW); + + win=Shell.getWindow("stereo"); + win.container().setLayout(new GridLayout(1,2)); + win.container().add(right.canvas); + win.container().add(left.canvas); + win.expose(); + win.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { dispose(); } + }); + + Shell.registerAgent(this); + } + + public void dispose() + { + Shell.deregisterAgent(this); + win.dispose(); + } + + protected void finalize() { Shell.trace("finalizing view "+this); } + + public void getCommands(Agent.Registry r) { r.add("start").add("stop"); } + public void execute(String cmd, Environment env) { + if (cmd.equals("start")) { left.startView(); right.startView(); } + else if (cmd.equals("stop")) { left.stopView(); right.stopView(); } + } + } + + public class eyeview extends View + { + Canvas3D canvas; + + public eyeview(ViewPlatform VP) + { + // create view bits + canvas=new Canvas3D(getGraphicsConfiguration()); + + addCanvas3D(canvas); + setPhysicalBody(new PhysicalBody()); + setPhysicalEnvironment(new PhysicalEnvironment()); + setWindowEyepointPolicy(View.RELATIVE_TO_WINDOW); + // setWindowResizePolicy(View.VIRTUAL_WORLD); + // setWindowMovementPolicy(View.VIRTUAL_WORLD); + setFrontClipDistance(0.1); + setBackClipDistance(20); + attachViewPlatform(VP); + } + } +} \ No newline at end of file