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

📄 show.java

📁 java 3d 系列源码
💻 JAVA
字号:
// 【\source\chapter2\Show.java】Shou.java
// 显示函数曲面
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Label;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.mouse.*;
public class Show extends Applet
{
	public Show ()
	{
		setLayout(new BorderLayout());
		Canvas3D c = new Canvas3D(null);
		add("Center", c);
		BranchGroup scene = new BranchGroup();
		TransformGroup objGroup=new TransformGroup();
		Transform3D trans = new Transform3D();
		
		trans.rotY(Math.PI/8);
		objGroup.setTransform(trans);
		objGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		scene.addChild(objGroup);
		BoundingSphere  bounds  = new BoundingSphere( 
new Point3d( 0.0, 0.0, 0.0 ), 100.0 );
		//创建背景
		Background      bg      = new Background();
		//指定背景颜色
		bg.setColor(new Color3f(0.1f,0.4f,0.7f));
		//指定背景的有效范围
		bg.setApplicationBounds( bounds );
		scene.addChild( bg );
		// 添加函数曲面
		Shape3D surf = new Surface();
		objGroup.addChild(surf);
		// 添加灯光
		AmbientLight lightA = new AmbientLight();
		lightA.setInfluencingBounds(new BoundingSphere());
		scene.addChild(lightA);
		DirectionalLight lightD1 = new DirectionalLight();
		lightD1.setInfluencingBounds(new BoundingSphere());
		Vector3f direction = new Vector3f(0.5f, 0.0f, -1.0f);
		Color3f color = new Color3f(1.0f,0f,0f);
		direction.normalize();
		lightD1.setDirection(direction);
		lightD1.setColor(color);
		scene.addChild(lightD1);
		// 添加鼠标行为,可以更好的观察函数曲面
		MouseRotate		myMR	= null;
		MouseTranslate	myMT	= null;
		MouseZoom			myMZ	= null;
		// 添加旋转功能
        myMR = new MouseRotate();
        myMR.setTransformGroup(objGroup);
        myMR.setSchedulingBounds(new BoundingSphere());
        scene.addChild(myMR);
        // 添加平移功能
        myMT = new MouseTranslate();
        myMT.setTransformGroup(objGroup);
        myMT.setSchedulingBounds(new BoundingSphere());
        scene.addChild(myMT);
		// 添加缩放功能
		myMZ = new MouseZoom();
		myMZ.setTransformGroup(objGroup);
		myMZ.setSchedulingBounds(new BoundingSphere());
		scene.addChild(myMZ);
		SimpleUniverse u = new SimpleUniverse(c);
		// 后移视平台
		u.getViewingPlatform().setNominalViewingTransform();
		u.addBranchGraph(scene);
	}
	public static void main(String argv[])
	{
		new MainFrame(new Show(), 256, 256);
	}
}// end of Show.java

⌨️ 快捷键说明

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