文件名称:java 3d 魔方源代码
文件大小:13KB
文件格式:RAR
更新时间:2012-01-19 05:14:22
java 3d 魔方
//存为MoFang.java import java.applet.Applet ; import java.awt.*; import com.sun.j3d.utils.applet.MainFrame ; import java.awt.BorderLayout ; import com.sun.j3d.utils.universe.SimpleUniverse ; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.behaviors.mouse.*; import com.sun.j3d.utils.behaviors.keyboard.*; import com.sun.j3d.utils.picking.behaviors.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.image.TextureLoader ; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.JFrame.*; import javax.swing.*; class mySimpleUniverse extends Applet { BranchGroup createSceneGraph(Canvas3D canvas) { //System.out.print("**1**"); //创建变换组,无用的t3D Transform3D t3d=new Transform3D(); TransformGroup trans=new TransformGroup(t3d); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); //创建分枝组 BranchGroup objRoot=new BranchGroup(); //测试 //SomeShape3D.book3D( this, trans); SomeShape3D.addText3DDonghua(trans,"魔方",new Point3f(-7.0f,6.0f,6.0f),0.1f,new Color3f(1.0f,0.0f,0.0f),1); //初始化数据结构 System.out.println("\n\n载入方块,并向变换组中加入每个方块的坐标系和方块..."); for(int i=0;i<=2;i++) for(int j=0;j<=2;j++) for(int k=0;k<=2;k++) { int[] p; p=Position.getPxyzFromPositionAy(i,j,k,MoFang.positionArray); MoFang.blockArray[i][j][k]=new Block(i,j,k,p[0],p[1],p[2],trans,t3d,objRoot,this); } System.out.println("加入每个方块的坐标系和方块,完成.\n"); //创建大坐标轴,自动加到主坐标系 SomeShape3D.zuoBiaoZhuBigXShape3D(trans); SomeShape3D.zuoBiaoZhuBigYShape3D(trans); SomeShape3D.zuoBiaoZhuBigZShape3D(trans); //创建边界对象 BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100); //创建鼠标pick行为,加到分支组objRoot PickRotateBehavior pickRotate=new PickRotateBehavior(objRoot,canvas,bounds); PickTranslateBehavior pickTranslate=new PickTranslateBehavior(objRoot,canvas,bounds); PickZoomBehavior pickZoom=new PickZoomBehavior(objRoot,canvas,bounds); //objRoot.addChild(pickRotate); objRoot.addChild(pickTranslate); //objRoot.addChild(pickZoom); //创建鼠标旋转行为 MouseRotate behavior=new MouseRotate(); behavior.setTransformGroup(trans); behavior.setSchedulingBounds(bounds); //创建鼠标平移行为 //MouseTranslate myMouseRotate=new MouseTranslate(); //myMouseRotate.setTransformGroup(trans); //myMouseRotate.setSchedulingBounds(bounds);
【文件预览】:
JAVA 3D 魔方源代码
----java-codes.txt(65KB)