计算机图形学 实验一:生成彩色立方体(含源代码)
(4页)
本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!
9.9 积分
实验一实验目的:生成彩色立方体实验代码://ColorCube1.javaimport java.applet.Applet; //可以插入htmlimport java.awt.BorderLayout; //窗口采用BorderLayout方式布局import com.sun.j3d.utils.applet.MainFrame; //applicationimport com.sun.j3d.utils.geometry.ColorCube;//调用生成ColorCube的Utilityimport com.sun.j3d.utils.geometry.Primitive;import com.sun.j3d.utils.universe.*; //观测位置的设置import javax.media.j3d.*; //核心类import javax.vecmath.*; //矢量计算import com.sun.j3d.utils.behaviors.mouse.*;public class ColorCube1 extends Applet { public BranchGroup createSceneGraph() { BranchGroup objRoot=new BranchGroup(); //BranchGroup的一个对象objRoot(放置背景、灯光) BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);//有效范围 TransformGroup objTrans=new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(objTrans); MouseRotate behavior = new MouseRotate(); behavior.setTransformGroup(objTrans); objRoot.addChild(behavior); behavior.setSchedulingBounds(bounds); MouseZoom behavior2 = new MouseZoom(); behavior2.setTransformGroup(objTrans); objRoot.addChild(behavior2); behavior2.setSchedulingBounds(bounds); MouseTranslate behavior3 = new MouseTranslate(); behavior3.setTransformGroup(objTrans); objRoot.addChild(behavior3); behavior3.setSchedulingBounds(bounds); Color3f bgColor=new Color3f(0.0f,0.0f,0.0f); //背景颜色 Background bg=new Background(bgColor); bg.setApplicationBounds(bounds); objRoot.addChild(bg); Color3f directionalColor=new Color3f(1.f,1.f,1.f); Vector3f vec=new Vector3f(1.f,1.f,-1.0f); DirectionalLight directionalLight=new DirectionalLight(directionalColor,vec); directionalLight.setInfluencingBounds(bounds); objRoot.addChild(directionalLight); Appearance app=new Appearance(); //外观材质 Material material=new Material(); //圆锥颜色 //material.setEmissiveColor(new Color3f(1.0f,1.0f,0.0f)); material.setDiffuseColor(new Color3f(1.0f,1.0f,0.0f)); //辐射光效果 app.setMaterial(material); ColorCube cone=new ColorCube(0.2); objTrans.addChild(cone); //objRoot.compile(); return objRoot; } public ColorCube1() { setLayout(new BorderLayout()); Canvas3D c=new Canvas3D(null); add("Center",c); BranchGroup scene=createSceneGraph(); SimpleUniverse u=new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); } public static void main(String[] args) { new MainFrame(new ColorCube1(),400,300); }}运行截图: 关 键 词: 计算机图形学实验一:生成彩色立方体(含源代码)
天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文