Mercurial > hg > jslab
comparison examples/java3d/Viewer.java @ 1:5df24c91468d
Oh my what a mess.
author | samer |
---|---|
date | Fri, 05 Apr 2019 16:26:00 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:bf79fb79ee13 | 1:5df24c91468d |
---|---|
1 /* | |
2 Viewer.java | |
3 | |
4 A View branch group containing a ViewPlatform | |
5 and associated View, Canvas etc. Creates a | |
6 window for itself. Can be added dynamically | |
7 to a live universe. | |
8 */ | |
9 | |
10 import samer.core.*; | |
11 import java.awt.event.*; | |
12 import java.awt.*; | |
13 import javax.media.j3d.*; | |
14 import javax.vecmath.*; | |
15 import com.sun.j3d.utils.behaviors.keyboard.*; | |
16 | |
17 import samer.core.Node; | |
18 | |
19 public class Viewer extends BranchGroup implements Agent | |
20 { | |
21 Node node; | |
22 Canvas3D canvas; | |
23 TransformGroup VT=new TransformGroup(); | |
24 View V=new View(); | |
25 Shell.Window win; | |
26 | |
27 public void lookFrom(Point3d eye, Vector3d up) | |
28 { | |
29 // view platform placement | |
30 Transform3D t=new Transform3D(); | |
31 t.lookAt(eye, new Point3d(0,0,0), up); | |
32 t.invert(); | |
33 VT.setTransform(t); | |
34 } | |
35 | |
36 public Viewer(String name) | |
37 { | |
38 node=new Node(name); | |
39 Shell.push(node); | |
40 | |
41 // create view bits | |
42 canvas=new Canvas3D(util.getGraphicsConfiguration()); | |
43 | |
44 // view platform placement | |
45 ViewPlatform VP=new ViewPlatform(); | |
46 | |
47 lookFrom(new Point3d(0,1,6), new Vector3d(0,1,0)); | |
48 | |
49 if (Shell.getBoolean("keynav",false)) { | |
50 // !!! all key navigators seem to be slaved! | |
51 util.addKeyNavigator(VT,util.readwrite(VT)); | |
52 } | |
53 | |
54 VT.addChild(VP); | |
55 addChild(VT); | |
56 | |
57 // view itself | |
58 V.addCanvas3D(canvas); | |
59 V.setPhysicalBody(new PhysicalBody()); | |
60 V.setPhysicalEnvironment(new PhysicalEnvironment()); | |
61 V.attachViewPlatform(VP); | |
62 V.setWindowEyepointPolicy(View.RELATIVE_TO_WINDOW); | |
63 V.setWindowResizePolicy(View.VIRTUAL_WORLD); | |
64 //V.setLocalEyeLightingEnable(true); | |
65 //v.setWindowMovementPolicy(View.VIRTUAL_WORLD); | |
66 | |
67 setCapability(ALLOW_DETACH); | |
68 setCapability(ALLOW_CHILDREN_WRITE); | |
69 compile(); | |
70 Shell.pop(); | |
71 | |
72 win=Shell.getWindow(name); | |
73 win.container().setLayout(new BorderLayout()); | |
74 win.container().add(canvas); | |
75 win.expose(); | |
76 win.addWindowListener(new WindowAdapter() { | |
77 public void windowClosing(WindowEvent e) { dispose(); } | |
78 }); | |
79 | |
80 Shell.registerAgent(this); | |
81 } | |
82 | |
83 public void dispose() | |
84 { | |
85 Shell.deregisterAgent(this); | |
86 win.dispose(); | |
87 detach(); | |
88 } | |
89 | |
90 protected void finalize() { Shell.trace("finalizing view "+this); } | |
91 | |
92 public void getCommands(Agent.Registry r) { r.add("start").add("stop"); } | |
93 public void execute(String cmd, Environment env) { | |
94 if (cmd.equals("start")) { V.startView(); } // canvas.startRenderer(); } | |
95 else if (cmd.equals("stop")) { V.stopView(); } // canvas.stopRenderer(); } | |
96 } | |
97 } |