Java examples for Media:3D
Create 3D universe
import java.awt.Frame; import java.applet.Applet; import java.awt.*; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; public class Main extends Applet { SimpleUniverse simpleU; /* w w w.ja va2s . com*/ public void init() { setLayout(new BorderLayout()); // standard Java code for BorderLayout Canvas3D c = new Canvas3D( SimpleUniverse.getPreferredConfiguration()); add("Center", c); simpleU = new SimpleUniverse(c); // setup the SimpleUniverse, attach the Canvas3D BranchGroup scene = createSceneGraph(); simpleU.getViewingPlatform().setNominalViewingTransform(); scene.compile(); simpleU.addBranchGraph(scene); //add your SceneGraph to the SimpleUniverse } public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); ColorCube c = new ColorCube(0.5f); objRoot.addChild(c); return objRoot; } public void destroy() { simpleU.removeAllLocales(); } public static void main(String[] args) { Frame frame = new MainFrame(new Main(), 500, 500); } }