DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

java programmer from china Nile has posted 6 posts at DZone. View Full User Profile

VirtualUniverse Starter

10.15.2009
| 1305 views |
  • submit to reddit
        // description of your code here

import java.awt.GraphicsConfiguration;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.Locale;
import javax.media.j3d.VirtualUniverse;
import javax.swing.JFrame;
import javax.vecmath.Vector3d;

import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.Viewer;
import com.sun.j3d.utils.universe.ViewingPlatform;

public class Ray extends JFrame {
	VirtualUniverse universe;
	Locale locale;

	public Ray() {
		GraphicsConfiguration config = SimpleUniverse
				.getPreferredConfiguration();
		Canvas3D canvas3D = new Canvas3D(config);
		add(canvas3D);
		universe = new VirtualUniverse();
		locale = new Locale(universe);
		BranchGroup root = new BranchGroup();
		locale.addBranchGraph(root);

		Viewer viewer = new Viewer(canvas3D);
		ViewingPlatform vp = new ViewingPlatform();
		viewer.setViewingPlatform(vp);
		locale.addBranchGraph(vp);
		
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		pack();
		setVisible(true);
	}
}