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

1    package j3d.cr325.Hello; 
2     
3     
4    import com.sun.j3d.utils.applet.MainFrame; 
5    import com.sun.j3d.utils.geometry.ColorCube; 
6    import com.sun.j3d.utils.universe.SimpleUniverse; 
7     
8    import javax.media.j3d.BranchGroup; 
9    import javax.media.j3d.Canvas3D; 
10   import javax.media.j3d.Transform3D; 
11   import javax.media.j3d.TransformGroup; 
12   import java.applet.Applet; 
13   import java.awt.*; 
14    
15   //   HelloJava3Dbalt renders a single, rotated cube. 
16    
17   public class HelloJava3Dbalt extends Applet { 
18       public BranchGroup createSceneGraph() { 
19           // Create the root of the branch graph 
20           BranchGroup bg = new BranchGroup(); 
21    
22           // rotate object has composited transformation matrix 
23           Transform3D rotate = new Transform3D(); 
24           Transform3D tempRotate = new Transform3D(); 
25    
26           rotate.rotX(Math.PI / 4.0d); 
27           tempRotate.rotY(Math.PI / 5.0d); 
28           tempRotate.mul(rotate); 
29    
30           TransformGroup objRotate = new TransformGroup(tempRotate); 
31    
32           bg.addChild(objRotate); 
33           objRotate.addChild(new ColorCube(0.4)); 
34           // Let Java 3D perform optimizations on this scene graph. 
35           bg.compile(); 
36    
37           return bg; 
38       } // end of CreateSceneGraph method of HelloJava3Dbalt 
39    
40       // Create a simple scene and attach it to the virtual universe 
41    
42       public HelloJava3Dbalt() { 
43           setLayout(new BorderLayout()); 
44           GraphicsConfiguration config = 
45                   SimpleUniverse.getPreferredConfiguration(); 
46    
47           Canvas3D canvas3D = new Canvas3D(config); 
48           add("Center", canvas3D); 
49    
50           BranchGroup bg = createSceneGraph(); 
51    
52           // SimpleUniverse is a Convenience Utility class 
53           SimpleUniverse su = new SimpleUniverse(canvas3D); 
54    
55           // This will move the ViewPlatform back a bit so the 
56           // objects in the scene can be viewed. 
57           su.getViewingPlatform().setNominalViewingTransform(); 
58    
59           su.addBranchGraph(bg); 
60       } // end of HelloJava3Db (constructor) 
61       //  The following allows this to be run as an application 
62       //  as well as an applet 
63    
64       public static void main(String[] args) { 
65           new MainFrame(new HelloJava3Dbalt(), 256, 256); 
66       } // end of main (method of HelloJava3Dbalt) 
67    
68   } // end of class HelloJava3Dbalt 
69