import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.Viewer;
import javax.vecmath.*;
import java.awt.*;
import javax.media.j3d.*;
import java.applet.*;

public class t81 extends Applet {
	public static void main(String[] args) {
		new MainFrame(new t81(),640,480);
	}

	public void init() {
		GraphicsConfiguration gc= SimpleUniverse.getPreferredConfiguration();
		Canvas3D cv= new Canvas3D(gc);
		setLayout(new BorderLayout());
		add(cv,BorderLayout.CENTER);
		BranchGroup bg= createSceneGraph();
		bg.compile();
		SimpleUniverse su= new SimpleUniverse(cv);
		su.getViewingPlatform().setNominalViewingTransform();
		su.addBranchGraph(bg);
		Viewer viewer= su.getViewer();
		View view2= viewer.getView();
		view2.setSceneAntialiasingEnable(true);
		System.out.printf("view2: %s\n",view2);
	}
	private BranchGroup createSceneGraph() {
		BranchGroup root= new BranchGroup();
		TransformGroup spin= new TransformGroup();
		spin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		root.addChild(spin);
		Appearance ap= new Appearance();
		ap.setMaterial(new Material());
		FontExtrusion fontExtrusion= new FontExtrusion();
		double tessellationTolerance= 1e-2;
		Text3D text3d= new Text3D(
			new Font3D(
				new Font("Helvetica",Font.PLAIN,48),
				tessellationTolerance,
				fontExtrusion),
			"01234567890 TEXT 3D");
		Shape3D text2= new Shape3D(text3d);
		text2.setAppearance(ap);
		BoundingBox boundingBox= new BoundingBox();
		text3d.getBoundingBox(boundingBox);
		System.out.printf("boundingBox: %s\n",boundingBox);
		Point3d p1= new Point3d();
		boundingBox.getUpper(p1);
		System.out.printf("upper: %s\n",p1);
		TransformGroup textTrans= new TransformGroup();
		Transform3D t3d= new Transform3D();
		t3d.setTranslation(new Vector3d(-(p1.x/2),-(p1.y/2),-(p1.z/2)));
		textTrans.setTransform(t3d);
		textTrans.addChild(text2);
		Transform3D tr= new Transform3D();
		tr.setScale(0.05);
		TransformGroup tg= new TransformGroup(tr);
		spin.addChild(tg);
		tg.addChild(textTrans);
		Alpha alpha= new Alpha(-1,1000000000);
		RotationInterpolator rotator= new RotationInterpolator(alpha,spin);
		BoundingSphere bounds= new BoundingSphere();
		rotator.setSchedulingBounds(bounds);
		spin.addChild(rotator);
		Background background= new Background(0.0f,0.0f,0.0f);
		background.setApplicationBounds(bounds);
		root.addChild(background);
		AmbientLight light= new AmbientLight(true,new Color3f(Color.white));
		light.setInfluencingBounds(bounds);
		root.addChild(light);
		PointLight ptlight= new PointLight(new Color3f(Color.white),new Point3f(3f,3f,3f),new Point3f(1f,0f,0f));
		ptlight.setInfluencingBounds(bounds);
		root.addChild(ptlight);
		PointLight ptlight2= new PointLight(new Color3f(Color.white),
		new Point3f(-2f,2f,2f),new Point3f(1f,0f,0f));
		ptlight2.setInfluencingBounds(bounds);
		root.addChild(ptlight2);
		return root;
	}
}