已阅读5页,还剩45页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/存为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;i27;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;i14;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;i27;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;i14;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;i27;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;i14;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;i27;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;i14;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;i27;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;i14;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.out.print(zuoBiaoZhuSmallY 创建 完成); trans.addChild(shape); /到这里,小坐标轴对象创建完成 public static void zuoBiaoZhuSmallZShape3D(TransformGroup trans) /创建小坐标轴对象 int i ; float x1,x2,y1,y2,z1,z2 ; Point3fvert=new Point3f41; Color3fcolors=new Color3f41; for(i=0;i27;i+) if(i=0) verti=new Point3f(0.0f,0.0f,zuoBiaoZhouSmallDingDian); colorsi=Block.mianColor4; else y1=(float)(zuoBiaoZhouSmallDingXi*Math.cos(i*2*Math.PI/25); z1=zuoBiaoZhouSmallDingChang ; x1=(float)(zuoBiaoZhouSmallDingXi*Math.sin(i*2*Math.PI/25); verti=new Point3f(x1,y1,z1); colorsi=Block.mianColor4; for(i=0;i14;i+) if(i=0) vert27+i=new Point3f(0.0f,0.0f,zuoBiaoZhouSmallDingDian); colors27+i=Block.mianColor4; else y1=(float)(0.005f*Math.cos(i*2*Math.PI/12); z1=zuoBiaoZhouSmallWeiDian ; x1=(float)(0.005f*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.setPol
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 景观灯采购合同
- 二年级道德与法治上册 我上二年级了 第2课《我为集体添光彩》教案 北师大版
- 2024-2025学年高中物理 第二章 原子结构 3 光谱 氢原子光谱教案1 教科版选修3-5
- 2024年学年八年级语文上册 第五单元 心灵诗语 第18课《采莲曲》教案 沪教版五四制
- 2023三年级英语上册 Unit 2 Colours Part B 第二课时教案 人教PEP
- 八年级政治下册 第五单元 我是中国公民 5.1 我们都是公民情境探究型教案 粤教版
- 2024-2025学年高中物理 第四章 机械能和能源 5 机械能守恒定律教案1 教科版必修2
- 高考地理一轮复习第十九章环境安全与国家安全第一节环境安全、全球气候与国家安全课件
- 最简单的居间合同(2篇)
- 汉子人教版课件
- 《会议摄影要点》PPT课件
- 国家自然科学基金申请经验交流PPT课件
- Shopping购物英语学习PPT课件
- 基于UbD理论小说叙事视角的群文阅读设计
- 内分泌系统和营养代谢性疾病总论PPT课件
- 抓斗式挖泥船疏浚施工方案(共7页)
- 专业化销售流程之寻找准主顾及约访
- 抹灰整改通知单
- 半导体简答题
- 某水库新建码头初步设计
- 学习能力的培养ppt课件
评论
0/150
提交评论