欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    魔方java源代码.doc

    • 资源ID:24129578       资源大小:418KB        全文页数:38页
    • 资源格式: DOC        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    魔方java源代码.doc

    【精品文档】如有侵权,请联系网站删除,仅供学习与交流魔方java源代码.精品文档./存为MoFang.javaimport 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("nn载入方块,并向变换组中加入每个方块的坐标系和方块."); 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.blockArrayijk=new Block(i,j,k,p0,p1,p2,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); /创建鼠标缩放行为 MouseZoom myMouseZoom=new MouseZoom(); myMouseZoom.setTransformGroup(trans); myMouseZoom.setSchedulingBounds(bounds); /创建键盘默认行为 KeyNavigatorBehavior keyNavBeh=new KeyNavigatorBehavior(trans); keyNavBeh.setSchedulingBounds(bounds); objRoot.addChild(keyNavBeh); /白色背景 Background bg=new Background(new Color3f(0.0f,0.0f,0.0f); bg.setApplicationBounds(bounds); objRoot.addChild(bg); /创建带材质的背景 /TextureLoader bgTexture=new TextureLoader("bg3.jpg",this); /Background bg=new Background(bgTexture.getImage(); /bg.setApplicationBounds(bounds); /trans.addChild(shape1);/3D物体 加到 变换组 /trans.addChild(shape2);/3D物体 加到 变换组 objRoot.addChild(trans); /变换组 加到 分枝组 objRoot.addChild(behavior); /鼠标行为 加到 分枝组 /objRoot.addChild(myMouseRotate); /objRoot.addChild(myMouseZoom); /objRoot.addChild(bg);/背景 加到 分枝组 /编译 objRpile(); /回送创建好的带3D物体的分枝组 return objRoot ; mySimpleUniverse() /创建带控制的画布 GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration(); Canvas3D c=new Canvas3D(config); /创建以画布为依托的简单场景图对象,没有多个Locale SimpleUniverse u=new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); /创建分支组对象 BranchGroup scene=createSceneGraph(c); /组装,分支组 对象加到 场景图 u.addBranchGraph(scene); /带场景图的画布 加到 本applet中 setLayout(new BorderLayout(); add("Center",c); /测试码 /public static void main(String aregs) /new MainFrame(new mySimpleUniverse(),200,200);/加applet到应用程序界面class SomeShape3D public static float zuoBiaoZhouSmallDingDian=0.09f;/小坐标顶点位置 public static float zuoBiaoZhouSmallDingXi=0.02f;/小坐标顶点伞的半径 public static float zuoBiaoZhouSmallDingChang=0.07f;/小坐标顶点伞的长度 public static float zuoBiaoZhouSmallWeiDian=-0.09f;/小坐标尾巴的位置 public static float zuoBiaoZhouBigDingDian=1.0f;/大坐标顶点位置 public static float zuoBiaoZhouBigDingXi=0.04f;/大坐标顶点伞的半径 public static float zuoBiaoZhouBigDingChang=0.8f;/大坐标顶点伞的长度 public static float zuoBiaoZhouBigWeiDian=-1.0f;/大坐标尾巴的位置 public static float fangKuaiBanJing=0.18f;/每个方块的半径 public static void zuoBiaoZhuBigXShape3D(TransformGroup trans) /创建大坐标轴对象 int i ; float x1,x2,y1,y2,z1,z2 ; SomeShape3D.addText3DDonghua(trans,"X",new Point3f(zuoBiaoZhouBigDingDian*10,0.0f,0.0f),0.1f,Block.mianColor0,0); Point3fvert=new Point3f41; Color3fcolors=new Color3f41; for(i=0;i<27;i+) if(i=0) verti=new Point3f(zuoBiaoZhouBigDingDian,0.0f,0.0f); colorsi=Block.mianColor0; else z1=(float)(zuoBiaoZhouBigDingXi*Math.cos(i*2*Math.PI/25); x1=zuoBiaoZhouBigDingChang; y1=(float)(zuoBiaoZhouBigDingXi*Math.sin(i*2*Math.PI/25); verti=new Point3f(x1,y1,z1); colorsi=Block.mianColor0; for(i=0;i<14;i+) if(i=0) vert27+i=new Point3f(zuoBiaoZhouBigDingDian,0.0f,0.0f); colors27+i=Block.mianColor0; else z1=(float)(0.01f*Math.cos(i*2*Math.PI/12); x1=zuoBiaoZhouBigWeiDian ; y1=(float)(0.01f*Math.sin(i*2*Math.PI/12); vert27+i=new Point3f(x1,y1,z1); colors27+i=Block.mianColor1; int count=new int2; count0=27 ; count1=14 ; TriangleFanArray tri=new TriangleFanArray( vert.length, TriangleFanArray.COORDINATES|TriangleStripArray.COLOR_3, count tri.setCoordinates(0,vert); tri.setColors(0,colors); Appearance app=new Appearance(); PolygonAttributes polyAttrib=new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); /polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE); app.setPolygonAttributes(polyAttrib); Shape3D shape=new Shape3D(tri,app); System.out.print("zuoBiaoZhuBigX 创建 完成n"); trans.addChild(shape); /到这里,大坐标轴对象创建完成 public static void zuoBiaoZhuBigYShape3D(TransformGroup trans) /创建大坐标轴对象 int i ; float x1,x2,y1,y2,z1,z2 ; SomeShape3D.addText3DDonghua(trans,"Y",new Point3f(-1.0f,zuoBiaoZhouBigDingDian*10,0.0f),0.1f,Block.mianColor2,0); Point3fvert=new Point3f41; Color3fcolors=new Color3f41; for(i=0;i<27;i+) if(i=0) verti=new Point3f(0.0f,zuoBiaoZhouBigDingDian,0.0f); colorsi=Block.mianColor2; else x1=(float)(zuoBiaoZhouBigDingXi*Math.cos(i*2*Math.PI/25); y1=zuoBiaoZhouBigDingChang; z1=(float)(zuoBiaoZhouBigDingXi*Math.sin(i*2*Math.PI/25); verti=new Point3f(x1,y1,z1); colorsi=Block.mianColor2; for(i=0;i<14;i+) if(i=0) vert27+i=new Point3f(0.0f,zuoBiaoZhouBigDingDian,0.0f); colors27+i=Block.mianColor2; else x1=(float)(0.01f*Math.cos(i*2*Math.PI/12); y1=zuoBiaoZhouBigWeiDian ; z1=(float)(0.01f*Math.sin(i*2*Math.PI/12); vert27+i=new Point3f(x1,y1,z1); colors27+i=Block.mianColor3; int count=new int2; count0=27 ; count1=14 ; TriangleFanArray tri=new TriangleFanArray( vert.length, TriangleFanArray.COORDINATES|TriangleStripArray.COLOR_3, count tri.setCoordinates(0,vert); tri.setColors(0,colors); Appearance app=new Appearance(); PolygonAttributes polyAttrib=new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); /polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE); app.setPolygonAttributes(polyAttrib); Shape3D shape=new Shape3D(tri,app); System.out.print("zuoBiaoZhuBigY 创建 完成n"); trans.addChild(shape); /到这里,大坐标轴对象创建完成 public static void zuoBiaoZhuBigZShape3D(TransformGroup trans) /创建大坐标轴对象 int i ; float x1,x2,y1,y2,z1,z2 ; SomeShape3D.addText3DDonghua(trans,"Z",new Point3f(-1.0f,0.0f,zuoBiaoZhouBigDingDian*10),0.1f,Block.mianColor4,0); Point3fvert=new Point3f41; Color3fcolors=new Color3f41; for(i=0;i<27;i+) if(i=0) verti=new Point3f(0.0f,0.0f,zuoBiaoZhouBigDingDian); colorsi=Block.mianColor4; else y1=(float)(zuoBiaoZhouBigDingXi*Math.cos(i*2*Math.PI/25); z1=zuoBiaoZhouBigDingChang; x1=(float)(zuoBiaoZhouBigDingXi*Math.sin(i*2*Math.PI/25); verti=new Point3f(x1,y1,z1); colorsi=Block.mianColor4; for(i=0;i<14;i+) if(i=0) vert27+i=new Point3f(0.0f,0.0f,zuoBiaoZhouBigDingDian); colors27+i=Block.mianColor4; else y1=(float)(0.01f*Math.cos(i*2*Math.PI/12); z1=zuoBiaoZhouBigWeiDian ; x1=(float)(0.01f*Math.sin(i*2*Math.PI/12); vert27+i=new Point3f(x1,y1,z1); colors27+i=Block.mianColor5; int count=new int2; count0=27 ; count1=14 ; TriangleFanArray tri=new TriangleFanArray( vert.length, TriangleFanArray.COORDINATES|TriangleStripArray.COLOR_3, count tri.setCoordinates(0,vert); tri.setColors(0,colors); Appearance app=new Appearance(); PolygonAttributes polyAttrib=new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); /polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE); app.setPolygonAttributes(polyAttrib); Shape3D shape=new Shape3D(tri,app); System.out.print("zuoBiaoZhuBigZ 创建 完成n"); trans.addChild(shape); /到这里,大坐标轴对象创建完成 public static void zuoBiaoZhuSmallXShape3D(TransformGroup trans) /创建小坐标轴对象 int i ; float x1,x2,y1,y2,z1,z2 ; Point3fvert=new Point3f41; Color3fcolors=new Color3f41; for(i=0;i<27;i+) if(i=0) verti=new Point3f(zuoBiaoZhouSmallDingDian,0.0f,0.0f); colorsi=Block.mianColor0; else z1=(float)(zuoBiaoZhouSmallDingXi*Math.cos(i*2*Math.PI/25); x1=zuoBiaoZhouSmallDingChang ; y1=(float)(zuoBiaoZhouSmallDingXi*Math.sin(i*2*Math.PI/25); verti=new Point3f(x1,y1,z1); colorsi=Block.mianColor0; for(i=0;i<14;i+) if(i=0) vert27+i=new Point3f(zuoBiaoZhouSmallDingDian,0.0f,0.0f); colors27+i=Block.mianColor0; else z1=(float)(0.005f*Math.cos(i*2*Math.PI/12); x1=zuoBiaoZhouSmallWeiDian ; y1=(float)(0.005f*Math.sin(i*2*Math.PI/12); vert27+i=new Point3f(x1,y1,z1); colors27+i=Block.mianColor1; int count=new int2; count0=27 ; count1=14 ; TriangleFanArray tri=new TriangleFanArray( vert.length, TriangleFanArray.COORDINATES|TriangleStripArray.COLOR_3, count tri.setCoordinates(0,vert); tri.setColors(0,colors); Appearance app=new Appearance(); PolygonAttributes polyAttrib=new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); /polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE); app.setPolygonAttributes(polyAttrib); Shape3D shape=new Shape3D(tri,app); /System.out.print("zuoBiaoZhuSmallX 创建 完成"); trans.addChild(shape); /到这里,小坐标轴对象创建完成 public static void zuoBiaoZhuSmallYShape3D(TransformGroup trans) /创建小坐标轴对象 int i ; float x1,x2,y1,y2,z1,z2 ; Point3fvert=new Point3f41; Color3fcolors=new Color3f41; for(i=0;i<27;i+) if(i=0) verti=new Point3f(0.0f,zuoBiaoZhouSmallDingDian,0.0f); colorsi=Block.mianColor2; else x1=(float)(zuoBiaoZhouSmallDingXi*Math.cos(i*2*Math.PI/25); y1=zuoBiaoZhouSmallDingChang ; z1=(float)(zuoBiaoZhouSmallDingXi*Math.sin(i*2*Math.PI/25); verti=new Point3f(x1,y1,z1); colorsi=Block.mianColor2; for(i=0;i<14;i+) if(i=0) vert27+i=new Point3f(0.0f,zuoBiaoZhouSmallDingDian,0.0f); colors27+i=Block.mianColor2; else x1=(float)(0.005f*Math.cos(i*2*Math.PI/12); y1=zuoBiaoZhouSmallWeiDian ; z1=(float)(0.005f*Math.sin(i*2*Math.PI/12); vert27+i=new Point3f(x1,y1,z1); colors27+i=Block.mianColor3; int count=new int2; count0=27 ; count1=14 ; TriangleFanArray tri=new TriangleFanArray( vert.length, TriangleFanArray.COORDINATES|TriangleStripArray.COLOR_3, count tri.setCoordinates(0,vert); tri.setColors(0,colors); Appearance app=new Appearance(); PolygonAttributes polyAttrib=new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); /polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE); app.setPolygonAttributes(polyAttrib); Shape3D shape=new Shape3D(tri,app); /System.o

    注意事项

    本文(魔方java源代码.doc)为本站会员(豆****)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开