All pastes #383595 Raw Edit

Untitled

public text v1 · immutable
·published 2007-03-06 14:23 UTC
rendered paste body
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Iterator;

import javax.media.j3d.Alpha;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.vecmath.Vector3d;

import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;


public class Cube extends JFrame implements KeyListener{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Cube(){
		addKeyListener(this);
		Canvas3D canvas3D = new
		Canvas3D(SimpleUniverse.getPreferredConfiguration());
		SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
		simpleU.getViewingPlatform().setNominalViewingTransform();
		//Background
		BranchGroup scene2=new BranchGroup();
		
		Transform3D translate = new Transform3D();
		Vector3d vector = new Vector3d(0, 0,-2);
		translate.setTranslation(vector);
		Alpha alph=new Alpha(-1,700);
		TransformGroup rotateobj=new TransformGroup(translate);
		TransformGroup spin=new TransformGroup();
		spin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		RotationInterpolator rp=new RotationInterpolator(alph,spin);
		BoundingSphere bounds = new BoundingSphere();
		rp.setSchedulingBounds(bounds);
		rotateobj.addChild(new ColorCube(0.4));
		//spin.addChild(rp);
		scene2.addChild(rotateobj);
		//spin.addChild(new ColorCube(0.4));	
		//scene2.addChild(cube);
		scene2.compile();
		simpleU.addBranchGraph(scene2);
		//BranchGroup scene = new BranchGroup();
		//scene.addChild(new ColorCube(0.4));
		//scene.addChild(new Cylinder( 1 , 6));
		//scene.compile();
		//simpleU.addBranchGraph(scene);
		this.add(canvas3D);
		this.setSize(200, 200);
		this.pack();
		this.setVisible(true);
		
	}
	
	public void keyPressed(KeyEvent arg0) {
		if (arg0.getKeyCode()==KeyEvent.VK_ESCAPE){
			System.exit(0);
		}
		
	}
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * @param args
	 */
	//-------------------------------------
	public static void main(String[] args) {
		
		Cube bla=new Cube();
		
		
		
		// TODO Auto-generated method stub

	}
	

}