import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.*;

/**
A class used to create a new virtual universe and associated view branch
*/
public class MyVirtualUniverse extends VirtualUniverse
{
	/**
	*/
	public MyVirtualUniverse()
	{
		super();
		createVU();
	}


	/**
	Create a new Virtual Universe and view branch
	*/
	private void createVU()
	{
		// Create Locale
		locale = new Locale(this);

		// Create Branch Group
		viewBG = new BranchGroup();

		// Create Transform Group
		viewTG = new TransformGroup();
		viewTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		viewTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

		// Create View Platform
		viewPlatform = new ViewPlatform();

		// Create View and set default clipping palnes
		view = new View();
		view.setFrontClipDistance(.2);
		view.setBackClipDistance(200);

		// Create Physical Body
		physicalBody = new PhysicalBody();

		// Create Physical Environment
		physicalEnvironment = new PhysicalEnvironment();

		// Create Board (Canvas) 3D
		board = Board3D.makeBoard();

		// attach nodes together

		view.setPhysicalBody(physicalBody);

		view.setPhysicalEnvironment(physicalEnvironment);

		view.addCanvas3D(board);

		view.attachViewPlatform(viewPlatform);

		viewTG.addChild(viewPlatform);

		viewBG.addChild(viewTG);

		addBranchGraph(viewBG);
	}

	/**
	Add a BranchGroup to this VU's locale
	@param branchGroup The Scene Graph to add
	*/
	public void addBranchGraph(BranchGroup branchGroup)
	{
		locale.addBranchGraph(branchGroup);
	}

	/**
	Gets the canvas that the content of this VU is rendered onto
	*/
	public Board3D getBoard()
	{
		return board;
	}

	/**
	Gets the TransformGroup that the 'camera' is attached to
	*/
	public TransformGroup getViewTG()
	{
		return viewTG;
	}


	/*
	Class Fields
	*/

	private Locale				locale				= null;
	private BranchGroup			viewBG				= null;
	private TransformGroup		viewTG				= null;
	private ViewPlatform		viewPlatform		= null;
	private View				view				= null;
	private Board3D				board				= null;
	private PhysicalBody		physicalBody		= null;
	private PhysicalEnvironment	physicalEnvironment	= null;
}

