/Users/lyon/j4p/src/j3d/cr325/Hello/HelloJava3Dc.java

1    package j3d.cr325.Hello; 
2     
3    import com.sun.j3d.utils.applet.MainFrame; 
4    import com.sun.j3d.utils.geometry.ColorCube; 
5    import com.sun.j3d.utils.universe.SimpleUniverse; 
6     
7    import javax.media.j3d.*; 
8    import java.applet.Applet; 
9    import java.awt.*; 
10    
11   //   HelloJava3Dc renders a single, rotating cube. 
12    
13   public class HelloJava3Dc extends Applet { 
14    
15       public BranchGroup createSceneGraph() { 
16           // Create the root of the branch graph 
17           BranchGroup bg = new BranchGroup(); 
18    
19           // Create the transform group node and initialize it to the 
20           // identity. Add it to the root of the subgraph. 
21           TransformGroup tg = new TransformGroup(); 
22           tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 
23           bg.addChild(tg); 
24    
25           // Create a simple shape leaf node, add it to the scene graph. 
26           // ColorCube is a Convenience Utility class 
27           tg.addChild(new ColorCube(0.4)); 
28    
29           // Create a new Behavior object that will perform the desired 
30           // operation on the specified transform object and add it into 
31           // the scene graph. 
32           Alpha a = new Alpha(-1, 4000); 
33           RotationInterpolator ri = 
34                   new RotationInterpolator(a, tg); 
35           BoundingSphere bs = new BoundingSphere(); 
36           ri.setSchedulingBounds(bs); 
37           tg.addChild(ri); 
38    
39           return bg; 
40       } // end of CreateSceneGraph method 
41    
42    
43       public HelloJava3Dc() { 
44           setLayout(new BorderLayout()); 
45           GraphicsConfiguration config = 
46                   SimpleUniverse.getPreferredConfiguration(); 
47    
48           Canvas3D canvas3D = new Canvas3D(config); 
49           add("Center", canvas3D); 
50    
51           BranchGroup scene = createSceneGraph(); 
52    
53           // SimpleUniverse is a Convenience Utility class 
54           SimpleUniverse simpleU = new SimpleUniverse(canvas3D); 
55    
56           // This will move the ViewPlatform back a bit so the 
57           // objects in the scene can be viewed. 
58           simpleU.getViewingPlatform().setNominalViewingTransform(); 
59    
60           simpleU.addBranchGraph(scene); 
61       } // end of HelloJava3D (constructor) 
62    
63       //  The following allows this to be run as an application 
64       //  as well as an applet 
65    
66       public static void main(String[] args) { 
67           Frame frame = new MainFrame(new HelloJava3Dc(), 256, 256); 
68       } // end of main (method of HelloJava3D) 
69    
70   } // end of class HelloJava3Dc 
71