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

📄 uglycube.java

📁 使用java3d进行,obj文件的加载.和实现全方位的3维场景交互
💻 JAVA
字号:
package csu.chailei.test422;

import java.applet.Applet;
import java.awt.BorderLayout;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.vp.*;

import javax.media.j3d.*;
import javax.vecmath.*;
public class UglyCube extends Applet {

	/**
	 * @param args
	 */
	private SimpleUniverse universe;
	private Canvas3D canvas;
	 private BoundingSphere bounds =new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0);
	 
	public UglyCube(){
		
	}
	 public void setupView() {	
		 /** Add some view related things to view branch side 	of scene graph */   
		 // add mouse interaction to the ViewingPlatform
		 OrbitBehavior orbit = new OrbitBehavior(canvas,OrbitBehavior.REVERSE_ALL|OrbitBehavior.STOP_ZOOM); 
		 orbit.setSchedulingBounds(bounds);	
		 ViewingPlatform viewingPlatform = universe.getViewingPlatform();   
		 // This will move the ViewPlatform back a bit so the      
		 // objects in the scene can be viewed.       
		 viewingPlatform.setNominalViewingTransform();      
		 viewingPlatform.setViewPlatformBehavior(orbit);	
		 }
	public void init()
	{
		canvas=new Canvas3D(SimpleUniverse.getPreferredConfiguration());
		setLayout(new BorderLayout());
		add("Center",canvas);
		//create top of our scene graph
		BranchGroup scene=new BranchGroup();
		scene.addChild(new ColorCube(0.4));
		Sphere sp=new Sphere(0.4f);
		scene.addChild(sp);
		//create universe
		
		universe=new SimpleUniverse(canvas);
		//universe.getViewingPlatform().setNominalViewingTransform();
//		ViewingPlatform viewingPlatform = universe.getViewingPlatform();
//		OrbitBehavior	orbit = new OrbitBehavior(canvas);
//		BoundingSphere bounds =
//		new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
//		orbit.setSchedulingBounds(bounds);
//		viewingPlatform.setViewPlatformBehavior(orbit); 
		 setupView();	
		 universe.addBranchGraph(scene);
		
	}
	public void destroy() {	
		 universe.removeAllLocales();   
		 }
	 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new MainFrame(new UglyCube(),400,400);

	}

}

⌨️ 快捷键说明

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