annotate src/samer/j3d/ViewBase.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
rev   line source
samer@0 1 /**
samer@0 2 ViewGroup.java
samer@0 3
samer@0 4 A View branch group containing a ViewPlatform
samer@0 5 and associated Views, Canvas3Ds and Windows to
samer@0 6 hold the canvases. Can be added dynamically
samer@0 7 to a live universe.
samer@0 8
samer@0 9 Parameters:
samer@0 10 initial placement
samer@0 11 autostart canvas?
samer@0 12 autostart view?
samer@0 13 keyboard navigator?
samer@0 14 various view policies
samer@0 15
samer@0 16 Requirements:
samer@0 17 must be placable (hence TransformGroup and ViewPlatform)
samer@0 18 must be Node so addable to universe
samer@0 19 renderable:
samer@0 20 view.renderOnce()
samer@0 21 view.startView()
samer@0 22 view.stopView()
samer@0 23 canvas.startRenderer()
samer@0 24 canvas.stopRenderer()
samer@0 25 ... ?
samer@0 26 disposable: cleans up properly
samer@0 27 must have accessible View and Canvas objects
samer@0 28 must manage multiple canvases for stereo
samer@0 29
samer@0 30 */
samer@0 31 package samer.j3d;
samer@0 32
samer@0 33 import samer.core.*;
samer@0 34 import samer.tools.*;
samer@0 35 import java.awt.*;
samer@0 36 import java.awt.event.*;
samer@0 37 import javax.media.j3d.*;
samer@0 38 import javax.vecmath.*;
samer@0 39
samer@0 40
samer@0 41 public class ViewBase extends javax.media.j3d.View implements Agent, WindowListener, Task
samer@0 42 {
samer@0 43 public ViewBase()
samer@0 44 {
samer@0 45 stopView(); // seems be started during constructor
samer@0 46
samer@0 47 PhysicalBody body=new PhysicalBody();
samer@0 48 PhysicalEnvironment env=new PhysicalEnvironment();
samer@0 49 double d=Shell.getDouble("eyeSeparation",0.01); // units??
samer@0 50 body.setLeftEyePosition(new Point3d(-d,0,0));
samer@0 51 body.setRightEyePosition(new Point3d(d,0,0));
samer@0 52 body.setNominalEyeHeightFromGround(0);
samer@0 53
samer@0 54 // canvas.getStereoAvailable()
samer@0 55 // canvas.setStereoEnable
samer@0 56 // queryProperties
samer@0 57
samer@0 58 setPhysicalBody(body);
samer@0 59 setPhysicalEnvironment(env);
samer@0 60
samer@0 61 setWindowEyepointPolicy(View.RELATIVE_TO_WINDOW);
samer@0 62 //setWindowResizePolicy(View.VIRTUAL_WORLD);
samer@0 63 //setLocalEyeLightingEnable(true);
samer@0 64 //setWindowMovementPolicy(View.VIRTUAL_WORLD);
samer@0 65 setFrontClipDistance(Shell.getDouble("front",0.5));
samer@0 66 setBackClipDistance(Shell.getDouble("back",20));
samer@0 67 setDepthBufferFreezeTransparent(true);
samer@0 68 // Shell.registerAgent(this);
samer@0 69 }
samer@0 70
samer@0 71
samer@0 72 public Canvas3D createCanvas() {
samer@0 73 GraphicsConfigTemplate tmp=new GraphicsConfigTemplate3D();
samer@0 74 Shell.trace("Graphics configuration template: "+tmp);
samer@0 75
samer@0 76 Canvas3D canvas=new Canvas3D(
samer@0 77 GraphicsEnvironment.getLocalGraphicsEnvironment().
samer@0 78 getDefaultScreenDevice().getBestConfiguration(tmp));
samer@0 79 addCanvas3D(canvas);
samer@0 80 return canvas;
samer@0 81 }
samer@0 82
samer@0 83 public Shell.Window createWindow(Canvas3D canvas, String name) {
samer@0 84 Shell.Window w=Shell.getWindow(name);
samer@0 85 w.container().setLayout(new java.awt.BorderLayout());
samer@0 86 w.container().add(canvas);
samer@0 87 w.addWindowListener(this);
samer@0 88 w.expose();
samer@0 89 // expose commands for agent
samer@0 90 return w;
samer@0 91 }
samer@0 92
samer@0 93 public void dispose() {
samer@0 94 stopView();
samer@0 95 // Shell.deregisterAgent(this);
samer@0 96 }
samer@0 97
samer@0 98 public void getCommands(Agent.Registry r) {
samer@0 99 r.add("start").add("stop").add("render");
samer@0 100 }
samer@0 101 public void execute(String cmd, Environment env) throws Exception {
samer@0 102 if (cmd.equals("render")) renderOnce();
samer@0 103 else if (cmd.equals("start")) { Shell.trace("view staring"); startView(); }
samer@0 104 else if (cmd.equals("stop")) { Shell.trace("view stopping"); stopView(); }
samer@0 105 }
samer@0 106
samer@0 107 public void starting() {}
samer@0 108 public void stopping() {}
samer@0 109 public void run() { if (!isViewRunning()) renderOnce(); }
samer@0 110
samer@0 111 public void windowOpened(WindowEvent e) {}
samer@0 112 public void windowClosed(WindowEvent e) { }
samer@0 113 public void windowClosing(WindowEvent e) { dispose(); }
samer@0 114 public void windowActivated(WindowEvent e) { }
samer@0 115 public void windowDeactivated(WindowEvent e) {}
samer@0 116 public void windowIconified(WindowEvent e) {}
samer@0 117 public void windowDeiconified(WindowEvent e) {}
samer@0 118 }