/Users/lyon/j4p/src/j3d/AxisClassDemoApp.java

1    package j3d; 
2     
3    /* 
4     *      @(#)AxisClassDemoApp.java 1.1 00/09/22 15:57 
5     * 
6     * Copyright (c) 1996-2000 Sun Microsystems, Inc. All Rights Reserved. 
7     * 
8     * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, 
9     * modify and redistribute this software in source and binary code form, 
10    * provided that i) this copyright notice and license appear on all copies of 
11    * the software; and ii) Licensee does not utilize the software in a manner 
12    * which is disparaging to Sun. 
13    * 
14    * This software is provided "AS IS," without a warranty of any kind. ALL 
15    * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY 
16    * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR 
17    * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE 
18    * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING 
19    * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS 
20    * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, 
21    * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER 
22    * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF 
23    * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE 
24    * POSSIBILITY OF SUCH DAMAGES. 
25    * 
26    * This software is not designed or intended for use in on-line control of 
27    * aircraft, air traffic, aircraft navigation or aircraft communications; or in 
28    * the design, construction, operation or maintenance of any nuclear 
29    * facility. Licensee represents and warrants that it will not use or 
30    * redistribute the Software for such purposes. 
31    */ 
32    
33   /* 
34    * Getting Started with the Java 3D API 
35    * written in Java 3D 
36    * 
37    * This is a program to demonstrate the Axis class 
38    * defined in the file Axis.java distributed with the tutorial. 
39    */ 
40    
41   import com.sun.j3d.utils.applet.MainFrame; 
42   import com.sun.j3d.utils.geometry.ColorCube; 
43   import com.sun.j3d.utils.universe.SimpleUniverse; 
44    
45   import javax.media.j3d.*; 
46   import javax.vecmath.Point3d; 
47   import javax.vecmath.Vector3f; 
48   import java.applet.Applet; 
49   import java.awt.*; 
50    
51    
52   public class AxisClassDemoApp extends Applet { 
53    
54       ///////////////////////////////////////////////// 
55       // 
56       // create scene graph branch group 
57       // 
58       public BranchGroup createSceneGraph() { 
59    
60           BranchGroup objRoot = new BranchGroup(); 
61           objRoot.addChild(new j3d.Axis()); 
62    
63           // Create the transform group node and initialize it to the 
64           // identity.  Enable the TRANSFORM_WRITE capability so that 
65           // our behavior code can modify it at runtime.  Add it to the 
66           // root of the subgraph. 
67           TransformGroup objSpin = new TransformGroup(); 
68           objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 
69    
70           // Create a new Behavior object that will perform the desired 
71           // operation on the specified transform object and add it into 
72           // the scene graph. 
73           Transform3D yAxis = new Transform3D(); 
74           Alpha rotationAlpha = new Alpha(-1, 4000); 
75    
76           RotationInterpolator rotator = 
77                   new RotationInterpolator(rotationAlpha, objSpin); 
78           BoundingSphere bounds = 
79                   new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); 
80           rotator.setSchedulingBounds(bounds); 
81    
82           Transform3D trans = new Transform3D(); 
83           trans.set(new Vector3f(0.5f, 0.0f, 0.0f)); 
84           TransformGroup objTrans = new TransformGroup(trans); 
85           objRoot.addChild(objSpin); 
86           objSpin.addChild(objTrans); 
87           objSpin.addChild(rotator); 
88           objTrans.addChild(new ColorCube(0.1)); 
89    
90           // Let Java 3D perform optimizations on this scene graph. 
91           objRoot.compile(); 
92    
93           return objRoot; 
94       } // end of CreateSceneGraph method of AxisClassDemoApp 
95    
96       // Create a simple scene and attach it to the virtual universe 
97    
98       public AxisClassDemoApp() { 
99           setLayout(new BorderLayout()); 
100          GraphicsConfiguration config = 
101                  SimpleUniverse.getPreferredConfiguration(); 
102   
103          Canvas3D canvas3D = new Canvas3D(config); 
104          add("Center", canvas3D); 
105   
106          BranchGroup scene = createSceneGraph(); 
107   
108          // SimpleUniverse is a Convenience Utility class 
109          SimpleUniverse simpleU = new SimpleUniverse(canvas3D); 
110   
111          // This will move the ViewPlatform back a bit so the 
112          // objects in the scene can be viewed. 
113          simpleU.getViewingPlatform().setNominalViewingTransform(); 
114   
115          simpleU.addBranchGraph(scene); 
116      } // end of AxisClassDemoApp constructor 
117   
118      //  The following allows this to be run as an application 
119      //  as well as an applet 
120   
121      public static void main(String[] args) { 
122          Frame frame = new MainFrame(new AxisClassDemoApp(), 256, 256); 
123      } // end of main method of AxisClassDemoApp 
124   
125  } // end of class AxisClassDemoApp 
126