1:// From Chapter 1 of "The Java 3D Tutorial"
2:
3:import java.applet.Applet;
4:import java.awt.*;
5:import com.sun.j3d.utils.applet.MainFrame;
6:import com.sun.j3d.utils.universe.*;
7:import com.sun.j3d.utils.geometry.*;
8:import javax.media.j3d.*;
9:import javax.vecmath.*;
10:
11:public class Simple extends Applet{
12:
13: public Simple() {
14: //set the layout manager for the applet
15: setLayout(new BorderLayout());
16:
17: //looks at your graphics hardware and cooks up a suitable config
18: GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
19:
20: //Canvas3D is a heavyweight component
21: Canvas3D canvas3d = new Canvas3D(config);
22:
23: //add it to this Applet
24: add("Center", canvas3d);
25:
26: //create the content branch group using the method createSceneGraph() below
27: BranchGroup scene = createSceneGraph();
28:
29: //compile
30: //this could also be done in createSceneGraph()
31: scene.compile();
32:
33: //create a SimpleUniverse class referencing canvas3d
34: SimpleUniverse sU = new SimpleUniverse(canvas3d);
35:
36: //the view platform starts out at the orgin
37: //but our cube is also centred at the origin
38: //this moves the view platform back a bit so we can see the cube
39: sU.getViewingPlatform().setNominalViewingTransform();
40:
41: //attaches the BranchGroup to the Locale object
42: sU.addBranchGraph(scene);
43:
44: } //end of Simple (constructor)
45:
46: public BranchGroup createSceneGraph(){
47: BranchGroup objRoot = new BranchGroup();
48:
49: objRoot.addChild(new ColorCube(0.4));
50:
51: return objRoot;
52: } //end of createSceneGraph method of Simple
53:
54: public static void main(String[] args){
55: Frame frame = new MainFrame(new Simple(), 256, 256);
56: } //end of main methof of Simple
57:
58:} //end of Simple (class)
previous
start
toc
next