/Users/lyon/j4p/src/j3d/viewer/Simple3D.java

1    package j3d.viewer; 
2     
3    /* 
4     * 
5     * (c) September 1998 by Mauro Marinilli 
6     * 
7     */ 
8     
9     
10   import com.sun.j3d.utils.applet.MainFrame; 
11   import com.sun.j3d.utils.geometry.ColorCube; 
12   import com.sun.j3d.utils.universe.SimpleUniverse; 
13   import j3d.Utils; 
14    
15   import javax.media.j3d.*; 
16   import javax.swing.*; 
17   import java.awt.*; 
18    
19    
20   public final class Simple3D extends VU { 
21       private final SimpleUniverse su; 
22    
23       private static BranchGroup createSceneGraph() { 
24           final BranchGroup objRoot = new BranchGroup(); 
25    
26           final Transform3D spin = new Transform3D(); 
27           final Transform3D tempspin = new Transform3D(); 
28    
29           spin.rotX(Math.PI / 4.0d); 
30           tempspin.rotY(Math.PI / 5.0d); 
31           spin.mul(tempspin); 
32    
33           final TransformGroup objTrans = new TransformGroup(spin); 
34           objRoot.addChild(objTrans); 
35    
36           objTrans.setCapability(BranchGroup.ALLOW_CHILDREN_READ); 
37           objTrans.addChild(new ColorCube(0.4)); 
38    
39    
40   //// 
41    
42           objTrans.addChild(new ColorCube(0.3)); 
43           objTrans.setCapability(BranchGroup.ALLOW_CHILDREN_READ); 
44           objTrans.addChild(new ColorCube(0.1)); 
45           objTrans.setCapability(BranchGroup.ALLOW_CHILDREN_READ); 
46    
47    
48    
49    
50   //// 
51    
52    
53           objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_READ); 
54           objRoot.compile(); 
55    
56           return objRoot; 
57       } 
58    
59    
60       public Simple3D() { 
61           setLayout(new BorderLayout()); 
62           final Canvas3D c = Utils.getCanvas3D(new JPanel()); 
63           add("Center", c); 
64    
65           final BranchGroup scene = createSceneGraph(); 
66    
67           // SimpleUniverse is a Convenience Utility class 
68           final SimpleUniverse u = new SimpleUniverse(c); 
69           su = u; 
70    
71           u.getViewingPlatform().setNominalViewingTransform(); 
72    
73           u.addBranchGraph(scene); 
74       } 
75    
76    
77       public VirtualUniverse getVU() { 
78           return su; 
79       } 
80    
81    
82       public static void main(final String[] args) { 
83    
84           final Simple3D he = new Simple3D(); 
85           new MainFrame(he, 256, 256); 
86       } 
87   } 
88