資源描述:
《魔方java源代碼》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、//存為MoFang.javaimportjava.applet.Applet;importjava.awt.*;importcom.sun.j3d.utils.applet.MainFrame;importjava.awt.BorderLayout;importcom.sun.j3d.utils.universe.SimpleUniverse;importjavax.media.j3d.*;importjavax.vecmath.*;importcom.sun.j3d.utils.behaviors.mouse.*;importcom.sun.j3d.utils.behavi
2、ors.keyboard.*;importcom.sun.j3d.utils.picking.behaviors.*;importcom.sun.j3d.utils.geometry.*;importcom.sun.j3d.utils.image.TextureLoader;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjavax.swing.JFrame.*;importjavax.swing.*;classmySimpleUniverseextendsApplet{BranchGroupc
3、reateSceneGraph(Canvas3Dcanvas){//System.out.print("**1**");//創(chuàng)建變換組,無用的t3DTransform3Dt3d=newTransform3D();TransformGrouptrans=newTransformGroup(t3d);trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);//創(chuàng)建分枝組BranchGroupobjRoot=ne
4、wBranchGroup();//測試//SomeShape3D.book3D(this,trans);SomeShape3D.addText3DDonghua(trans,"魔方",newPoint3f(-7.0f,6.0f,6.0f),0.1f,newColor3f(1.0f,0.0f,0.0f),1);//初始化數(shù)據(jù)結(jié)構(gòu)System.out.println("載入方塊,并向變換組中加入每個方塊的坐標系和方塊...");for(inti=0;i<=2;i++)for(intj=0;j<=2;j++)for(intk=0;k<=2;k++){int[]p;p=Posi
5、tion.getPxyzFromPositionAy(i,j,k,MoFang.positionArray);MoFang.blockArray[i][j][k]=newBlock(i,j,k,p[0],p[1],p[2],trans,t3d,objRoot,this);}System.out.println("加入每個方塊的坐標系和方塊,完成.");//創(chuàng)建大坐標軸,自動加到主坐標系SomeShape3D.zuoBiaoZhuBigXShape3D(trans);SomeShape3D.zuoBiaoZhuBigYShape3D(trans);SomeShape3D.zu
6、oBiaoZhuBigZShape3D(trans);//創(chuàng)建邊界對象BoundingSpherebounds=newBoundingSphere(newPoint3d(0.0,0.0,0.0),100);//創(chuàng)建鼠標pick行為,加到分支組objRootPickRotateBehaviorpickRotate=newPickRotateBehavior(objRoot,canvas,bounds);PickTranslateBehaviorpickTranslate=newPickTranslateBehavior(objRoot,canvas,bounds);PickZoo
7、mBehaviorpickZoom=newPickZoomBehavior(objRoot,canvas,bounds);//objRoot.addChild(pickRotate);objRoot.addChild(pickTranslate);//objRoot.addChild(pickZoom);//創(chuàng)建鼠標旋轉(zhuǎn)行為MouseRotatebehavior=newMouseRotate();behavior.setTransformGroup(trans);behavior.setSc