⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mycube1.java

📁 关于java3D学习的示例程序
💻 JAVA
字号:
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
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.*;
import com.sun.j3d.utils.behaviors.mouse.*;
public class MyCube1 extends Applet{
	public BranchGroup createSceneGraph(){
		BranchGroup objRoot=new BranchGroup();
		BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
		Color3f bgColor=new Color3f(0.0f,0.0f,0.0f);
		Background bg=new Background(bgColor);
		bg.setApplicationBounds(bounds);
		objRoot.addChild(bg);
		TransformGroup trans=new TransformGroup();
		trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		objRoot.addChild(trans);
		TransformGroup g1=new TransformGroup();
		g1.addChild(new ColorCube(0.2));
		Transform3D t=new Transform3D();
		t=new Transform3D();
		t.setScale(0.5);
		t.setTranslation(new Vector3f(0.0f,0.6f,0.0f));
		t.setRotation(new Quat4f(0.78f,0.78f,0.78f,0.0f));
		TransformGroup g2=new TransformGroup(t);
		g2.addChild(new ColorCube(0.2));
		trans.addChild(g1);
		trans.addChild(g2);
		MouseRotate behavior=new MouseRotate();
		behavior.setTransformGroup(trans);
		objRoot.addChild(behavior);
		behavior.setSchedulingBounds(bounds);
		MouseZoom behavior2=new MouseZoom();
		behavior2.setTransformGroup(trans);
		objRoot.addChild(behavior2);
		behavior2.setSchedulingBounds(bounds);
		MouseTranslate behavior3=new MouseTranslate();
		behavior3.setTransformGroup(trans);
		objRoot.addChild(behavior3);
		behavior3.setSchedulingBounds(bounds);
		objRoot.compile();
		return objRoot;
	}
	public MyCube1(){
		setLayout(new BorderLayout());
		Canvas3D c=new Canvas3D(null);
		add("Center",c);
		BranchGroup scene=createSceneGraph();
		SimpleUniverse u=new SimpleUniverse(c);
		u.getViewingPlatform().setNominalViewingTransform();
		u.addBranchGraph(scene);
	}
	public static void main(String[] args){
		new MainFrame(new MyCube1(),400,300);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -